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,17 +163,10 @@ clearNSMutableString(NSMutableString *string)
- (void)_generateWithCallback: (void (^)(NSMutableString *))block - (void)_generateWithCallback: (void (^)(NSMutableString *))block
{ {
UIStoryboard *mainStoryboard =
[UIStoryboard storyboardWithName: @"Main"
bundle: nil];
UIViewController *activityController = [mainStoryboard
instantiateViewControllerWithIdentifier: @"activityIndicator"];
[self.navigationController.view addSubview: activityController.view];
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
id <PasswordGenerator> generator; id <PasswordGenerator> generator;
char *passphrase; char *passphrase;
UIStoryboard *mainStoryboard;
UIViewController *activityController;
if (_legacy) if (_legacy)
generator = [LegacyPasswordGenerator generator]; generator = [LegacyPasswordGenerator generator];
@ -184,10 +177,17 @@ clearNSMutableString(NSMutableString *string)
generator.length = _length; generator.length = _length;
passphrase = of_strdup([self.passphraseField.text UTF8String]); passphrase = of_strdup([self.passphraseField.text UTF8String]);
@try {
self.passphraseField.text = @"";
generator.passphrase = passphrase; generator.passphrase = passphrase;
mainStoryboard = [UIStoryboard storyboardWithName: @"Main"
bundle: nil];
activityController = [mainStoryboard
instantiateViewControllerWithIdentifier: @"activityIndicator"];
[self.navigationController.view addSubview: activityController.view];
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
@try {
[generator derivePassword]; [generator derivePassword];
} @finally { } @finally {
of_explicit_memset(passphrase, 0, strlen(passphrase)); of_explicit_memset(passphrase, 0, strlen(passphrase));
@ -199,9 +199,11 @@ clearNSMutableString(NSMutableString *string)
of_explicit_memset(generator.output, 0, of_explicit_memset(generator.output, 0,
strlen((char *)generator.output)); strlen((char *)generator.output));
dispatch_sync(dispatch_get_main_queue(), ^ {
activityController.view.hidden = YES; activityController.view.hidden = YES;
block(password); block(password);
}); });
});
} }
- (IBAction)remove: (id)sender - (IBAction)remove: (id)sender