Use recovery suggestion key for update permission error (#2180)

This commit is contained in:
Zorg authored and GitHub committed 2022-06-26 18:41:55 -07:00
1 parent d544d456e0
commit d2fd9a50e0
2 files changed
+18 -20

No files matched your search

+13 -19
View File
@@ -121,28 +121,22 @@
} else if (underlyingError.code == SUInstallationError) {
NSError *secondUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
if (secondUnderlyingError != nil && [secondUnderlyingError.domain isEqualToString:NSCocoaErrorDomain] && secondUnderlyingError.code == NSFileWriteNoPermissionError) {
NSBundle *mainBundle = [NSBundle mainBundle];
// macOS 13 and later introduce a policy where Gatekeeper can block app modifications if the apps have different Team IDs
BOOL warnAboutGatekeeper;
if (@available(macOS 13, *)) {
warnAboutGatekeeper = ![mainBundle isEqual:self.host.bundle];
} else {
warnAboutGatekeeper = NO;
}
// Note: these error strings will only surface for external app updaters like sparkle-cli (i.e, updaters that update other app bundles)
NSString *errorDescription;
if (warnAboutGatekeeper) {
SUHost *mainBundleHost = [[SUHost alloc] initWithBundle:mainBundle];
errorDescription = [NSString stringWithFormat:SULocalizedString(@"The installation failed due to not having permission to write the new update. To install the update, you may need to allow modifications from %1$@ in System Settings under Privacy & Security and App Management", nil), mainBundleHost.name];
} else {
errorDescription = SULocalizedString(@"The installation failed due to not having permission to write the new update.", nil);
}
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: errorDescription,
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
NSLocalizedDescriptionKey: SULocalizedString(@"The installation failed due to not having permission to write the new update.", nil),
NSUnderlyingErrorKey: (NSError * _Nonnull)currentInstallerError
};
}];
// macOS 13 and later introduce a policy where Gatekeeper can block app modifications if the apps have different Team IDs
if (@available(macOS 13, *)) {
NSBundle *mainBundle = [NSBundle mainBundle];
if (![mainBundle isEqual:self.host.bundle]) {
SUHost *mainBundleHost = [[SUHost alloc] initWithBundle:mainBundle];
userInfo[NSLocalizedRecoverySuggestionErrorKey] = [NSString stringWithFormat:SULocalizedString(@"You may need to allow modifications from %1$@ in System Settings under Privacy & Security and App Management to install future updates.", nil), mainBundleHost.name];
}
}
customError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationWriteNoPermissionError userInfo:userInfo];
}
+5 -1
View File
@@ -248,7 +248,11 @@ typedef NS_ENUM(int, CLIErrorExitStatus) {
fprintf(stderr, "%s\n", error.localizedDescription.UTF8String);
exit(CLIErrorCodeCannotInstallInteractivePackageAsRoot);
} else if (error.code == SUInstallationWriteNoPermissionError) {
fprintf(stderr, "Error: %s\n", error.localizedDescription.UTF8String);
fprintf(stderr, "Error: %s", error.localizedDescription.UTF8String);
if (error.localizedRecoverySuggestion != nil) {
fprintf(stderr, " %s", error.localizedRecoverySuggestion.UTF8String);
}
fprintf(stderr, "\n");
exit(CLIErrorExitStatusInstallationWriteNoPermissionError);
} else {
fprintf(stderr, "Error: Update has failed due to error %ld (%s). %s\n", (long)error.code, error.domain.UTF8String, error.localizedDescription.UTF8String);