Created
September 10, 2021 14:44
-
-
Save roustem/007a42f660be055cae433542ad33d86b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)checkAllTheBadLaunchStates { | |
NSURL *bundleURL = [[NSBundle mainBundle] bundleURL]; | |
if ([bundleURL.path hasPrefix:@"/Applications"] && [bundleURL ag_isQuarantined]) { | |
log_error(self, @"Application has been translocated"); | |
NSString *title = OPLocalizedString(@"The system has quarantined 1Password.", @"title: 1Password has been quarantined by macOS."); | |
NSString *message = OPLocalizedString(@"1Password was not moved to the Applications folder correctly. To fix this issue, 1Password will copy a command to the Clipboard that you can paste in Terminal.", @"message: we're in AppTranlocation jail, updates will fail, no extensions will work."); | |
NSString *defaultButton = OPLocalizedString(@"Open Terminal", @"button: opens the Terminal app"); | |
NSString *secondaryButton = OPLocalizedString(@"Quit 1Password", @""); | |
op_showAlert(title, message, defaultButton, secondaryButton, nil, NO, ^(NSAlert *alert, NSModalResponse response) { | |
if (response == NSAlertFirstButtonReturn) { | |
NSString *command = [NSString stringWithFormat:@"sudo xattr -r -d com.apple.quarantine \"%@\" && open \"%@\"", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] bundlePath]]; | |
[[NSPasteboard generalPasteboard] clearContents]; | |
BOOL success = [[NSPasteboard generalPasteboard] setString:command forType:NSPasteboardTypeString]; | |
if (success) { | |
[[NSWorkspace sharedWorkspace] launchApplication:@"Terminal"]; | |
NSString *title = OPLocalizedString(@"Command Copied", @""); | |
NSString *informativeText = OPLocalizedString(@"Choose Edit > Paste and press Return.", @""); | |
NSUserNotification *notification = [OPLocalNotificationHelper notificationForIdentifier:@"com.agilebits.onepassword7.app-translocated" title:title subtitle:nil informativeText:informativeText image: nil actionButtonTitle:nil userInfo: nil]; | |
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; | |
} | |
else { | |
log_error(self, @"Failed to put the command on the pasteboard"); | |
} | |
} | |
exit(0); | |
}); | |
} | |
else if ([bundleURL.path containsString:@".Trash"]) { | |
log_error(self, @"Application is in the trash, this isn't a workable configuration"); | |
NSString *title = OPLocalizedString(@"1Password is trashed. 🥃", @"title "); | |
NSString *message = OPLocalizedString(@"1Password can’t be opened from the Trash. To fix the issue, move 1Password to the Applications folder.", @"message; when the user has somehow managed to launch 1Password form the trash"); | |
NSString *defaultButton = OPLocalizedString(@"Show 1Password in Finder", @"button: OK"); | |
NSString *secondaryButton = OPLocalizedString(@"Quit 1Password", @""); | |
op_showAlert(title, message, defaultButton, secondaryButton, nil, NO, ^(NSAlert *alert, NSModalResponse response) { | |
if (response == NSAlertFirstButtonReturn) { | |
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[bundleURL]]; | |
} | |
exit(0); | |
}); | |
} | |
else if ([bundleURL.path hasPrefix:@"/Applications"] == NO && isRunningFromXcode() == NO) { | |
log_error(self, @"Application is not in the /Applications folder"); | |
NSString *title = OPLocalizedString(@"1Password can’t fill or save in your browser.", @"title: 1Password isn't in the /Applications folder, so none of the browser extension can work."); | |
NSString *message = OPLocalizedString(@"1Password must be in the Applications folder to fill and save in your browser. To fix this issue, move 1Password to the Applications folder.", @"message; when the user has 1Password located somewhere other than the /Applications folder."); | |
NSString *defaultButton = OPLocalizedString(@"Show 1Password in Finder", @"button: OK"); | |
NSString *ignoreButton = OPLocalizedString(@"Ignore", @"button: OK"); | |
op_showAlert(title, message, defaultButton, ignoreButton, nil, NO, ^(NSAlert *alert, NSModalResponse response) { | |
if (response == NSAlertFirstButtonReturn) { | |
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[bundleURL]]; | |
exit(0); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment