From 1757359fbf3df32d9cb4f438b55d9736882dbb41 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 4 Nov 2019 21:41:42 -0800 Subject: [PATCH] Fix "server busy" pairing error dialog --- Limelight/Network/PairManager.h | 6 +----- Limelight/Network/PairManager.m | 10 ++++++---- Limelight/ViewControllers/MainFrameViewController.m | 6 ++++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Limelight/Network/PairManager.h b/Limelight/Network/PairManager.h index c137ff45..2cc29d2b 100644 --- a/Limelight/Network/PairManager.h +++ b/Limelight/Network/PairManager.h @@ -10,7 +10,7 @@ @protocol PairCallback -- (void) showPIN:(NSString*)PIN; +- (void) startPairing:(NSString*)PIN; - (void) pairSuccessful:(NSData*)serverCert; - (void) pairFailed:(NSString*)message; - (void) alreadyPaired; @@ -19,8 +19,4 @@ @interface PairManager : NSOperation - (id) initWithManager:(HttpManager*)httpManager clientCert:(NSData*)clientCert callback:(id)callback; -- (NSString*) generatePIN; -- (NSData*) saltPIN:(NSString*)PIN; -- (void) initiatePair:(int)serverMajorVersion; - @end diff --git a/Limelight/Network/PairManager.m b/Limelight/Network/PairManager.m index 6bce3599..2aa19188 100644 --- a/Limelight/Network/PairManager.m +++ b/Limelight/Network/PairManager.m @@ -30,6 +30,10 @@ } - (void) main { + // We have to call startPairing before calling any other _callback functions + NSString* PIN = [self generatePIN]; + [_callback startPairing:PIN]; + ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest:false] fallbackError:401 fallbackRequest:[_httpManager newHttpServerInfoRequest]]]; @@ -42,7 +46,7 @@ [_callback pairFailed:@"Missing XML element"]; return; } - [self initiatePair: [[appversion substringToIndex:1] intValue]]; + [self initiatePairWithPin:PIN forServerMajorVersion:[[appversion substringToIndex:1] intValue]]; } else { [_callback alreadyPaired]; } @@ -78,7 +82,7 @@ } // All codepaths must call finishPairing exactly once before returning! -- (void) initiatePair:(int)serverMajorVersion { +- (void) initiatePairWithPin:(NSString*)PIN forServerMajorVersion:(int)serverMajorVersion { Log(LOG_I, @"Pairing with generation %d server", serverMajorVersion); // Start a background task to help prevent the app from being killed @@ -87,10 +91,8 @@ Log(LOG_W, @"Background pairing time has expired!"); }]; - NSString* PIN = [self generatePIN]; NSData* salt = [self saltPIN:PIN]; Log(LOG_I, @"PIN: %@, saltedPIN: %@", PIN, salt); - [_callback showPIN:PIN]; HttpResponse* pairResp = [[HttpResponse alloc] init]; [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:pairResp withUrlRequest:[_httpManager newPairRequest:salt clientCert:_clientCert]]]; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 8714c46e..13f02b88 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -56,8 +56,10 @@ } static NSMutableSet* hostList; -- (void)showPIN:(NSString *)PIN { - dispatch_async(dispatch_get_main_queue(), ^{ +- (void)startPairing:(NSString *)PIN { + // Needs to be synchronous to ensure the alert is shown before any potential + // failure callback could be invoked. + dispatch_sync(dispatch_get_main_queue(), ^{ self->_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing" message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN] preferredStyle:UIAlertControllerStyleAlert];