Fixed the bug where hotkeys would not activate if iTunes was launched
[MenuTunes.git] / MainController.m
index 5f25c09..dd8c51d 100755 (executable)
@@ -41,6 +41,7 @@ static MainController *sharedController;
         menuController = [[MenuController alloc] init];
         df = [[NSUserDefaults standardUserDefaults] retain];
         timerUpdating = NO;
         menuController = [[MenuController alloc] init];
         df = [[NSUserDefaults standardUserDefaults] retain];
         timerUpdating = NO;
+        blinged = NO;
     }
     return self;
 }
     }
     return self;
 }
@@ -159,7 +160,11 @@ static MainController *sharedController;
     NSMutableDictionary *globalPrefs;
     [df synchronize];
     globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
     NSMutableDictionary *globalPrefs;
     [df synchronize];
     globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
-    [globalPrefs setObject:date forKey:@"ITMTTrialStart"];
+    if (date) {
+        [globalPrefs setObject:date forKey:@"ITMTTrialStart"];
+    } else {
+        [globalPrefs removeObjectForKey:@"ITMTTrialStart"];
+    }
     [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
     [df synchronize];
     [globalPrefs release];
     [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
     [df synchronize];
     [globalPrefs release];
@@ -174,19 +179,34 @@ static MainController *sharedController;
 - (void)blingTime
 {
     NSDate *now = [NSDate date];
 - (void)blingTime
 {
     NSDate *now = [NSDate date];
-    if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) {
-        [self setBlingTime:now];
-    }
-    if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) ) {
-        [statusItem setEnabled:NO];
-        [self clearHotKeys];
-        if ([refreshTimer isValid]) {
-        [refreshTimer invalidate];
+    if (![self blingBling]) {
+        if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) {
+            [self setBlingTime:now];
         }
         }
-        if ([registerTimer isValid]) {
-        [registerTimer invalidate];
+        if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) && (blinged != YES) ) {
+            blinged = YES;
+            [statusItem setEnabled:NO];
+            [self clearHotKeys];
+            if ([refreshTimer isValid]) {
+                [refreshTimer invalidate];
+            }
+            [statusWindowController showRegistrationQueryWindow];
         }
         }
-        [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];
     }
 }
 
     }
 }
 
@@ -753,6 +773,7 @@ static MainController *sharedController;
 {
     if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
         ITDebugLog(@"Remote application launched.");
 {
     if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
         ITDebugLog(@"Remote application launched.");
+        playerRunningState = ITMTRemotePlayerRunning;
         [currentRemote begin];
         [self setLatestSongIdentifier:@""];
         [self timerUpdate];
         [currentRemote begin];
         [self setLatestSongIdentifier:@""];
         [self timerUpdate];
@@ -763,7 +784,6 @@ static MainController *sharedController;
                              repeats:YES] retain];
         //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
         [self setupHotKeys];
                              repeats:YES] retain];
         //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
         [self setupHotKeys];
-        playerRunningState = ITMTRemotePlayerRunning;
     }
 }
 
     }
 }
 
@@ -775,9 +795,6 @@ static MainController *sharedController;
         [refreshTimer invalidate];
         [refreshTimer release];
         refreshTimer = nil;
         [refreshTimer invalidate];
         [refreshTimer release];
         refreshTimer = nil;
-        [registerTimer invalidate];
-        [registerTimer release];
-        registerTimer = nil;
         [self clearHotKeys];
         playerRunningState = ITMTRemotePlayerNotRunning;
      }
         [self clearHotKeys];
         playerRunningState = ITMTRemotePlayerNotRunning;
      }