Ignore:
Timestamp:
Oct 10, 2009, 12:00:46 AM (13 years ago)
Author:
livings124
Message:

on 10.6 simplify the check for already-running Transmission instances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r9235 r9257  
    170170{
    171171    //make sure another Transmission.app isn't running already
    172     NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    173     int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
    174 
    175     for (NSDictionary * dic in [[NSWorkspace sharedWorkspace] launchedApplications])
    176     {
    177         if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
    178             && [[dic objectForKey: @"NSApplicationProcessIdentifier"] intValue] != processIdentifier)
    179         {
    180             NSAlert * alert = [[NSAlert alloc] init];
    181             [alert addButtonWithTitle: NSLocalizedString(@"Quit", "Transmission already running alert -> button")];
    182             [alert setMessageText: NSLocalizedString(@"Transmission is already running.",
    183                                                     "Transmission already running alert -> title")];
    184             [alert setInformativeText: NSLocalizedString(@"There is already a copy of Transmission running. "
    185                 "This copy cannot be opened until that instance is quit.", "Transmission already running alert -> message")];
    186             [alert setAlertStyle: NSCriticalAlertStyle];
    187            
    188             [alert runModal];
    189             [alert release];
    190            
    191             //kill ourselves right away
    192             exit(0);
    193         }
     172    BOOL othersRunning = NO;
     173   
     174    if ([NSApp isOnSnowLeopardOrBetter])
     175    {
     176        NSArray * apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: [[NSBundle mainBundle] bundleIdentifier]];
     177        othersRunning = [apps count] > 1;
     178    }
     179    else
     180    {
     181        NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
     182        const int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
     183
     184        for (NSDictionary * dic in [[NSWorkspace sharedWorkspace] launchedApplications])
     185        {
     186            if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
     187                    && [[dic objectForKey: @"NSApplicationProcessIdentifier"] intValue] != processIdentifier)
     188                othersRunning = YES;
     189        }
     190    }
     191   
     192    if (othersRunning)
     193    {
     194        NSAlert * alert = [[NSAlert alloc] init];
     195        [alert addButtonWithTitle: NSLocalizedString(@"Quit", "Transmission already running alert -> button")];
     196        [alert setMessageText: NSLocalizedString(@"Transmission is already running.",
     197                                                "Transmission already running alert -> title")];
     198        [alert setInformativeText: NSLocalizedString(@"There is already a copy of Transmission running. "
     199            "This copy cannot be opened until that instance is quit.", "Transmission already running alert -> message")];
     200        [alert setAlertStyle: NSCriticalAlertStyle];
     201       
     202        [alert runModal];
     203        [alert release];
     204       
     205        //kill ourselves right away
     206        exit(0);
    194207    }
    195208   
Note: See TracChangeset for help on using the changeset viewer.