2
0

Need to -resume the task to start it, fixes issue with importing sites.

This commit is contained in:
Maarten Billemont 2017-04-14 00:24:34 -04:00
parent 2bdec415e9
commit 3fcf1131ac

View File

@ -269,80 +269,80 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
NSURL *url = openPanel.URL; NSURL *url = openPanel.URL;
[openPanel close]; [openPanel close];
[[NSURLSession sharedSession] [[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:
dataTaskWithURL:url completionHandler:^(NSData *importedSitesData, NSURLResponse *response, NSError *error) { ^(NSData *importedSitesData, NSURLResponse *response, NSError *error) {
if (error) if (error)
err( @"While reading imported sites from %@: %@", url, [error fullDescription] ); err( @"While reading imported sites from %@: %@", url, [error fullDescription] );
if (!importedSitesData) if (!importedSitesData)
return; return;
NSString *importedSitesString = [[NSString alloc] initWithData:importedSitesData encoding:NSUTF8StringEncoding]; NSString *importedSitesString = [[NSString alloc] initWithData:importedSitesData encoding:NSUTF8StringEncoding];
MPImportResult result = [self importSites:importedSitesString askImportPassword:^NSString *(NSString *userName) { MPImportResult result = [self importSites:importedSitesString askImportPassword:^NSString *(NSString *userName) {
__block NSString *masterPassword = nil; __block NSString *masterPassword = nil;
PearlMainQueueWait( ^{ PearlMainQueueWait( ^{
NSAlert *alert = [NSAlert new]; NSAlert *alert = [NSAlert new];
[alert addButtonWithTitle:@"Unlock"]; [alert addButtonWithTitle:@"Unlock"];
[alert addButtonWithTitle:@"Cancel"]; [alert addButtonWithTitle:@"Cancel"];
alert.messageText = @"Import File's Master Password"; alert.messageText = @"Import File's Master Password";
alert.informativeText = strf( @"%@'s export was done using a different master password.\n" alert.informativeText = strf( @"%@'s export was done using a different master password.\n"
@"Enter that master password to unlock the exported data.", userName ); @"Enter that master password to unlock the exported data.", userName );
alert.accessoryView = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )]; alert.accessoryView = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
[alert layout]; [alert layout];
if ([alert runModal] == NSAlertFirstButtonReturn) if ([alert runModal] == NSAlertFirstButtonReturn)
masterPassword = ((NSTextField *)alert.accessoryView).stringValue; masterPassword = ((NSTextField *)alert.accessoryView).stringValue;
} ); } );
return masterPassword; return masterPassword;
} askUserPassword:^NSString *(NSString *userName, NSUInteger importCount, NSUInteger deleteCount) { } askUserPassword:^NSString *(NSString *userName, NSUInteger importCount, NSUInteger deleteCount) {
__block NSString *masterPassword = nil; __block NSString *masterPassword = nil;
PearlMainQueueWait( ^{ PearlMainQueueWait( ^{
NSAlert *alert = [NSAlert new]; NSAlert *alert = [NSAlert new];
[alert addButtonWithTitle:@"Import"]; [alert addButtonWithTitle:@"Import"];
[alert addButtonWithTitle:@"Cancel"]; [alert addButtonWithTitle:@"Cancel"];
alert.messageText = strf( @"Master Password for\n%@", userName ); alert.messageText = strf( @"Master Password for\n%@", userName );
alert.informativeText = strf( @"Imports %lu sites, overwriting %lu.", alert.informativeText = strf( @"Imports %lu sites, overwriting %lu.",
(unsigned long)importCount, (unsigned long)deleteCount ); (unsigned long)importCount, (unsigned long)deleteCount );
alert.accessoryView = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )]; alert.accessoryView = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
[alert layout]; [alert layout];
if ([alert runModal] == NSAlertFirstButtonReturn) if ([alert runModal] == NSAlertFirstButtonReturn)
masterPassword = ((NSTextField *)alert.accessoryView).stringValue; masterPassword = ((NSTextField *)alert.accessoryView).stringValue;
} ); } );
return masterPassword; return masterPassword;
}]; }];
PearlMainQueue( ^{ PearlMainQueue( ^{
switch (result) { switch (result) {
case MPImportResultSuccess: { case MPImportResultSuccess: {
[self updateUsers]; [self updateUsers];
NSAlert *alert = [NSAlert new]; NSAlert *alert = [NSAlert new];
alert.messageText = @"Successfully imported sites."; alert.messageText = @"Successfully imported sites.";
[alert runModal]; [alert runModal];
break; break;
} }
case MPImportResultCancelled: case MPImportResultCancelled:
break; break;
case MPImportResultInternalError: case MPImportResultInternalError:
[[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ [[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{
NSLocalizedDescriptionKey: @"Import failed because of an internal error." NSLocalizedDescriptionKey: @"Import failed because of an internal error."
}]] runModal]; }]] runModal];
break; break;
case MPImportResultMalformedInput: case MPImportResultMalformedInput:
[[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ [[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{
NSLocalizedDescriptionKey: @"The import doesn't look like a Master Password export." NSLocalizedDescriptionKey: @"The import doesn't look like a Master Password export."
}]] runModal]; }]] runModal];
break; break;
case MPImportResultInvalidPassword: case MPImportResultInvalidPassword:
[[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ [[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{
NSLocalizedDescriptionKey: @"Incorrect master password for the import sites." NSLocalizedDescriptionKey: @"Incorrect master password for the import sites."
}]] runModal]; }]] runModal];
break; break;
} }
} ); } );
}]; }] resume];
} }
- (IBAction)togglePreference:(id)sender { - (IBAction)togglePreference:(id)sender {