iOS: Fix UI operations on non-main thread

This commit is contained in:
Jonathan Schleifer 2017-09-15 03:39:30 +02:00
parent 415ff25bf2
commit c291a09ce5
No known key found for this signature in database
GPG key ID: 28D65178B37F33E3

View file

@ -163,31 +163,31 @@ clearNSMutableString(NSMutableString *string)
- (void)_generateWithCallback: (void (^)(NSMutableString *))block - (void)_generateWithCallback: (void (^)(NSMutableString *))block
{ {
UIStoryboard *mainStoryboard = id <PasswordGenerator> generator;
[UIStoryboard storyboardWithName: @"Main" char *passphrase;
bundle: nil]; UIStoryboard *mainStoryboard;
UIViewController *activityController = [mainStoryboard UIViewController *activityController;
if (_legacy)
generator = [LegacyPasswordGenerator generator];
else
generator = [NewPasswordGenerator generator];
generator.site = _name;
generator.length = _length;
passphrase = of_strdup([self.passphraseField.text UTF8String]);
generator.passphrase = passphrase;
mainStoryboard = [UIStoryboard storyboardWithName: @"Main"
bundle: nil];
activityController = [mainStoryboard
instantiateViewControllerWithIdentifier: @"activityIndicator"]; instantiateViewControllerWithIdentifier: @"activityIndicator"];
[self.navigationController.view addSubview: activityController.view]; [self.navigationController.view addSubview: activityController.view];
dispatch_async(dispatch_get_global_queue( dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
id <PasswordGenerator> generator;
char *passphrase;
if (_legacy)
generator = [LegacyPasswordGenerator generator];
else
generator = [NewPasswordGenerator generator];
generator.site = _name;
generator.length = _length;
passphrase = of_strdup([self.passphraseField.text UTF8String]);
@try { @try {
self.passphraseField.text = @"";
generator.passphrase = passphrase;
[generator derivePassword]; [generator derivePassword];
} @finally { } @finally {
of_explicit_memset(passphrase, 0, strlen(passphrase)); of_explicit_memset(passphrase, 0, strlen(passphrase));
@ -199,8 +199,10 @@ clearNSMutableString(NSMutableString *string)
of_explicit_memset(generator.output, 0, of_explicit_memset(generator.output, 0,
strlen((char *)generator.output)); strlen((char *)generator.output));
activityController.view.hidden = YES; dispatch_sync(dispatch_get_main_queue(), ^ {
block(password); activityController.view.hidden = YES;
block(password);
});
}); });
} }