From: Mitchell Livingston Date: Sat, 10 Oct 2009 00:00:46 +0000 (+0000) Subject: on 10.6 simplify the check for already-running Transmission instances X-Git-Tag: 1.80b5~623 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=444f8f553f07c7c84ff67e9e0d0506b743501fd1;p=transmission on 10.6 simplify the check for already-running Transmission instances --- diff --git a/macosx/Controller.m b/macosx/Controller.m index 8d868667e..d83556d25 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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"]]]; diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index 423b6e80b..fb2970578 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -699,7 +699,7 @@ 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;