More fixes on timeout poop
[MenuTunes.git] / MainController.m
index 8784dd1..4eb7891 100755 (executable)
 #import "StatusWindowController.h"
 #import "StatusItemHack.h"
 
 #import "StatusWindowController.h"
 #import "StatusItemHack.h"
 
+@interface NSMenu (MenuImpl)
+- (id)_menuImpl;
+@end
+
 @interface NSCarbonMenuImpl:NSObject
 {
     NSMenu *_menu;
 @interface NSCarbonMenuImpl:NSObject
 {
     NSMenu *_menu;
@@ -358,17 +362,21 @@ static MainController *sharedController;
 - (void)timerUpdate
 {
        if ([[self currentRemote] playerStateUniqueIdentifier] == nil) {
 - (void)timerUpdate
 {
        if ([[self currentRemote] playerStateUniqueIdentifier] == nil) {
+               if ([statusItem isEnabled]) {
+                       [statusItem setToolTip:@"iTunes not responding."];
+                       [self clearHotKeys];
+               }
                [statusItem setEnabled:NO];
                [statusItem setEnabled:NO];
-               [statusItem setToolTip:@"iTunes not responding."];
                return;
        } else if (![statusItem isEnabled]) {
                [statusItem setEnabled:YES];
                [statusItem setToolTip:_toolTip];
                return;
        } else if (![statusItem isEnabled]) {
                [statusItem setEnabled:YES];
                [statusItem setToolTip:_toolTip];
+               [self setupHotKeys];
                return;
        }
        
        if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
                return;
        }
        
        if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
-        ITDebugLog(@"The song changed.");
+        ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
         if ([df boolForKey:@"runScripts"]) {
             NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
             NSEnumerator *scriptsEnum = [scripts objectEnumerator];
         if ([df boolForKey:@"runScripts"]) {
             NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
             NSEnumerator *scriptsEnum = [scripts objectEnumerator];
@@ -430,6 +438,21 @@ static MainController *sharedController;
 - (void)menuClicked
 {
     ITDebugLog(@"Menu clicked.");
 - (void)menuClicked
 {
     ITDebugLog(@"Menu clicked.");
+       
+       if ( ([[self currentRemote] playerStateUniqueIdentifier] == nil) && playerRunningState == ITMTRemotePlayerRunning ) {
+               if ([statusItem isEnabled]) {
+                       [statusItem setToolTip:@"iTunes not responding."];
+                       [self clearHotKeys];
+               }
+               [statusItem setEnabled:NO];
+               return;
+       } else if (![statusItem isEnabled]) {
+               [statusItem setEnabled:YES];
+               [statusItem setToolTip:_toolTip];
+               [self setupHotKeys];
+               return;
+       }
+       
     if ([networkController isConnectedToServer]) {
         //Used the cached version
         return;
     if ([networkController isConnectedToServer]) {
         //Used the cached version
         return;
@@ -1374,6 +1397,8 @@ static MainController *sharedController;
             [refreshTimer invalidate];
             [refreshTimer release];
             refreshTimer = nil;
             [refreshTimer invalidate];
             [refreshTimer release];
             refreshTimer = nil;
+                       [statusItem setEnabled:YES];
+                       [statusItem setToolTip:@"iTunes not running."];
             [self clearHotKeys];
             
             if ([df objectForKey:@"ShowPlayer"] != nil) {
             [self clearHotKeys];
             
             if ([df objectForKey:@"ShowPlayer"] != nil) {