Expose reason why new update is not available to user

When user is on version >= latest appcast feed item, we give them an option to view version history.

When user can't update because of a min/max OS requirement, we give them an option to view product's website.
This commit is contained in:
Zorg committed 2021-06-26 18:18:44 -07:00
1 parent 5d27dc6fb3
commit aa867a0cb9
1 file changed
+47 -5
+47 -5
View File
@@ -20,6 +20,7 @@
#import "SUApplicationInfo.h"
#import "SUOperatingSystem.h"
#import "SPUUserUpdateState.h"
#import "SUErrors.h"
#import <AppKit/AppKit.h>
@@ -250,7 +251,7 @@
alert.messageText = SULocalizedString(@"Update Error!", nil);
alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]];
[alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)];
[self showAlert:alert];
[self showAlert:alert secondaryAction:nil];
acknowledgement();
}
@@ -263,12 +264,49 @@
NSAlert *alert = [NSAlert alertWithError:error];
alert.alertStyle = NSAlertStyleInformational;
[self showAlert:alert];
// Can we give more information to the user?
SPUNoUpdateFoundReason reason = (SPUNoUpdateFoundReason)[(NSNumber *)error.userInfo[SPUNoUpdateFoundReasonKey] integerValue];
void (^secondaryAction)(void) = nil;
SUAppcastItem *latestAppcastItem = error.userInfo[SPULatestAppcastItemFoundKey];
if (latestAppcastItem != nil) {
switch (reason) {
case SPUNoUpdateFoundReasonOnLatestVersion:
case SPUNoUpdateFoundReasonOnNewerThanLatestVersion: {
if (latestAppcastItem.releaseNotesURL != nil) {
// Show the user the past version history if available
[alert addButtonWithTitle:SULocalizedString(@"Version History", nil)];
secondaryAction = ^{
[[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.releaseNotesURL];
};
}
break;
}
case SPUNoUpdateFoundReasonSystemIsTooOld:
case SPUNoUpdateFoundReasonSystemIsTooNew:
if (latestAppcastItem.infoURL != nil) {
// Show the user the product's link if available
[alert addButtonWithTitle:SULocalizedString(@"Learn More...", nil)];
secondaryAction = ^{
[[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.infoURL];
};
}
break;
case SPUNoUpdateFoundReasonUnknown:
break;
}
}
[self showAlert:alert secondaryAction:secondaryAction];
acknowledgement();
}
- (void)showAlert:(NSAlert *)alert
- (void)showAlert:(NSAlert *)alert secondaryAction:(void (^ _Nullable)(void))secondaryAction
{
id <SPUStandardUserDriverDelegate> delegate = self.delegate;
@@ -281,7 +319,11 @@
if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; }
[alert setIcon:[SUApplicationInfo bestIconForHost:self.host]];
[alert runModal];
NSModalResponse response = [alert runModal];
if (response == NSAlertSecondButtonReturn && secondaryAction != nil) {
secondaryAction();
}
if ([delegate respondsToSelector:@selector(standardUserDriverDidShowModalAlert)]) {
[delegate standardUserDriverDidShowModalAlert];
@@ -435,7 +477,7 @@
} else {
alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ is now updated!", nil), hostName];
}
[self showAlert:alert];
[self showAlert:alert secondaryAction:nil];
}
acknowledgement();