From 2157f78ffd99369e0930d6803031f5bce0e359a3 Mon Sep 17 00:00:00 2001 From: Mayur Pawashe Date: Sat, 10 Jul 2021 08:52:06 -0700 Subject: [PATCH] Provide reason update is not found to updater delegate (#1886) --- Sparkle/SPUBasicUpdateDriver.m | 23 ++++++++++++++--------- Sparkle/SPUUpdaterDelegate.h | 14 ++++++++++++++ Sparkle/SUAppcastDriver.h | 2 +- Sparkle/SUAppcastDriver.m | 18 +++++++++--------- Sparkle/SUConstants.m | 1 + Sparkle/SUErrors.h | 1 + 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index 2e1fe8fb..c3ed3749 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -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]; } } diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index 9d456f40..b49e8c58 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -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. diff --git a/Sparkle/SUAppcastDriver.h b/Sparkle/SUAppcastDriver.h index 4aebb9c5..33ef4058 100644 --- a/Sparkle/SUAppcastDriver.h +++ b/Sparkle/SUAppcastDriver.h @@ -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 diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 324ba7dc..b86514de 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -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]; } } diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 1d3c3cd1..2160e509 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -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"; diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index 4b5a2eae..058fc927 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -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