Expose the reason and latest appcast item when update is not found

This commit is contained in:
Zorg committed 2021-06-26 16:06:39 -07:00
1 parent fefce16697
commit 5d27dc6fb3
4 files changed
+48 -7

No files matched your search

+27 -7
View File
@@ -171,6 +171,7 @@
NSString *recoverySuggestion;
NSString *recoveryOption;
SPUNoUpdateFoundReason reason;
if (latestAppcastItem != nil) {
switch (hostToLatestAppcastItemComparisonResult) {
case NSOrderedDescending:
@@ -178,12 +179,16 @@
localizedDescription = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.\n(You are currently running version %@.)", nil), [self.host name], latestAppcastItem.displayVersionString, [self.host displayVersion]];
reason = SPUNoUpdateFoundReasonOnNewerThanLatestVersion;
break;
case NSOrderedSame:
// No new update is available and we're on the latest
localizedDescription = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
reason = SPUNoUpdateFoundReasonOnLatestVersion;
break;
case NSOrderedAscending:
// This means a new update doesn't match the OS requirements
@@ -191,20 +196,26 @@
localizedDescription = SULocalizedString(@"Your macOS version is too old", nil);
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too old to install it. At least macOS %3$@ is required.", nil), [self.host name], latestAppcastItem.versionString, latestAppcastItem.minimumSystemVersion];
reason = SPUNoUpdateFoundReasonSystemIsTooOld;
} else if (!latestAppcastItem.maximumOperatingSystemVersionIsOK) {
localizedDescription = SULocalizedString(@"Your macOS version is too new", nil);
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@.", nil), [self.host name], latestAppcastItem.versionString, latestAppcastItem.maximumSystemVersion];
reason = SPUNoUpdateFoundReasonSystemIsTooNew;
} else {
// We shouldn't realistically get here
localizedDescription = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
reason = SPUNoUpdateFoundReasonUnknown;
}
break;
}
recoveryOption = @"OK";
recoveryOption = SULocalizedString(@"OK", nil);
} else {
// When no updates are found in the appcast, or latest appcast item info
// was not provided (i.e, for a background update check)
@@ -212,18 +223,27 @@
localizedDescription = SULocalizedString(@"Update Error!", nil);
recoverySuggestion = SULocalizedString(@"No valid update information could be loaded.", nil);
recoveryOption = SULocalizedString(@"Cancel Update", nil);
reason = SPUNoUpdateFoundReasonUnknown;
}
NSMutableDictionary *userInfo =
[NSMutableDictionary dictionaryWithDictionary:@{
NSLocalizedDescriptionKey: localizedDescription,
NSLocalizedRecoverySuggestionErrorKey: recoverySuggestion,
NSLocalizedRecoveryOptionsErrorKey: @[recoveryOption],
SPUNoUpdateFoundReasonKey: @(reason),
}];
if (latestAppcastItem != nil) {
userInfo[SPULatestAppcastItemFoundKey] = latestAppcastItem;
}
NSError *notFoundError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SUNoUpdateError
userInfo:@{
NSLocalizedDescriptionKey: localizedDescription,
NSLocalizedRecoverySuggestionErrorKey: recoverySuggestion,
NSLocalizedRecoveryOptionsErrorKey: @[recoveryOption]
}
];
userInfo:[userInfo copy]];
[self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
}
}
+8
View File
@@ -116,6 +116,14 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
* Before this point, -showUserInitiatedUpdateCheckWithCancellation: may be called.
*
* @param error The error associated with why a new update was not found.
* There are various reasons a new update is unavailable and can't be installed.
* This error object is populated with recovery and suggestion strings suitable to be shown in an alert.
*
* The userInfo dictionary is also populated with two keys:
* SPULatestAppcastItemFoundKey: if available, this may provide the latest SUAppcastItem that was found.
* SPUNoUpdateFoundReasonKey: if available, this will provide the SUNoUpdateFoundReason. For example the reason could be because
* the latest version in the feed requires a newer OS version or could be because the user is already on the latest version.
*
* @param acknowledgement Acknowledge to the updater that no update found error was shown.
*/
- (void)showUpdateNotFoundWithError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement;
+2
View File
@@ -57,6 +57,8 @@ NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript";
NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize";
NSString *const SUDefaultsDomainKey = @"SUDefaultsDomain";
NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain";
NSString *const SPUNoUpdateFoundReasonKey = @"SUNoUpdateFoundReason";
NSString *const SPULatestAppcastItemFoundKey = @"SULatestAppcastItemFound";
NSString *const SUAppendVersionNumberKey = @"SUAppendVersionNumber";
NSString *const SUEnableAutomatedDowngradesKey = @"SUEnableAutomatedDowngrades";
+11
View File
@@ -78,4 +78,15 @@ typedef NS_ENUM(OSStatus, SUError) {
SUIncorrectAPIUsageError = 5000
};
typedef NS_ENUM(OSStatus, SPUNoUpdateFoundReason) {
SPUNoUpdateFoundReasonUnknown,
SPUNoUpdateFoundReasonOnLatestVersion,
SPUNoUpdateFoundReasonOnNewerThanLatestVersion,
SPUNoUpdateFoundReasonSystemIsTooOld,
SPUNoUpdateFoundReasonSystemIsTooNew
};
SU_EXPORT extern NSString *const SPUNoUpdateFoundReasonKey;
SU_EXPORT extern NSString *const SPULatestAppcastItemFoundKey;
#endif