From bbfffdf79f0ac374ee3c811006e224c49a55e850 Mon Sep 17 00:00:00 2001 From: Matthew Douglass Date: Sun, 16 Oct 2016 20:40:22 -0700 Subject: [PATCH] Scanning an invalid QR code shows an error dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * From the error dialog you are able to back out of scanning or try again. Adds English localization for this message. Adds an extra flag in OWSQRCodeScanningViewController to make sure that we don’t handle captureResults when capture is disabled (this was racing before because the call to [capture stop] is async and that was causing the cancel case to present the error dialog multiple times. Fixes Signal-iOS#1347 * Fixes appearance of race with starting capture Also marks the capture variable as atomic since it is accessed on multiple threads. // FREEBIE --- .../OWSLinkDeviceViewController.m | 79 ++++++++++++------ .../OWSQRCodeScanningViewController.m | 9 +- .../translations/en.lproj/Localizable.strings | Bin 59344 -> 60034 bytes 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Signal/src/view controllers/OWSLinkDeviceViewController.m b/Signal/src/view controllers/OWSLinkDeviceViewController.m index 2e31142ee..a6e39b556 100644 --- a/Signal/src/view controllers/OWSLinkDeviceViewController.m +++ b/Signal/src/view controllers/OWSLinkDeviceViewController.m @@ -62,16 +62,18 @@ NS_ASSUME_NONNULL_BEGIN // pragma mark - OWSQRScannerDelegate - (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string { - NSString *title - = NSLocalizedString(@"LINK_DEVICE_PERMISSION_ALERT_TITLE", @"confirm the users intent to link a new device"); - NSString *linkingDescription - = NSLocalizedString(@"LINK_DEVICE_PERMISSION_ALERT_BODY", @"confirm the users intent to link a new device"); - - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title - message:linkingDescription - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction *cancelAction = + OWSDeviceProvisioningURLParser *parser = [[OWSDeviceProvisioningURLParser alloc] initWithProvisioningURL:string]; + if (!parser.isValid) { + DDLogError(@"Unable to parse provisioning params from QRCode: %@", string); + + NSString* title = NSLocalizedString(@"LINK_DEVICE_INVALID_CODE_TITLE", @"report an invalid linking code"); + NSString* body = NSLocalizedString(@"LINK_DEVICE_INVALID_CODE_BODY", @"report an invalid linking code"); + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title + message:body + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { @@ -79,28 +81,51 @@ NS_ASSUME_NONNULL_BEGIN [self.navigationController popViewControllerAnimated:YES]; }); }]; - [alertController addAction:cancelAction]; - - UIAlertAction *proceedAction = - [UIAlertAction actionWithTitle:NSLocalizedString(@"CONFIRM_LINK_NEW_DEVICE_ACTION", @"Button text") + [alertController addAction:cancelAction]; + + UIAlertAction *proceedAction = + [UIAlertAction actionWithTitle:NSLocalizedString(@"LINK_DEVICE_RESTART", @"attempt another linking") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [self provisionWithString:string]; + [self.qrScanningController startCapture]; }]; - [alertController addAction:proceedAction]; - - [self presentViewController:alertController animated:YES completion:nil]; + [alertController addAction:proceedAction]; + + [self presentViewController:alertController animated:YES completion:nil]; + } else { + NSString *title + = NSLocalizedString(@"LINK_DEVICE_PERMISSION_ALERT_TITLE", @"confirm the users intent to link a new device"); + NSString *linkingDescription + = NSLocalizedString(@"LINK_DEVICE_PERMISSION_ALERT_BODY", @"confirm the users intent to link a new device"); + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title + message:linkingDescription + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *cancelAction = + [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil) + style:UIAlertActionStyleCancel + handler:^(UIAlertAction *action) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.navigationController popViewControllerAnimated:YES]; + }); + }]; + [alertController addAction:cancelAction]; + + UIAlertAction *proceedAction = + [UIAlertAction actionWithTitle:NSLocalizedString(@"CONFIRM_LINK_NEW_DEVICE_ACTION", @"Button text") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [self provisionWithParser:parser]; + }]; + [alertController addAction:proceedAction]; + + [self presentViewController:alertController animated:YES completion:nil]; + } } -- (void)provisionWithString:(NSString *)string +- (void)provisionWithParser:(OWSDeviceProvisioningURLParser *)parser { - OWSDeviceProvisioningURLParser *parser = [[OWSDeviceProvisioningURLParser alloc] initWithProvisioningURL:string]; - - if (!parser.isValid) { - DDLogError(@"Unable to parse provisioning params from QRCode: %@", string); - return; - } - NSData *myPublicKey = [[TSStorageManager sharedManager] identityKeyPair].publicKey; NSData *myPrivateKey = [[TSStorageManager sharedManager] identityKeyPair].ows_privateKey; NSString *accountIdentifier = [TSStorageManager localNumber]; @@ -123,7 +148,7 @@ NS_ASSUME_NONNULL_BEGIN dispatch_async(dispatch_get_main_queue(), ^{ [self presentViewController:[self retryAlertControllerWithError:error retryBlock:^{ - [self provisionWithString:string]; + [self provisionWithParser:parser]; }] animated:YES completion:nil]; diff --git a/Signal/src/view controllers/OWSQRCodeScanningViewController.m b/Signal/src/view controllers/OWSQRCodeScanningViewController.m index 356bf8974..56b4b0ec5 100644 --- a/Signal/src/view controllers/OWSQRCodeScanningViewController.m +++ b/Signal/src/view controllers/OWSQRCodeScanningViewController.m @@ -8,7 +8,7 @@ @interface OWSQRCodeScanningViewController () @property (nonatomic) BOOL captureEnabled; -@property (nonatomic, strong) ZXCapture *capture; +@property (atomic, strong) ZXCapture *capture; @property UIView *maskingView; @property CALayer *maskingLayer; @@ -97,14 +97,17 @@ dispatch_async(dispatch_get_main_queue(), ^{ [self.view.layer addSublayer:self.capture.layer]; [self.view bringSubviewToFront:self.maskingView]; + [self.capture start]; }); }); + } else { + [self.capture start]; } - [self.capture start]; } - (void)stopCapture { + self.captureEnabled = NO; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self.capture stop]; }); @@ -137,6 +140,8 @@ - (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result { + if (!self.captureEnabled) + return; [self stopCapture]; // TODO bounding rectangle diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 6f997da9e3d361d7cfc4c754f4aa3df1a0dafb6b..a0cb16df288af3ae1c6f540cdbea40098c58d6d2 100644 GIT binary patch delta 380 zcmca`p1J8N^M>R|%OZwUh609sh9ZU%1_g#hhCCpd2_(ya>>MB~1;_`{c?{WLG9AcI z2C7e)yem>w+>^nNA&kM1!H2<&jT>+@36lgz)RS7h?6i6pR`NcrHKyJ!|*gg4GjQ3>0?Gk}77wIu5 zF<3Kj0iiyF7Em8ed^0J*e{*tV6O(QtFpNro?#u;-7%a5%fvgOmSP{^6n5#gcl|Fe- bq%wC9gDXQYLkKX0f+n{tQ{DVD`gJz|{6$il delta 19 bcmZp=%6#EG^M>Te%~PYBm^M$3d)*BHUz-W8