if ([df boolForKey:@"enableSharing"]) {
[self setServerStatus:YES];
} else if ([df boolForKey:@"useSharedPlayer"]) {
- [self checkForRemoteServer];
+ [self checkForRemoteServerAndConnectImmediately:YES];
}
//Setup for notification of the remote player launching or quitting
}
- (void)checkForRemoteServer
+{
+ [self checkForRemoteServerAndConnectImmediately:NO];
+}
+
+- (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately
{
ITDebugLog(@"Checking for remote server.");
- [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:nil];
+ [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:[NSNumber numberWithBool:connectImmediately]];
}
- (void)runRemoteServerCheck:(id)sender
ITDebugLog(@"Remote server check running.");
if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
ITDebugLog(@"Remote server found.");
- [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
+ if ([sender boolValue]) {
+ [self performSelectorOnMainThread:@selector(connectToServer) withObject:nil waitUntilDone:NO];
+ } else {
+ [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
+ }
} else {
ITDebugLog(@"Remote server not found.");
[self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO];
- (void)remoteServerNotFound:(id)sender
{
- [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
+ if (![[NetworkController sharedController] isConnectedToServer]) {
+ [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
+ }
}
- (void)networkError:(NSException *)exception
[[StatusWindowController sharedController] showNetworkErrorQueryWindow];
if ([self disconnectFromServer]) {
[[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
- [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:YES];
+ [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
} else {
ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
}
- (void)reconnect
{
- if ([self connectToServer] == 0) {
- [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:YES];
- }
+ /*if ([self connectToServer] == 0) {
+ [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
+ }*/
+ [self checkForRemoteServerAndConnectImmediately:YES];
[[StatusWindow sharedWindow] setLocked:NO];
[[StatusWindow sharedWindow] vanish:self];
[[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];