From ce95f2c153a35e51a4228561a4b24ac15166fb6a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 21 Oct 2016 12:07:29 -0700 Subject: [PATCH] Fix some pairing glitches and add a cancel button --- Limelight/Network/PairManager.m | 5 +++- .../ViewControllers/MainFrameViewController.m | 27 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Limelight/Network/PairManager.m b/Limelight/Network/PairManager.m index ac22cbf..7898be4 100644 --- a/Limelight/Network/PairManager.m +++ b/Limelight/Network/PairManager.m @@ -68,12 +68,15 @@ } NSInteger pairedStatus; if (![pairResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) { - [_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]]; [_callback pairFailed:@"Pairing was declined by the target."]; return; } NSString* plainCert = [pairResp getStringTag:@"plaincert"]; + if ([plainCert length] == 0) { + [_callback pairFailed:@"Another pairing attempt is already in progress."]; + return; + } CryptoManager* cryptoMan = [[CryptoManager alloc] init]; NSData* aesKey; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 24043de..07c7afc 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -48,21 +48,26 @@ static NSMutableSet* hostList; _pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing" message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN] preferredStyle:UIAlertControllerStyleAlert]; + [_pairAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action) { + [_discMan startDiscovery]; + [self hideLoadingFrame]; + }]]; [self presentViewController:_pairAlert animated:YES completion:nil]; }); } - (void)pairFailed:(NSString *)message { dispatch_async(dispatch_get_main_queue(), ^{ - [_pairAlert dismissViewControllerAnimated:YES completion:nil]; - _pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing Failed" - message:message - preferredStyle:UIAlertControllerStyleAlert]; - [_pairAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]]; - [self presentViewController:_pairAlert animated:YES completion:nil]; - - [_discMan startDiscovery]; - [self hideLoadingFrame]; + [_pairAlert dismissViewControllerAnimated:YES completion:^{ + _pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing Failed" + message:message + preferredStyle:UIAlertControllerStyleAlert]; + [_pairAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]]; + [self presentViewController:_pairAlert animated:YES completion:nil]; + + [_discMan startDiscovery]; + [self hideLoadingFrame]; + }]; }); } @@ -581,8 +586,8 @@ static NSMutableSet* hostList; -(void)handleReturnToForeground { - // This will refresh the applist - if (_selectedHost != nil) { + // This will refresh the applist when a paired host is selected + if (_selectedHost != nil && _selectedHost.pairState == PairStatePaired) { [self hostClicked:_selectedHost view:nil]; } }