Skip to content

Commit

Permalink
Unlock volume on background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
kainjow committed Dec 1, 2018
1 parent a665b79 commit 5a32067
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions SLDiskManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,22 @@ - (void)unlockDisk:(SLDisk *)disk withPassword:(NSString *)password
NSString *volumeKind = disk.volumeKind;
NSString *diskID = disk.diskID;

// Execute diskutil, passing the volumeKind and the encryption password
int status = -1;
NSArray *args = @[volumeKind, @"unlockVolume", diskID, @"-passphrase", password];
NSString *output = [NSTask outputStringForTaskAtPath:@"/usr/sbin/diskutil" arguments:args encoding:NSUTF8StringEncoding status:&status];

// In case return code is not zero, there was an error
if (status != 0) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"There was an error unlocking the disk", nil);
alert.informativeText = output;
[alert runModal];
}
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// Execute diskutil, passing the volumeKind and the encryption password
int status = -1;
NSArray *args = @[volumeKind, @"unlockVolume", diskID, @"-passphrase", password];
NSString *output = [NSTask outputStringForTaskAtPath:@"/usr/sbin/diskutil" arguments:args encoding:NSUTF8StringEncoding status:&status];

dispatch_async(dispatch_get_main_queue(), ^{
// In case return code is not zero, there was an error
if (status != 0) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"There was an error unlocking the disk", nil);
alert.informativeText = output;
[alert runModal];
}
});
});
}

typedef void (^SLEjectHandler)(BOOL ejected);
Expand Down

0 comments on commit 5a32067

Please sign in to comment.