diff options
-rw-r--r-- | macosx/Controller.h | 2 | ||||
-rw-r--r-- | macosx/Controller.mm | 77 |
2 files changed, 62 insertions, 17 deletions
diff --git a/macosx/Controller.h b/macosx/Controller.h index b3c425e53..619fb8817 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -394,5 +394,7 @@ BOOL fIsDragging; - (void) remindUserOfSleepOrShutdown; - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex; + +- (int) hbInstances; @end diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 36cd1b79c..f56e622f7 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -142,26 +142,48 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It /*On Screen Notification*/ NSString * alertTitle; - if (fWorkingCount > 0) + + /* We check to see if there is already another instance of hb running. + * Note: hbInstances == 1 means we are the only instance of HandBrake.app + */ + if ([self hbInstances] > 1) { - alertTitle = [NSString stringWithFormat: - NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""), - fWorkingCount,fPendingCount]; + alertTitle = [NSString stringWithFormat: + NSLocalizedString(@"There is already an instance of HandBrake running.", @"")]; + NSBeginCriticalAlertSheet( + alertTitle, + NSLocalizedString(@"Reload Queue", nil), + nil, + nil, + fWindow, self, + nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil, + NSLocalizedString(@" HandBrake will now load up the existing queue.", nil)); } else { - alertTitle = [NSString stringWithFormat: - NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""), - fPendingCount]; + if (fWorkingCount > 0) + { + alertTitle = [NSString stringWithFormat: + NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""), + fWorkingCount,fPendingCount]; + } + else + { + alertTitle = [NSString stringWithFormat: + NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""), + fPendingCount]; + } + + NSBeginCriticalAlertSheet( + alertTitle, + NSLocalizedString(@"Reload Queue", nil), + nil, + NSLocalizedString(@"Empty Queue", nil), + fWindow, self, + nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil, + NSLocalizedString(@" Do you want to reload them ?", nil)); } - NSBeginCriticalAlertSheet( - alertTitle, - NSLocalizedString(@"Reload Queue", nil), - nil, - NSLocalizedString(@"Empty Queue", nil), - fWindow, self, - nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil, - NSLocalizedString(@" Do you want to reload them ?", nil)); + // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo // right below to either clear the old queue or keep it loaded up. } @@ -180,6 +202,24 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It } } +- (int) hbInstances +{ + /* check to see if another instance of HandBrake.app is running */ + NSArray *runningAppDictionaries = [[NSWorkspace sharedWorkspace] launchedApplications]; + NSDictionary *aDictionary; + int hbInstances = 0; + for (aDictionary in runningAppDictionaries) + { + // NSLog(@"Open App: %@", [aDictionary valueForKey:@"NSApplicationName"]); + + if ([[aDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"]) + { + hbInstances++; + } + } + return hbInstances; +} + - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo { if (returnCode == NSAlertOtherReturn) @@ -198,8 +238,11 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It } else { - [self setQueueEncodingItemsAsPending]; - [self showQueueWindow:NULL]; + if ([self hbInstances] == 1) + { + [self setQueueEncodingItemsAsPending]; + } + [self showQueueWindow:NULL]; } } |