Provide reason update is not found to updater delegate (#1886)

This commit is contained in:
Mayur Pawashe authored and GitHub committed 2021-07-10 08:52:06 -07:00
1 parent e5c63b6369
commit 2157f78ffd
6 files changed
+40 -19

No files matched your search

+14 -9
View File
@@ -159,14 +159,9 @@
[self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem systemDomain:nil];
}
- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult
- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult background:(BOOL)background
{
if (!self.aborted) {
if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) {
[self.updaterDelegate updaterDidNotFindUpdate:self.updater];
}
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
NSString *localizedDescription;
NSString *recoverySuggestion;
@@ -190,7 +185,8 @@
reason = SPUNoUpdateFoundReasonOnLatestVersion;
break;
case NSOrderedAscending:
// This means a new update doesn't match the OS requirements
// A new update is available but cannot be installed
if (!latestAppcastItem.minimumOperatingSystemVersionIsOK) {
localizedDescription = SULocalizedString(@"Your macOS version is too old", nil);
@@ -214,8 +210,7 @@
break;
}
} else {
// When no updates are found in the appcast, or latest appcast item info
// was not provided (i.e, for a background update check)
// When no updates are found in the appcast
// We will need to assume the user is up to date if the feed doen't have any applicable update items
// There could be update items on channels the updater is not subscribed to for example. But we can't tell the user about them.
// There could also only be update items available for other platforms or none at all.
@@ -233,6 +228,7 @@
NSLocalizedRecoverySuggestionErrorKey: recoverySuggestion,
NSLocalizedRecoveryOptionsErrorKey: @[recoveryOption],
SPUNoUpdateFoundReasonKey: @(reason),
SPUNoUpdateFoundUserInitiatedKey: @(!background),
}];
if (latestAppcastItem != nil) {
@@ -244,6 +240,15 @@
errorWithDomain:SUSparkleErrorDomain
code:SUNoUpdateError
userInfo:[userInfo copy]];
if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:error:))]) {
[self.updaterDelegate updaterDidNotFindUpdate:self.updater error:notFoundError];
} else if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) {
[self.updaterDelegate updaterDidNotFindUpdate:self.updater];
}
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater userInfo:userInfo];
[self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
}
}
+14
View File
@@ -222,6 +222,20 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck)
*/
- (void)updater:(SPUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item;
/*!
Called when a valid update is not found.
\param updater The updater instance.
\param error An error containing information on why a new valid update was not found
There are various reasons a new update is unavailable and can't be installed.
The userInfo dictionary on the error is also populated with three keys:
SPULatestAppcastItemFoundKey: if available, this may provide the latest SUAppcastItem that was found. This will be nil if it's unavailable.
SPUNoUpdateFoundReasonKey: 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.
SPUNoUpdateFoundUserInitiatedKey: A boolean that indicates if a new update was not found when the user intitiated an update check manually.
*/
- (void)updaterDidNotFindUpdate:(SPUUpdater *)updater error:(NSError *)error;
/*!
Called when a valid update is not found.
+1 -1
View File
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)didFailToFetchAppcastWithError:(NSError *)error;
- (void)didFinishLoadingAppcast:(SUAppcast *)appcast;
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem;
- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult;
- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult background:(BOOL)background;
@end
+9 -9
View File
@@ -223,21 +223,21 @@
// We found a suitable update
[self.delegate didFindValidUpdateWithAppcastItem:finalPrimaryItem secondaryAppcastItem:finalSecondaryItem];
} else {
// Find the latest appcast item even if it fails min/max OS test
// We want to inform the user if an update requires a different OS version
// We only need to do this if an update is being checked by the user manually
SUAppcastItem *notFoundPrimaryItem;
// Find the latest appcast item that we can report to the user and updater delegates
// This may include updates that fail due to OS version requirements.
// This excludes newer backgrounded updates that fail because they are skipped or not in current phased rollout group
SUAppcast *notFoundAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdate:skippedUpdate hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:NO testMinimumAutoupdateVersion:NO];
SUAppcastItem *notFoundPrimaryItem = [self retrieveBestAppcastItemFromAppcast:notFoundAppcast versionComparator:applicationVersionComparator secondaryUpdate:nil];
NSComparisonResult hostToLatestAppcastItemComparisonResult;
if (!background) {
notFoundPrimaryItem = [self retrieveBestAppcastItemFromAppcast:macOSAppcast versionComparator:applicationVersionComparator secondaryUpdate:nil];
if (notFoundPrimaryItem != nil) {
hostToLatestAppcastItemComparisonResult = [applicationVersionComparator compareVersion:self.host.version toVersion:notFoundPrimaryItem.versionString];
} else {
notFoundPrimaryItem = nil;
hostToLatestAppcastItemComparisonResult = 0;
}
[self.delegate didNotFindUpdateWithLatestAppcastItem:notFoundPrimaryItem hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult];
[self.delegate didNotFindUpdateWithLatestAppcastItem:notFoundPrimaryItem hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult background:background];
}
}
+1
View File
@@ -58,6 +58,7 @@ NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize";
NSString *const SUDefaultsDomainKey = @"SUDefaultsDomain";
NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain";
NSString *const SPUNoUpdateFoundReasonKey = @"SUNoUpdateFoundReason";
NSString *const SPUNoUpdateFoundUserInitiatedKey = @"SPUNoUpdateUserInitiated";
NSString *const SPULatestAppcastItemFoundKey = @"SULatestAppcastItemFound";
NSString *const SUAppendVersionNumberKey = @"SUAppendVersionNumber";
+1
View File
@@ -88,5 +88,6 @@ typedef NS_ENUM(OSStatus, SPUNoUpdateFoundReason) {
SU_EXPORT extern NSString *const SPUNoUpdateFoundReasonKey;
SU_EXPORT extern NSString *const SPULatestAppcastItemFoundKey;
SU_EXPORT extern NSString *const SPUNoUpdateFoundUserInitiatedKey;
#endif