Fixed some warnings. Upped the server check to 90 seconds, from 45.
[MenuTunes.git] / MainController.m
index c4fd253..c2acaf1 100755 (executable)
@@ -33,6 +33,7 @@
 @interface MainController(Private)
 - (ITMTRemote *)loadRemote;
 - (void)setLatestSongIdentifier:(NSString *)newIdentifier;
+- (void)checkForRemoteServer;
 - (void)applicationLaunched:(NSNotification *)note;
 - (void)applicationTerminated:(NSNotification *)note;
 @end
@@ -89,9 +90,7 @@ static MainController *sharedController;
     if ([df boolForKey:@"enableSharing"]) {
         [self setServerStatus:YES];
     } else if ([df boolForKey:@"useSharedPlayer"]) {
-        if ([self connectToServer] == 0) {
-            [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
-        }
+        [self checkForRemoteServer];
     }
     
     //Setup for notification of the remote player launching or quitting
@@ -107,7 +106,7 @@ static MainController *sharedController;
             name:NSWorkspaceDidLaunchApplicationNotification
             object:nil];
     
-    if ( ! [df objectForKey:@"menu"] ) {  // If this is nil, defaults have never been registered.
+    if (![df objectForKey:@"menu"]) {  // If this is nil, defaults have never been registered.
         [[PreferencesController sharedPrefs] registerDefaults];
     }
     
@@ -164,7 +163,7 @@ static MainController *sharedController;
                 Class remoteClass = [remoteBundle principalClass];
 
                 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
-                    [remoteClass isKindOfClass:[NSObject class]]) {
+                    [(NSObject *)remoteClass isKindOfClass:[NSObject class]]) {
                     id remote = [remoteClass remote];
                     ITDebugLog(@"Adding remote at path %@", bundlePath);
                     [remoteArray addObject:remote];
@@ -546,7 +545,7 @@ static MainController *sharedController;
             NSString *path;
             if ( (path = [df stringForKey:@"CustomPlayerPath"]) ) {
             } else {
-                path = [[self currentRemote] playerFullName];
+                pathITDebugLog(@"Showing player interface."); = [[self currentRemote] playerFullName];
             }
             if (![[NSWorkspace sharedWorkspace] launchApplication:path]) {
                 ITDebugLog(@"Error Launching Player");
@@ -1134,20 +1133,38 @@ static MainController *sharedController;
     return YES;
 }
 
-- (void)checkForRemoteServer:(NSTimer *)timer
+- (void)checkForRemoteServer
 {
     ITDebugLog(@"Checking for remote server.");
+    [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:nil];
+}
+
+- (void)runRemoteServerCheck:(id)sender
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    ITDebugLog(@"Remote server check running.");
     if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
         ITDebugLog(@"Remote server found.");
-        [timer invalidate];
-        if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
-            [[StatusWindowController sharedController] showReconnectQueryWindow];
-        }
+        [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
     } else {
         ITDebugLog(@"Remote server not found.");
+        [self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO];
+    }
+    [pool release];
+}
+
+- (void)remoteServerFound:(id)sender
+{
+    if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
+        [[StatusWindowController sharedController] showReconnectQueryWindow];
     }
 }
 
+- (void)remoteServerNotFound:(id)sender
+{
+    [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
+}
+
 - (void)networkError:(NSException *)exception
 {
     ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
@@ -1155,7 +1172,7 @@ static MainController *sharedController;
         NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil);
         if ([self disconnectFromServer]) {
             [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
-            [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
+            [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:YES];
         } else {
             ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
         }
@@ -1165,7 +1182,7 @@ static MainController *sharedController;
 - (void)reconnect
 {
     if ([self connectToServer] == 0) {
-        [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
+        [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:YES];
     }
     [[StatusWindow sharedWindow] setLocked:NO];
     [[StatusWindow sharedWindow] vanish:self];