X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/d80384d37fa13bec5d65bc6aa97248036f743052..7bc6c0f1e85a6460ae61a80a80f974931924ec48:/iTunesRemote.m diff --git a/iTunesRemote.m b/iTunesRemote.m index 8745044..3381cb3 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -28,6 +28,8 @@ asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype); //Register for application termination in NSWorkspace + [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]; + [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil]; NSLog(@"iTunes Plugin loaded"); return YES; @@ -39,9 +41,33 @@ CloseComponent(asComponent); //Unregister for application termination in NSWorkspace + [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; + return YES; } +- (void)applicationLaunched:(NSNotification *)note +{ + NSDictionary *info = [note userInfo]; + + if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) { + iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue]; + iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue]; + + [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidLaunchNotification" object:nil]; + } +} + +- (void)applicationTerminated:(NSNotification *)note +{ + NSDictionary *info = [note userInfo]; + + if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) { + iTunesPSN.highLongOfPSN = kNoProcess; + [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidTerminateNotification" object:nil]; + } +} + - (PlayerState)playerState { NSString *result = [self runScriptAndReturnResult:@"get player state"];