]> granicus.if.org Git - transmission/commitdiff
on 10.6 simplify the check for already-running Transmission instances
authorMitchell Livingston <livings124@transmissionbt.com>
Sat, 10 Oct 2009 00:00:46 +0000 (00:00 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sat, 10 Oct 2009 00:00:46 +0000 (00:00 +0000)
macosx/Controller.m
macosx/TorrentCell.m

index 8d868667e52b1bac5b4dc131f544afaba4485ef8..d83556d2599aae9842f3c0d951e4e67dbb5919ce 100644 (file)
@@ -169,30 +169,43 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
 + (void) initialize
 {
     //make sure another Transmission.app isn't running already
-    NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
-    int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
-
-    for (NSDictionary * dic in [[NSWorkspace sharedWorkspace] launchedApplications])
+    BOOL othersRunning = NO;
+    
+    if ([NSApp isOnSnowLeopardOrBetter])
+    {
+        NSArray * apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: [[NSBundle mainBundle] bundleIdentifier]];
+        othersRunning = [apps count] > 1;
+    }
+    else
     {
-        if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
-            && [[dic objectForKey: @"NSApplicationProcessIdentifier"] intValue] != processIdentifier)
+        NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
+        const int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
+
+        for (NSDictionary * dic in [[NSWorkspace sharedWorkspace] launchedApplications])
         {
-            NSAlert * alert = [[NSAlert alloc] init];
-            [alert addButtonWithTitle: NSLocalizedString(@"Quit", "Transmission already running alert -> button")];
-            [alert setMessageText: NSLocalizedString(@"Transmission is already running.",
-                                                    "Transmission already running alert -> title")];
-            [alert setInformativeText: NSLocalizedString(@"There is already a copy of Transmission running. "
-                "This copy cannot be opened until that instance is quit.", "Transmission already running alert -> message")];
-            [alert setAlertStyle: NSCriticalAlertStyle];
-            
-            [alert runModal];
-            [alert release];
-            
-            //kill ourselves right away
-            exit(0);
+            if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
+                    && [[dic objectForKey: @"NSApplicationProcessIdentifier"] intValue] != processIdentifier)
+                othersRunning = YES;
         }
     }
     
+    if (othersRunning)
+    {
+        NSAlert * alert = [[NSAlert alloc] init];
+        [alert addButtonWithTitle: NSLocalizedString(@"Quit", "Transmission already running alert -> button")];
+        [alert setMessageText: NSLocalizedString(@"Transmission is already running.",
+                                                "Transmission already running alert -> title")];
+        [alert setInformativeText: NSLocalizedString(@"There is already a copy of Transmission running. "
+            "This copy cannot be opened until that instance is quit.", "Transmission already running alert -> message")];
+        [alert setAlertStyle: NSCriticalAlertStyle];
+        
+        [alert runModal];
+        [alert release];
+        
+        //kill ourselves right away
+        exit(0);
+    }
+    
     [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary dictionaryWithContentsOfFile:
         [[NSBundle mainBundle] pathForResource: @"Defaults" ofType: @"plist"]]];
     
index 423b6e80b2ffb65d72896f88c27ed02be6c4f878..fb29705784fa8dcbe9251f32de1ddc30a51739cf 100644 (file)
     NSRect result;
     result.size = [string size];
     
-    result.origin.x = NSMaxX(bounds) - result.size.width - PADDING_HORIZONTAL;
+    result.origin.x = NSMaxX(bounds) - (NSWidth(result) + PADDING_HORIZONTAL);
     result.origin.y = NSMinY(bounds) + PADDING_ABOVE_MIN_STATUS;
     
     return result;