Fixed the bug where hotkeys would not activate if iTunes was launched
[MenuTunes.git] / MainController.m
index a9ea365..dd8c51d 100755 (executable)
@@ -41,6 +41,7 @@ static MainController *sharedController;
         menuController = [[MenuController alloc] init];
         df = [[NSUserDefaults standardUserDefaults] retain];
         timerUpdating = NO;
+        blinged = NO;
     }
     return self;
 }
@@ -182,18 +183,29 @@ static MainController *sharedController;
         if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) {
             [self setBlingTime:now];
         }
-        if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) ) {
+        if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) && (blinged != YES) ) {
+            blinged = YES;
             [statusItem setEnabled:NO];
             [self clearHotKeys];
             if ([refreshTimer isValid]) {
                 [refreshTimer invalidate];
             }
-            if ([registerTimer isValid]) {
-                [registerTimer invalidate];
-            }
             [statusWindowController showRegistrationQueryWindow];
         }
     } else {
+        if (blinged) {
+            [statusItem setEnabled:YES];
+            [self setupHotKeys];
+            if (![refreshTimer isValid]) {
+                [refreshTimer release];
+                refreshTimer = refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
+                             target:self
+                             selector:@selector(timerUpdate)
+                             userInfo:nil
+                             repeats:YES] retain];
+            }
+            blinged = NO;
+        }
         [self setBlingTime:nil];
     }
 }
@@ -761,6 +773,7 @@ static MainController *sharedController;
 {
     if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
         ITDebugLog(@"Remote application launched.");
+        playerRunningState = ITMTRemotePlayerRunning;
         [currentRemote begin];
         [self setLatestSongIdentifier:@""];
         [self timerUpdate];
@@ -771,7 +784,6 @@ static MainController *sharedController;
                              repeats:YES] retain];
         //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
         [self setupHotKeys];
-        playerRunningState = ITMTRemotePlayerRunning;
     }
 }
 
@@ -783,9 +795,6 @@ static MainController *sharedController;
         [refreshTimer invalidate];
         [refreshTimer release];
         refreshTimer = nil;
-        [registerTimer invalidate];
-        [registerTimer release];
-        registerTimer = nil;
         [self clearHotKeys];
         playerRunningState = ITMTRemotePlayerNotRunning;
      }