From 1aadf1b351d85095ecfa1b75d06e95f4252ac369 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 11:57:33 -0700 Subject: [PATCH] Remove passing around preventsAutoupdate flag Also improve user driver documentation slightly. --- Sparkle/SPUAutomaticUpdateDriver.m | 6 +++--- Sparkle/SPUBasicUpdateDriver.h | 2 +- Sparkle/SPUBasicUpdateDriver.m | 11 ++++++----- Sparkle/SPUCoreBasedUpdateDriver.h | 4 ++-- Sparkle/SPUCoreBasedUpdateDriver.m | 12 ++++++------ Sparkle/SPUDownloadedUpdate.m | 5 ----- Sparkle/SPUInformationalUpdate.h | 2 +- Sparkle/SPUInformationalUpdate.m | 4 +--- Sparkle/SPUProbingUpdateDriver.m | 2 +- Sparkle/SPUResumableUpdate.h | 1 - Sparkle/SPUUIBasedUpdateDriver.m | 4 ++-- Sparkle/SPUUserDriver.h | 4 ++-- Sparkle/SUAppcastDriver.h | 2 +- Sparkle/SUAppcastDriver.m | 4 +--- 14 files changed, 27 insertions(+), 36 deletions(-) diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 7c25b19b..445f2178 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -80,12 +80,12 @@ SULog(SULogLevelError, @"Error: resumeDownloadedUpdate:completion: called on SPUAutomaticUpdateDriver"); } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem { self.updateItem = updateItem; - if (updateItem.isInformationOnlyUpdate || preventsAutoupdate) { - [self.coreDriver deferInformationalUpdate:updateItem secondaryUpdate:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + if (updateItem.isInformationOnlyUpdate || updateItem.majorUpgrade) { + [self.coreDriver deferInformationalUpdate:updateItem secondaryUpdate:secondaryUpdateItem]; [self abortUpdate]; } else { [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:YES]; diff --git a/Sparkle/SPUBasicUpdateDriver.h b/Sparkle/SPUBasicUpdateDriver.h index afe99e8d..f8ff4461 100644 --- a/Sparkle/SPUBasicUpdateDriver.h +++ b/Sparkle/SPUBasicUpdateDriver.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SPUBasicUpdateDriverDelegate -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain; +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem systemDomain:(NSNumber * _Nullable)systemDomain; - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index 173bde88..a03f2e05 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -90,7 +90,8 @@ [self notifyFinishLoadingAppcast]; SUAppcastItem *nonNullUpdateItem = updateItem; - [self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:NO systemDomain:systemDomain]; +#warning please check this + [self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } } @@ -139,7 +140,7 @@ } } -- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain +- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain { if (!self.aborted) { [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -150,13 +151,13 @@ [self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem]; } - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate systemDomain:systemDomain]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } } -- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem { - [self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem preventsAutoupdate:preventsAutoupdate systemDomain:nil]; + [self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem systemDomain:nil]; } - (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 833ff946..dfb912ec 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SPUCoreBasedUpdateDriverDelegate -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem; - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently; @@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem inBackground:(BOOL)background; -- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem; - (void)extractDownloadedUpdate; diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 551fd2c2..fb07b1ef 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -149,7 +149,7 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain { self.updateItem = updateItem; self.secondaryUpdateItem = secondaryUpdateItem; @@ -157,18 +157,18 @@ if (self.resumingInstallingUpdate) { assert(systemDomain != nil); [self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem systemDomain:systemDomain.boolValue]; - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } else { if (!self.preventsInstallerInteraction) { // Simple case - delegate allows interaction, so we should continue along - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } else { // Package type installations will always require installer interaction as long as we don't support running as root // If it's not a package type installation, we should be okay since we did an auth check before checking for updates above if (![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) { [self.delegate coreDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNotAllowedInteractionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A new update is available but cannot be installed because interaction has been prevented."] }]]; } else { - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } } } @@ -225,9 +225,9 @@ [self extractUpdate:downloadedUpdate]; } -- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem { - self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } - (void)extractDownloadedUpdate diff --git a/Sparkle/SPUDownloadedUpdate.m b/Sparkle/SPUDownloadedUpdate.m index f3d7b520..5107da89 100644 --- a/Sparkle/SPUDownloadedUpdate.m +++ b/Sparkle/SPUDownloadedUpdate.m @@ -33,9 +33,4 @@ return self; } -- (BOOL)preventsAutoupdate -{ - return NO; -} - @end diff --git a/Sparkle/SPUInformationalUpdate.h b/Sparkle/SPUInformationalUpdate.h index 0d54f99d..b6979855 100644 --- a/Sparkle/SPUInformationalUpdate.h +++ b/Sparkle/SPUInformationalUpdate.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUInformationalUpdate : NSObject -- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem; @end diff --git a/Sparkle/SPUInformationalUpdate.m b/Sparkle/SPUInformationalUpdate.m index e9eec62f..4148d2cf 100644 --- a/Sparkle/SPUInformationalUpdate.m +++ b/Sparkle/SPUInformationalUpdate.m @@ -17,15 +17,13 @@ // because the property is declared in a protocol @synthesize updateItem = _updateItem; @synthesize secondaryUpdateItem = _secondaryUpdateItem; -@synthesize preventsAutoupdate = _preventsAutoupdate; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem { self = [super init]; if (self != nil) { _updateItem = updateItem; _secondaryUpdateItem = secondaryUpdateItem; - _preventsAutoupdate = preventsAutoupdate; } return self; } diff --git a/Sparkle/SPUProbingUpdateDriver.m b/Sparkle/SPUProbingUpdateDriver.m index 71257a36..f60f973d 100644 --- a/Sparkle/SPUProbingUpdateDriver.m +++ b/Sparkle/SPUProbingUpdateDriver.m @@ -54,7 +54,7 @@ [self.basicDriver resumeUpdate:resumableUpdate completion:completionBlock]; } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem secondaryAppcastItem:(SUAppcastItem *)__unused secondaryAppcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate systemDomain:(NSNumber * _Nullable)__unused systemDomain +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem secondaryAppcastItem:(SUAppcastItem *)__unused secondaryAppcastItem systemDomain:(NSNumber * _Nullable)__unused systemDomain { // Stop as soon as we have an answer [self abortUpdate]; diff --git a/Sparkle/SPUResumableUpdate.h b/Sparkle/SPUResumableUpdate.h index 895a80c8..1b138587 100644 --- a/Sparkle/SPUResumableUpdate.h +++ b/Sparkle/SPUResumableUpdate.h @@ -16,7 +16,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) SUAppcastItem *updateItem; @property (nonatomic, readonly, nullable) SUAppcastItem *secondaryUpdateItem; -@property (nonatomic, readonly) BOOL preventsAutoupdate; @end diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 775c01c9..9c7f13b6 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -148,7 +148,7 @@ { // Informational downloads shouldn't be presented as updates to be downloaded // Neither should items that prevent auto updating - if (!resumableUpdate.updateItem.isInformationOnlyUpdate && !resumableUpdate.preventsAutoupdate) { + if (!resumableUpdate.updateItem.isInformationOnlyUpdate && !resumableUpdate.updateItem.majorUpgrade) { self.resumingDownloadedUpdate = YES; } [self.coreDriver resumeUpdate:resumableUpdate completion:completionBlock]; @@ -161,7 +161,7 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem { if (self.userInitiated) { [SPUSkippedUpdate clearSkippedUpdateForHost:self.host]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 6bb4259a..05344ea9 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -68,8 +68,8 @@ SU_EXPORT @protocol SPUUserDriver * * state.userInitiated indicates if the update was initiated by the user or if it was automatically scheduled in the background. * - * Additionally, these two properties on the appcastItem may be of importance: - * appcastItem.informationOnlyUpdate indicates if the update is only informational. These updates cannot be installed because they have no download. You can direct the user to the infoURL property of the appcastItem in their web browser. + * Additionally, these properties on the appcastItem are of importance: + * appcastItem.informationOnlyUpdate indicates if the update is only informational. These updates cannot be installed because they have no download. You can direct the user to the infoURL property of the appcastItem in their web browser. Sometimes information only updates are used as a fallback in case a bad update is shipped, so you'll want to support this case. * appcastItem.majorUpgrade indicates if the update is a major or paid upgrade. * appcastItem.criticalUpdate indicates if the update is a critical update. * diff --git a/Sparkle/SUAppcastDriver.h b/Sparkle/SUAppcastDriver.h index 12509e3a..560ec6a4 100644 --- a/Sparkle/SUAppcastDriver.h +++ b/Sparkle/SUAppcastDriver.h @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)didFailToFetchAppcastWithError:(NSError *)error; - (void)didFinishLoadingAppcast:(SUAppcast *)appcast; -- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem; - (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult; @end diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index b8ff51ab..f2ec1d59 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -200,9 +200,7 @@ if ([self isItemNewer:finalPrimaryItem]) { // We found a suitable update - BOOL preventsAutoupdate = finalPrimaryItem.majorUpgrade; - - [self.delegate didFindValidUpdateWithAppcastItem:finalPrimaryItem secondaryAppcastItem:finalSecondaryItem preventsAutoupdate:preventsAutoupdate]; + [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