From 253f45b476ce62393e57b09749816f7a1bb36c40 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 30 May 2021 23:32:45 -0700 Subject: [PATCH 01/29] Add optional version field to sparkle:criticalUpdate element This version indicates the version that was first marked critical. So versions below this specified version will treat the update as critical while versions >= the specified version will not. Also move sparkle:criticalUpdate to root level element instead of it being a tag. The tagged version is now deprecated and doesn't support the version field. --- Sparkle.xcodeproj/project.pbxproj | 12 ++++ Sparkle/SPUAppcastItemSelection.h | 30 ++++++++ Sparkle/SPUAppcastItemSelection.m | 82 ++++++++++++++++++++++ Sparkle/SPUAutomaticUpdateDriver.m | 7 +- Sparkle/SPUUIBasedUpdateDriver.m | 4 +- Sparkle/SPUUpdater.m | 3 +- Sparkle/SPUUserUpdateState+Private.h | 2 +- Sparkle/SPUUserUpdateState.h | 1 + Sparkle/SPUUserUpdateState.m | 9 ++- Sparkle/SUAppcast.m | 8 +-- Sparkle/SUAppcastDriver.m | 23 ++---- Sparkle/SUAppcastItem+Private.h | 2 + Sparkle/SUAppcastItem.h | 2 +- Sparkle/SUAppcastItem.m | 23 +++++- Sparkle/SUUpdateAlert.m | 6 +- Tests/Resources/testappcast.xml | 2 +- Tests/SUAppcastTest.swift | 15 ++-- Tests/Sparkle Unit Tests-Bridging-Header.h | 1 + 18 files changed, 195 insertions(+), 37 deletions(-) create mode 100644 Sparkle/SPUAppcastItemSelection.h create mode 100644 Sparkle/SPUAppcastItemSelection.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 5bf88164..45009beb 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -323,6 +323,10 @@ 7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 7293A1B11CEE9B9F00B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 729924941DF4A45000DBCDF5 /* SUUpdateValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */; }; + 729E1D16266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */; }; + 729E1D17266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */; }; + 729E1D18266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */; }; + 729E1D19266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */; }; 72A1C2631CD6849C004CD282 /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; }; 72A450531C69A68900D67EEA /* SUUpdatePermissionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A450541C69A68900D67EEA /* SUUpdatePermissionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */; }; @@ -1294,6 +1298,8 @@ 729924921DF4A45000DBCDF5 /* SUUpdateValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUUpdateValidator.h; path = Sparkle/SUUpdateValidator.h; sourceTree = SOURCE_ROOT; }; 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUUpdateValidator.m; path = Sparkle/SUUpdateValidator.m; sourceTree = SOURCE_ROOT; }; 729BB3D11D503826007C4276 /* org.sparkle-project.Downloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "org.sparkle-project.Downloader.entitlements"; path = "Downloader/org.sparkle-project.Downloader.entitlements"; sourceTree = SOURCE_ROOT; }; + 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemSelection.h; sourceTree = ""; }; + 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemSelection.m; sourceTree = ""; }; 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = ""; }; 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdatePermissionResponse.h; sourceTree = ""; }; @@ -1877,6 +1883,8 @@ 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */, 725DED73263D123900E7FA8F /* SUAppcastItem+Private.h */, 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */, + 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */, + 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */, 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */, 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */, 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */, @@ -2399,6 +2407,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 729E1D17266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */, 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */, 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */, 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, @@ -2453,6 +2462,7 @@ 720E217B1D0D00BF003A311C /* SPUUpdaterCycle.h in Headers */, 72F9EC481D5EA904004AC8B6 /* SPUUpdaterDelegate.h in Headers */, 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */, + 729E1D16266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */, 72F9EC3F1D5E823F004AC8B6 /* SPUUpdaterTimer.h in Headers */, 7269E494264798200088C213 /* SPUSkippedUpdate.h in Headers */, 723ABFC4259D4CB300BDB4FA /* SUWKWebView.h in Headers */, @@ -3574,6 +3584,7 @@ 72A5D5C51D6929F80009E5AC /* SULog.m in Sources */, 72A5D5C61D6929F80009E5AC /* SUOperatingSystem.m in Sources */, 72A5D5BE1D6929F80009E5AC /* SUStandardVersionComparator.m in Sources */, + 729E1D19266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */, 72A5D5BF1D6929F80009E5AC /* SUSystemProfiler.m in Sources */, 72A5D5D71D6929F80009E5AC /* SUUpdatePermissionResponse.m in Sources */, 72A5D5B11D6929F80009E5AC /* SUXPCInstallerConnection.m in Sources */, @@ -3674,6 +3685,7 @@ 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */, 7269E49A2648F7C00088C213 /* SPUUserUpdateState.m in Sources */, 725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */, + 729E1D18266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */, 7214B8821D456A8500CB5CED /* SUBundleIcon.m in Sources */, 72DBA37F1D62C23E002594A8 /* SUCodeSigningVerifier.m in Sources */, 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */, diff --git a/Sparkle/SPUAppcastItemSelection.h b/Sparkle/SPUAppcastItemSelection.h new file mode 100644 index 00000000..bc2ec307 --- /dev/null +++ b/Sparkle/SPUAppcastItemSelection.h @@ -0,0 +1,30 @@ +// +// SPUAppcastItemSelection.h +// Sparkle +// +// Created by Mayur Pawashe on 5/30/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import + +@class SUAppcastItem; +@class SUHost; +@class SPUUpdater; + +@protocol SPUUpdaterDelegate; +@protocol SUVersionComparison; + +NS_ASSUME_NONNULL_BEGIN + +// Functions for querying if appcast item properties that depend on current host version + +BOOL SPUAppcastItemIsCriticalWithComparator(SUAppcastItem *appcastItem, NSString *hostVersion, id versionComparator); + +BOOL SPUAppcastItemIsCritical(SUAppcastItem *appcastItem, NSString *hostVersion, SPUUpdater *updater, id _Nullable updaterDelegate); + +id SPUVersionComparator(SPUUpdater *updater, id _Nullable updaterDelegate); + +BOOL SPUAppcastItemContainsCriticalTag(SUAppcastItem *appcastItem); + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemSelection.m b/Sparkle/SPUAppcastItemSelection.m new file mode 100644 index 00000000..89ff0956 --- /dev/null +++ b/Sparkle/SPUAppcastItemSelection.m @@ -0,0 +1,82 @@ +// +// SPUAppcastItemSelection.m +// Sparkle +// +// Created by Mayur Pawashe on 5/30/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUAppcastItemSelection.h" +#import "SUHost.h" +#import "SUAppcastItem.h" +#import "SUAppcastItem+Private.h" +#import "SPUUpdater.h" +#import "SPUUpdaterDelegate.h" +#import "SUStandardVersionComparator.h" +#import "SUVersionComparisonProtocol.h" +#import "SUConstants.h" + + +#include "AppKitPrevention.h" + +static NSString * _Nullable SPUAppcastItemCriticalUpdateVersion(SUAppcastItem *appcastItem, BOOL *isCriticalWithoutVersion) +{ + NSDictionary *criticalUpdateDictionary = appcastItem.criticalUpdateDictionary; + if (criticalUpdateDictionary == nil) { + *isCriticalWithoutVersion = NO; + return nil; + } + + NSString *criticalVersion = criticalUpdateDictionary[SUAppcastAttributeVersion]; + if (criticalVersion == nil || ![criticalVersion isKindOfClass:[NSString class]]) { + *isCriticalWithoutVersion = YES; + return nil; + } + + return criticalVersion; +} + +static BOOL SPUCriticalUpdateTest(id versionComparator, NSString *hostVersion, NSString *criticalVersion) +{ + return ([versionComparator compareVersion:hostVersion toVersion:criticalVersion] == NSOrderedAscending); +} + +BOOL SPUAppcastItemIsCriticalWithComparator(SUAppcastItem *appcastItem, NSString *hostVersion, id versionComparator) +{ + BOOL isCriticalWithoutVersion = NO; + NSString *criticalVersion = SPUAppcastItemCriticalUpdateVersion(appcastItem, &isCriticalWithoutVersion); + if (criticalVersion == nil) { + return isCriticalWithoutVersion; + } + + return SPUCriticalUpdateTest(versionComparator, hostVersion, criticalVersion); +} + +BOOL SPUAppcastItemIsCritical(SUAppcastItem *appcastItem, NSString *hostVersion, SPUUpdater *updater, id _Nullable updaterDelegate) +{ + BOOL isCriticalWithoutVersion = NO; + NSString *criticalVersion = SPUAppcastItemCriticalUpdateVersion(appcastItem, &isCriticalWithoutVersion); + if (criticalVersion == nil) { + return isCriticalWithoutVersion; + } + + id versionComparator = SPUVersionComparator(updater, updaterDelegate); + return SPUCriticalUpdateTest(versionComparator, hostVersion, criticalVersion); +} + +id SPUVersionComparator(SPUUpdater *updater, id _Nullable updaterDelegate) +{ + id comparator = nil; + + // Give the delegate a chance to provide a custom version comparator + if ([updaterDelegate respondsToSelector:@selector((versionComparatorForUpdater:))]) { + comparator = [updaterDelegate versionComparatorForUpdater:(id _Nonnull)updater]; + } + + // If we don't get a comparator from the delegate, use the default comparator + if (comparator == nil) { + comparator = [SUStandardVersionComparator defaultComparator]; + } + + return comparator; +} diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index bb497601..2635762f 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -15,12 +15,14 @@ #import "SUAppcastItem.h" #import "SPUUserDriver.h" #import "SUErrors.h" +#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @interface SPUAutomaticUpdateDriver () +@property (nonatomic, readonly) SUHost *host; @property (nonatomic, readonly, weak) id updater; @property (nonatomic, readonly, weak) id userDriver; @property (nonatomic, readonly, weak, nullable) id updaterDelegate; @@ -32,6 +34,7 @@ @implementation SPUAutomaticUpdateDriver +@synthesize host = _host; @synthesize updater = _updater; @synthesize userDriver = _userDriver; @synthesize updaterDelegate = _updaterDelegate; @@ -43,6 +46,7 @@ { self = [super init]; if (self != nil) { + _host = host; _updater = updater; // The user driver is only used for a termination callback _userDriver = userDriver; @@ -133,7 +137,8 @@ - (void)abortUpdateWithError:(NSError *)error { - BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate || self.updateItem.isInformationOnlyUpdate); + BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || SPUAppcastItemIsCritical(self.updateItem, self.host.version, self.updater, self.updaterDelegate) || self.updateItem.isInformationOnlyUpdate); + [self.coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error]; } diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 4c62a506..6a181c7a 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -19,6 +19,7 @@ #import "SPUDownloadDriver.h" #import "SPUSkippedUpdate.h" #import "SPUUserUpdateState+Private.h" +#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @@ -181,8 +182,9 @@ } BOOL majorUpgrade = preventsAutoupdate; + BOOL criticalUpdate = SPUAppcastItemIsCritical(updateItem, self.host.version, self.updater, self.updaterDelegate); - SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade]; + SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 89a8800c..2adb175e 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -30,6 +30,7 @@ #import "SPUUpdaterTimer.h" #import "SPUResumableUpdate.h" #import "SUSignatures.h" +#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @@ -884,7 +885,7 @@ static NSString *escapeURLComponent(NSString *str) { // Proceed as normal if there's no resumable updates completionHandler(regularCheckInterval); } else { - if (!installationInfo.canSilentlyInstall || [installationInfo.appcastItem isCriticalUpdate] || [installationInfo.appcastItem isInformationOnlyUpdate]) { + if (!installationInfo.canSilentlyInstall || SPUAppcastItemIsCritical(((SPUInstallationInfo * _Nonnull)installationInfo).appcastItem, self.host.version, self, self.delegate) || [installationInfo.appcastItem isInformationOnlyUpdate]) { completionHandler(MIN(regularCheckInterval, SUImpatientUpdateCheckInterval)); } else { completionHandler(MAX(regularCheckInterval, SUImpatientUpdateCheckInterval)); diff --git a/Sparkle/SPUUserUpdateState+Private.h b/Sparkle/SPUUserUpdateState+Private.h index 90e732c4..cd58b47a 100644 --- a/Sparkle/SPUUserUpdateState+Private.h +++ b/Sparkle/SPUUserUpdateState+Private.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUUserUpdateState (Private) -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade; +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate; @end diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUserUpdateState.h index b1be0c91..1611f9d7 100644 --- a/Sparkle/SPUUserUpdateState.h +++ b/Sparkle/SPUUserUpdateState.h @@ -40,6 +40,7 @@ SU_EXPORT @interface SPUUserUpdateState : NSObject @property (nonatomic, readonly) SPUUserUpdateStage stage; @property (nonatomic, readonly) BOOL userInitiated; @property (nonatomic, readonly) BOOL majorUpgrade; +@property (nonatomic, readonly) BOOL criticalUpdate; @end diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUserUpdateState.m index 935f6766..576f4db2 100644 --- a/Sparkle/SPUUserUpdateState.m +++ b/Sparkle/SPUUserUpdateState.m @@ -15,20 +15,23 @@ #define SPUUserUpdateStateStageKey @"SPUUserUpdateStateStage" #define SPUUserUpdateStateUserInitiatedKey @"SPUUserUpdateStateUserInitiated" #define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" +#define SPUUserUpdateStateCriticalUpdateKey @"SPUUserUpdateStateCriticalUpdate" @implementation SPUUserUpdateState @synthesize stage = _stage; @synthesize userInitiated = _userInitiated; @synthesize majorUpgrade = _majorUpgrade; +@synthesize criticalUpdate = _criticalUpdate; -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate { self = [super init]; if (self != nil) { _stage = stage; _userInitiated = userInitiated; _majorUpgrade = majorUpgrade; + _criticalUpdate = criticalUpdate; } return self; } @@ -38,6 +41,7 @@ [encoder encodeInteger:self.stage forKey:SPUUserUpdateStateStageKey]; [encoder encodeBool:self.userInitiated forKey:SPUUserUpdateStateUserInitiatedKey]; [encoder encodeBool:self.majorUpgrade forKey:SPUUserUpdateStateMajorUpgradeKey]; + [encoder encodeBool:self.criticalUpdate forKey:SPUUserUpdateStateCriticalUpdateKey]; } - (instancetype)initWithCoder:(NSCoder *)decoder @@ -45,8 +49,9 @@ SPUUserUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; BOOL userInitiated = [decoder decodeBoolForKey:SPUUserUpdateStateUserInitiatedKey]; BOOL majorUpgrade = [decoder decodeBoolForKey:SPUUserUpdateStateMajorUpgradeKey]; + BOOL criticalUpdate = [decoder decodeBoolForKey:SPUUserUpdateStateCriticalUpdateKey]; - return [self initWithStage:stage userInitiated:userInitiated majorUpgrade:majorUpgrade]; + return [self initWithStage:stage userInitiated:userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; } + (BOOL)supportsSecureCoding diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 8b262a7f..2fafa686 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -119,10 +119,10 @@ for (NSString *name in nodesDict) { node = [self bestNodeInNodes:[nodesDict objectForKey:name]]; - if ([name isEqualToString:SURSSElementEnclosure]) { - // enclosure is flattened as a separate dictionary for some reason - NSDictionary *encDict = [self attributesOfNode:(NSXMLElement *)node]; - [dict setObject:encDict forKey:name]; + if ([name isEqualToString:SURSSElementEnclosure] || [name isEqualToString:SUAppcastElementCriticalUpdate]) { + // These are flattened as a separate dictionary for some reason + NSDictionary *innerDict = [self attributesOfNode:(NSXMLElement *)node]; + [dict setObject:innerDict forKey:name]; } else if ([name isEqualToString:SURSSElementPubDate]) { // We don't want to parse and create a NSDate instance - diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 61358cc0..42627d7d 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -23,6 +23,7 @@ #import "SPUDownloadData.h" #import "SULocalizations.h" #import "SUErrors.h" +#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @@ -30,7 +31,7 @@ @interface SUAppcastDriver () @property (nonatomic, readonly) SUHost *host; -@property (nullable, nonatomic, readonly, weak) id updater; +@property (nonatomic, readonly, weak) id updater; @property (nullable, nonatomic, readonly, weak) id updaterDelegate; @property (nullable, nonatomic, readonly, weak) id delegate; @property (nonatomic) SPUDownloadDriver *downloadDriver; @@ -237,7 +238,7 @@ return [appcast copyByFilteringItems:^(SUAppcastItem *item) { BOOL passesOSVersion = (!testOSVersion || [self isItemMinimumAndMaximumOperatingSystemVersionOK:item]); - BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate]; + BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate hostVersion:hostVersion versionComparator:versionComparator]; BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || hostVersion == nil || versionComparator == nil || [self isItemMinimumAutoupdateVersionOK:item.minimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]); @@ -310,19 +311,7 @@ - (id)versionComparator { - id comparator = nil; - - // Give the delegate a chance to provide a custom version comparator - if ([self.updaterDelegate respondsToSelector:@selector((versionComparatorForUpdater:))]) { - comparator = [self.updaterDelegate versionComparatorForUpdater:(id _Nonnull)self.updater]; - } - - // If we don't get a comparator from the delegate, use the default comparator - if (!comparator) { - comparator = [[SUStandardVersionComparator alloc] init]; - } - - return comparator; + return SPUVersionComparator(self.updater, self.updaterDelegate); } - (BOOL)isItemNewer:(SUAppcastItem *)ui @@ -351,9 +340,9 @@ return NO; } -+ (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate ++ (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator { - if (phasedUpdateGroup == nil || [ui isCriticalUpdate]) { + if (phasedUpdateGroup == nil || SPUAppcastItemIsCriticalWithComparator(ui, hostVersion, versionComparator)) { return YES; } diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h index b368c6a8..1c939cf0 100644 --- a/Sparkle/SUAppcastItem+Private.h +++ b/Sparkle/SUAppcastItem+Private.h @@ -25,6 +25,8 @@ NS_ASSUME_NONNULL_BEGIN // Initializes with data from a dictionary provided by the RSS class. - (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; +@property (nullable, nonatomic, readonly) NSDictionary *criticalUpdateDictionary; + @end NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index ec8f7fd8..7c8b9f00 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -43,7 +43,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly, nullable) NSString *minimumAutoupdateVersion; @property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; -@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate; +@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate __deprecated_msg("Use SPUUserUpdateState.criticalUpdate instead"); @property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 405007a7..0d5c44da 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -188,7 +188,28 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT - (BOOL)isCriticalUpdate { - return [(NSArray *)[self.propertiesDictionary objectForKey:SUAppcastElementTags] containsObject:SUAppcastElementCriticalUpdate]; + return self.criticalUpdateDictionary != nil; +} + +- (NSDictionary * _Nullable)criticalUpdateDictionary +{ + NSDictionary *criticalUpdateDictionary = self.propertiesDictionary[SUAppcastElementCriticalUpdate]; + if (criticalUpdateDictionary != nil) { + return criticalUpdateDictionary; + } + + NSArray *tags = [self.propertiesDictionary objectForKey:SUAppcastElementTags]; + if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { + return @{}; + } + + return nil; +} + +- (BOOL)containsCriticalUpdateTag +{ + NSArray *tags = [self.propertiesDictionary objectForKey:SUAppcastElementTags]; + return [tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]; } - (BOOL)isMacOsUpdate diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 8a2e3194..1d293e87 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -380,7 +380,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); } - if ([self.updateItem isCriticalUpdate] && !self.state.majorUpgrade) { + if (self.state.criticalUpdate && !self.state.majorUpgrade) { self.skipButton.hidden = YES; self.laterButton.hidden = YES; } @@ -406,7 +406,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (NSString *)titleText { - if ([self.updateItem isCriticalUpdate]) + if (self.state.criticalUpdate) { return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [self.host name]]; } @@ -437,7 +437,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE if (self.state.stage == SPUUserUpdateStageInformational) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; - } else if ([self.updateItem isCriticalUpdate]) { + } else if (self.state.criticalUpdate) { if (self.state.stage == SPUUserUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. This is an important update; would you like to download it now?", @"Description text for SUUpdateAlert when the critical update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index d602ba7b..7121e47a 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -7,7 +7,7 @@ desc Sat, 26 Jul 2014 15:20:11 +0000 - + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index dfc8110a..54c8ba1a 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -21,28 +21,35 @@ class SUAppcastTest: XCTestCase { let items = appcast.items XCTAssertEqual(4, items.count) + + let standardComparator = SUStandardVersionComparator() XCTAssertEqual("Version 2.0", items[0].title) XCTAssertEqual("desc", items[0].itemDescription) XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString) - XCTAssertTrue(items[0].isCriticalUpdate) + XCTAssertTrue(SPUAppcastItemIsCriticalWithComparator(items[0], "1.0", standardComparator)) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[0], "1.5", standardComparator)) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[0], "2.0", standardComparator)) // This is the best release matching our system version XCTAssertEqual("Version 3.0", items[1].title) XCTAssertNil(items[1].itemDescription) XCTAssertNil(items[1].dateString) - XCTAssertFalse(items[1].isCriticalUpdate) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[1], "1.0", standardComparator)) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[1], "2.0", standardComparator)) XCTAssertEqual(items[1].phasedRolloutInterval, 86400) XCTAssertEqual("Version 4.0", items[2].title) XCTAssertNil(items[2].itemDescription) XCTAssertEqual("Sat, 26 Jul 2014 15:20:13 +0000", items[2].dateString) - XCTAssertFalse(items[2].isCriticalUpdate) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[2], "1.0", standardComparator)) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[2], "2.0", standardComparator)) XCTAssertEqual("Version 5.0", items[3].title) XCTAssertNil(items[3].itemDescription) XCTAssertNil(items[3].dateString) - XCTAssertFalse(items[3].isCriticalUpdate) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[3], "1.0", standardComparator)) + XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[3], "2.0", standardComparator)) // Test best appcast item & a delta update item let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index a4376798..2142332e 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -20,6 +20,7 @@ #import "SPUSkippedUpdate.h" #import "SUSignatures.h" #import "SPUInstallationType.h" +#import "SPUAppcastItemSelection.h" NS_ASSUME_NONNULL_BEGIN From b7f9b76dd9bff32d6cadc40086107199063a29d1 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 00:00:38 -0700 Subject: [PATCH 02/29] Rename SPUUserUpdateState -> SPUUpdateState --- Sparkle.xcodeproj/project.pbxproj | 28 ++++++------- Sparkle/SPUCoreBasedUpdateDriver.h | 2 +- Sparkle/SPUStandardUserDriver.m | 2 +- Sparkle/SPUUIBasedUpdateDriver.m | 40 +++++++++---------- Sparkle/SPUUpdateState+Private.h | 22 ++++++++++ ...{SPUUserUpdateState.h => SPUUpdateState.h} | 22 +++++----- ...{SPUUserUpdateState.m => SPUUpdateState.m} | 10 ++--- Sparkle/SPUUserDriver.h | 17 ++++---- Sparkle/SPUUserUpdateState+Private.h | 22 ---------- Sparkle/SUUpdateAlert.h | 6 +-- Sparkle/SUUpdateAlert.m | 19 ++++----- TestApplication/SUPopUpTitlebarUserDriver.m | 10 ++--- 12 files changed, 100 insertions(+), 100 deletions(-) create mode 100644 Sparkle/SPUUpdateState+Private.h rename Sparkle/{SPUUserUpdateState.h => SPUUpdateState.h} (63%) rename Sparkle/{SPUUserUpdateState.m => SPUUpdateState.m} (83%) delete mode 100644 Sparkle/SPUUserUpdateState+Private.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 45009beb..7ff6de0d 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -289,9 +289,9 @@ 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; 7269E497264798200088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; 7269E4982648D3460088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; - 7269E49A2648F7C00088C213 /* SPUUserUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */; }; - 7269E49B2648F7C00088C213 /* SPUUserUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */; }; - 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUserUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7269E49A2648F7C00088C213 /* SPUUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUpdateState.m */; }; + 7269E49B2648F7C00088C213 /* SPUUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUpdateState.m */; }; + 726DF88E1C84277600188804 /* SPUUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E075C1CA3A6D6001A286B /* SPUSecureCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */; }; 726E075D1CA3A6D6001A286B /* SPUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */; }; 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E078B1CA891E9001A286B /* SPUUpdaterSettings.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -391,7 +391,7 @@ 72A5D5F41D692CF50009E5AC /* SparkleCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72A5D59C1D6927730009E5AC /* SparkleCore.framework */; }; 72A5D5F51D692CFE0009E5AC /* SparkleCore.framework in Copy Sparkle */ = {isa = PBXBuildFile; fileRef = 72A5D59C1D6927730009E5AC /* SparkleCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 72A5D5F81D692F2B0009E5AC /* SUExport.h in Headers */ = {isa = PBXBuildFile; fileRef = 14652F8319A9759F00959E44 /* SUExport.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 72A5D5F91D692F4C0009E5AC /* SPUUserUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUserUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 72A5D5F91D692F4C0009E5AC /* SPUUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5FB1D69312F0009E5AC /* SUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SUBundleIcon.m */; }; 72A6F98A1C94E2D6005F404C /* SUUpdaterDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A6F9891C94E2D6005F404C /* SUUpdaterDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72AC6B261B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */; }; @@ -1257,10 +1257,10 @@ 7267E5FB1D3DD1B700D1BF90 /* SPUResumableUpdate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUResumableUpdate.h; sourceTree = ""; }; 7269E492264798200088C213 /* SPUSkippedUpdate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUSkippedUpdate.h; sourceTree = ""; }; 7269E493264798200088C213 /* SPUSkippedUpdate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUSkippedUpdate.m; sourceTree = ""; }; - 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUUserUpdateState.m; sourceTree = ""; }; - 7269E49C2648FC6C0088C213 /* SPUUserUpdateState+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUUserUpdateState+Private.h"; sourceTree = ""; }; + 7269E4992648F7C00088C213 /* SPUUpdateState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUUpdateState.m; sourceTree = ""; }; + 7269E49C2648FC6C0088C213 /* SPUUpdateState+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUUpdateState+Private.h"; sourceTree = ""; }; 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 726DF88D1C84277500188804 /* SPUUserUpdateState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUserUpdateState.h; sourceTree = ""; }; + 726DF88D1C84277500188804 /* SPUUpdateState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdateState.h; sourceTree = ""; }; 726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUSecureCoding.h; path = Sparkle/SPUSecureCoding.h; sourceTree = SOURCE_ROOT; }; 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUSecureCoding.m; path = Sparkle/SPUSecureCoding.m; sourceTree = SOURCE_ROOT; }; 726E07681CA616A4001A286B /* libxar.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxar.tbd; path = usr/lib/libxar.tbd; sourceTree = SDKROOT; }; @@ -2052,6 +2052,9 @@ 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */, 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */, 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */, + 726DF88D1C84277500188804 /* SPUUpdateState.h */, + 7269E49C2648FC6C0088C213 /* SPUUpdateState+Private.h */, + 7269E4992648F7C00088C213 /* SPUUpdateState.m */, ); name = "Update Control"; sourceTree = ""; @@ -2156,9 +2159,6 @@ 725CB9581C7121830064365A /* SPUStandardUserDriver.h */, 725CB9591C7121830064365A /* SPUStandardUserDriver.m */, 726E4A361C89116000C57C6A /* SPUStandardUserDriverDelegate.h */, - 726DF88D1C84277500188804 /* SPUUserUpdateState.h */, - 7269E49C2648FC6C0088C213 /* SPUUserUpdateState+Private.h */, - 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */, 725CB9561C7120410064365A /* SPUUserDriver.h */, ); name = "User Driver"; @@ -2413,7 +2413,7 @@ 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */, 721D588E25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */, - 72A5D5F91D692F4C0009E5AC /* SPUUserUpdateState.h in Headers */, + 72A5D5F91D692F4C0009E5AC /* SPUUpdateState.h in Headers */, 72A5D5E71D692BB00009E5AC /* SPUUpdatePermissionRequest.h in Headers */, EA1E286F22B6661D004AA304 /* SUSignatures.h in Headers */, 72A5D5E21D692B770009E5AC /* SPUUpdater.h in Headers */, @@ -2454,7 +2454,7 @@ 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */, 725CB95A1C7121830064365A /* SPUStandardUserDriver.h in Headers */, 726E4A371C89116000C57C6A /* SPUStandardUserDriverDelegate.h in Headers */, - 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */, + 726DF88E1C84277600188804 /* SPUUpdateState.h in Headers */, 72B767DA1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.h in Headers */, 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */, 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */, @@ -3579,7 +3579,7 @@ 72A5D5B01D6929F80009E5AC /* SUInstallerConnection.m in Sources */, 72A5D5AE1D6929F80009E5AC /* SUInstallerLauncher.m in Sources */, 72B3DED01E23479000457642 /* SPUInformationalUpdate.m in Sources */, - 7269E49B2648F7C00088C213 /* SPUUserUpdateState.m in Sources */, + 7269E49B2648F7C00088C213 /* SPUUpdateState.m in Sources */, 72A5D5B21D6929F80009E5AC /* SUInstallerStatus.m in Sources */, 72A5D5C51D6929F80009E5AC /* SULog.m in Sources */, 72A5D5C61D6929F80009E5AC /* SUOperatingSystem.m in Sources */, @@ -3683,7 +3683,7 @@ 72B767CB1C9B707000A07552 /* SUAppcastDriver.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */, - 7269E49A2648F7C00088C213 /* SPUUserUpdateState.m in Sources */, + 7269E49A2648F7C00088C213 /* SPUUpdateState.m in Sources */, 725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */, 729E1D18266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */, 7214B8821D456A8500CB5CED /* SUBundleIcon.m in Sources */, diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 85805166..3eec77d8 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -7,7 +7,7 @@ // #import -#import "SPUUserUpdateState.h" +#import "SPUUpdateState.h" #import "SPUUpdateDriver.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 25a0e8c1..66a04762 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -115,7 +115,7 @@ #pragma mark Update Found -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { assert(NSThread.isMainThread); diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 6a181c7a..6bb22416 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -18,7 +18,7 @@ #import "SPUResumableUpdate.h" #import "SPUDownloadDriver.h" #import "SPUSkippedUpdate.h" -#import "SPUUserUpdateState+Private.h" +#import "SPUUpdateState+Private.h" #import "SPUAppcastItemSelection.h" @@ -170,28 +170,28 @@ id updaterDelegate = self.updaterDelegate; - SPUUserUpdateStage stage; + SPUUpdateStage stage; if (updateItem.isInformationOnlyUpdate) { - stage = SPUUserUpdateStageInformational; + stage = SPUUpdateStageInformational; } else if (self.resumingDownloadedUpdate) { - stage = SPUUserUpdateStageDownloaded; + stage = SPUUpdateStageDownloaded; } else if (self.resumingInstallingUpdate) { - stage = SPUUserUpdateStageInstalling; + stage = SPUUpdateStageInstalling; } else { - stage = SPUUserUpdateStageNotDownloaded; + stage = SPUUpdateStageNotDownloaded; } BOOL majorUpgrade = preventsAutoupdate; BOOL criticalUpdate = SPUAppcastItemIsCritical(updateItem, self.host.version, self.updater, self.updaterDelegate); - SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; + SPUUpdateState *state = [[SPUUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ // Rule out invalid choices SPUUserUpdateChoice validatedChoice; - if (stage == SPUUserUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { + if (stage == SPUUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { validatedChoice = SPUUserUpdateChoiceDismiss; } else { validatedChoice = userChoice; @@ -200,16 +200,16 @@ switch (validatedChoice) { case SPUUserUpdateChoiceInstall: { switch (stage) { - case SPUUserUpdateStageDownloaded: + case SPUUpdateStageDownloaded: [self.coreDriver extractDownloadedUpdate]; break; - case SPUUserUpdateStageInstalling: + case SPUUpdateStageInstalling: [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; - case SPUUserUpdateStageNotDownloaded: + case SPUUpdateStageNotDownloaded: [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:NO]; break; - case SPUUserUpdateStageInformational: + case SPUUpdateStageInformational: assert(false); break; } @@ -223,9 +223,9 @@ } switch (stage) { - case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageInformational: + case SPUUpdateStageDownloaded: + case SPUUpdateStageNotDownloaded: + case SPUUpdateStageInformational: // Informational updates can be resumed too, so make sure we check // self.resumingDownloadedUpdate instead of the stage we pass to user driver if (self.resumingDownloadedUpdate) { @@ -235,7 +235,7 @@ [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break; - case SPUUserUpdateStageInstalling: + case SPUUpdateStageInstalling: [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; } @@ -244,13 +244,13 @@ } case SPUUserUpdateChoiceDismiss: { switch (stage) { - case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageInformational: { + case SPUUpdateStageDownloaded: + case SPUUpdateStageNotDownloaded: + case SPUUpdateStageInformational: { [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break; } - case SPUUserUpdateStageInstalling: { + case SPUUpdateStageInstalling: { [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; } diff --git a/Sparkle/SPUUpdateState+Private.h b/Sparkle/SPUUpdateState+Private.h new file mode 100644 index 00000000..ed040132 --- /dev/null +++ b/Sparkle/SPUUpdateState+Private.h @@ -0,0 +1,22 @@ +// +// SPUUpdateState+Private.h +// Sparkle +// +// Created by Mayur Pawashe on 5/9/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#ifndef SPUUpdateState_Private_h +#define SPUUpdateState_Private_h + +NS_ASSUME_NONNULL_BEGIN + +@interface SPUUpdateState (Private) + +- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUUpdateState_Private_h */ diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUpdateState.h similarity index 63% rename from Sparkle/SPUUserUpdateState.h rename to Sparkle/SPUUpdateState.h index 1611f9d7..034b6495 100644 --- a/Sparkle/SPUUserUpdateState.h +++ b/Sparkle/SPUUpdateState.h @@ -1,13 +1,13 @@ // -// SPUUserUpdateState.h +// SPUUpdateState.h // Sparkle // // Created by Mayur Pawashe on 2/29/16. // Copyright © 2016 Sparkle Project. All rights reserved. // -#ifndef SPUUserUpdateState_h -#define SPUUserUpdateState_h +#ifndef SPUUpdateState_h +#define SPUUpdateState_h #if __has_feature(modules) #if __has_warning("-Watimport-in-framework-header") @@ -28,16 +28,16 @@ typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { SPUUserUpdateChoiceDismiss, }; -typedef NS_ENUM(NSInteger, SPUUserUpdateStage) { - SPUUserUpdateStageNotDownloaded, - SPUUserUpdateStageDownloaded, - SPUUserUpdateStageInstalling, - SPUUserUpdateStageInformational +typedef NS_ENUM(NSInteger, SPUUpdateStage) { + SPUUpdateStageNotDownloaded, + SPUUpdateStageDownloaded, + SPUUpdateStageInstalling, + SPUUpdateStageInformational }; -SU_EXPORT @interface SPUUserUpdateState : NSObject +SU_EXPORT @interface SPUUpdateState : NSObject -@property (nonatomic, readonly) SPUUserUpdateStage stage; +@property (nonatomic, readonly) SPUUpdateStage stage; @property (nonatomic, readonly) BOOL userInitiated; @property (nonatomic, readonly) BOOL majorUpgrade; @property (nonatomic, readonly) BOOL criticalUpdate; @@ -46,4 +46,4 @@ SU_EXPORT @interface SPUUserUpdateState : NSObject NS_ASSUME_NONNULL_END -#endif /* SPUUserUpdateState_h */ +#endif /* SPUUpdateState_h */ diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUpdateState.m similarity index 83% rename from Sparkle/SPUUserUpdateState.m rename to Sparkle/SPUUpdateState.m index 576f4db2..a86a8d4e 100644 --- a/Sparkle/SPUUserUpdateState.m +++ b/Sparkle/SPUUpdateState.m @@ -6,8 +6,8 @@ // Copyright © 2021 Sparkle Project. All rights reserved. // -#import "SPUUserUpdateState.h" -#import "SPUUserUpdateState+Private.h" +#import "SPUUpdateState.h" +#import "SPUUpdateState+Private.h" #include "AppKitPrevention.h" @@ -17,14 +17,14 @@ #define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" #define SPUUserUpdateStateCriticalUpdateKey @"SPUUserUpdateStateCriticalUpdate" -@implementation SPUUserUpdateState +@implementation SPUUpdateState @synthesize stage = _stage; @synthesize userInitiated = _userInitiated; @synthesize majorUpgrade = _majorUpgrade; @synthesize criticalUpdate = _criticalUpdate; -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate +- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate { self = [super init]; if (self != nil) { @@ -46,7 +46,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder { - SPUUserUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; + SPUUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; BOOL userInitiated = [decoder decodeBoolForKey:SPUUserUpdateStateUserInitiatedKey]; BOOL majorUpgrade = [decoder decodeBoolForKey:SPUUserUpdateStateMajorUpgradeKey]; BOOL criticalUpdate = [decoder decodeBoolForKey:SPUUserUpdateStateCriticalUpdateKey]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 684cf12d..f606a958 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -15,7 +15,7 @@ #import #endif -#import "SPUUserUpdateState.h" +#import "SPUUpdateState.h" #import "SUExport.h" NS_ASSUME_NONNULL_BEGIN @@ -62,15 +62,14 @@ SU_EXPORT @protocol SPUUserDriver * * @param state The current state of the update. * The state.stage values are: - * SPUUserUpdateStateNotDownloaded - Update has not been downloaded yet. - * SPUUserUpdateStateDownloaded - Update has already been downloaded but not started installing yet. - * SPUUserUpdateStateInstalling - Update has been downloaded and already started installing. - * SPUUserUpdateStateInformational - Update is only informational and has no download. You can direct the user to the infoURL property of the appcastItem in their web browser. Use this to check if an update is informational, instead of using the informationOnlyUpdate property of the appcast item. + * SPUUpdateStateNotDownloaded - Update has not been downloaded yet. + * SPUUpdateStateDownloaded - Update has already been downloaded but not started installing yet. + * SPUUpdateStateInstalling - Update has been downloaded and already started installing. + * SPUUpdateStateInformational - Update is only informational and has no download. You can direct the user to the infoURL property of the appcastItem in their web browser. Use this to check if an update is informational, instead of using the informationOnlyUpdate property of the appcast item. * * state.userInitiated indicates if the update was initiated by the user or if it was automatically scheduled in the background. * state.majorUpgrade indicates if the update is a major or paid upgrade. - * - * Additionally, you may want to check the criticalUpdate property of the appcastItem to let the user know if the update is critical. + * state.criticalUpdate indicates if the update is a critical update. * * @param reply * A reply of SPUUserUpdateChoiceInstall begins or resumes downloading or installing the update. @@ -82,9 +81,9 @@ SU_EXPORT @protocol SPUUserDriver * * A reply of SPUUserUpdateChoiceSkip skips this particular version and won't notify the user again, unless they initiate an update check themselves. * If state.majorUpgrade is YES, the major update and any minor updates to that major release are skipped. - * If the state.stage is SPUUserUpdateStateInstalling, the installation is also canceled when the update is skipped. + * If the state.stage is SPUUpdateStateInstalling, the installation is also canceled when the update is skipped. */ -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; /*! * Show the user the release notes for the new update diff --git a/Sparkle/SPUUserUpdateState+Private.h b/Sparkle/SPUUserUpdateState+Private.h deleted file mode 100644 index cd58b47a..00000000 --- a/Sparkle/SPUUserUpdateState+Private.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// SPUUserUpdateState+Private.h -// Sparkle -// -// Created by Mayur Pawashe on 5/9/21. -// Copyright © 2021 Sparkle Project. All rights reserved. -// - -#ifndef SPUUserUpdateState_Private_h -#define SPUUserUpdateState_Private_h - -NS_ASSUME_NONNULL_BEGIN - -@interface SPUUserUpdateState (Private) - -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate; - -@end - -NS_ASSUME_NONNULL_END - -#endif /* SPUUserUpdateState_Private_h */ diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 41ee55bd..6e610f4d 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -11,16 +11,16 @@ #import #import "SUVersionDisplayProtocol.h" -#import "SPUUserUpdateState.h" +#import "SPUUpdateState.h" @protocol SUUpdateAlertDelegate; -@class SUAppcastItem, SPUDownloadData, SUHost; +@class SUAppcastItem, SPUDownloadData, SUHost, SPUUpdateState; @interface SUUpdateAlert : NSWindowController @property (nonatomic, weak, readonly) id versionDisplayer; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block; - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; - (void)showReleaseNotesFailedToDownload; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 1d293e87..bd105384 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -27,6 +27,7 @@ #import "SUTouchBarForwardDeclarations.h" #import "SUTouchBarButtonGroup.h" #import "SPUXPCServiceInfo.h" +#import "SPUUpdateState.h" static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdateAlert"; @@ -36,7 +37,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @property (strong) SUHost *host; @property (nonatomic) BOOL allowsAutomaticUpdates; @property (nonatomic, copy, nullable) void(^completionBlock)(SPUUserUpdateChoice); -@property (nonatomic) SPUUserUpdateState *state; +@property (nonatomic) SPUUpdateState *state; @property (strong) NSProgressIndicator *releaseNotesSpinner; @@ -80,7 +81,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @synthesize webView = _webView; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; if (self != nil) { @@ -92,7 +93,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE _completionBlock = [block copy]; SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; - _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && state.stage != SPUUserUpdateStageInformational; + _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && state.stage != SPUUpdateStageInformational; [self setShouldCascadeWindows:NO]; } return self; @@ -338,7 +339,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE [self.window setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! } - if (self.state.stage == SPUUserUpdateStageInformational) { + if (self.state.stage == SPUUpdateStageInformational) { [self.installButton setTitle:SULocalizedString(@"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed.")]; [self.installButton setAction:@selector(openInfoURL:)]; } @@ -372,7 +373,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } } - if (self.state.stage == SPUUserUpdateStageInstalling) { + if (self.state.stage == SPUUpdateStageInstalling) { // We're going to be relaunching pretty instantaneously self.installButton.title = SULocalizedString(@"Install and Relaunch", nil); @@ -410,7 +411,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE { return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [self.host name]]; } - else if (self.state.stage == SPUUserUpdateStageDownloaded || self.state.stage == SPUUserUpdateStageInstalling) + else if (self.state.stage == SPUUpdateStageDownloaded || self.state.stage == SPUUpdateStageInstalling) { return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [self.host name]]; } @@ -435,16 +436,16 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We display a different summary depending on if it's an "info-only" item, or a "critical update" item, or if we've already downloaded the update and just need to relaunch NSString *finalString = nil; - if (self.state.stage == SPUUserUpdateStageInformational) { + if (self.state.stage == SPUUpdateStageInformational) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; } else if (self.state.criticalUpdate) { - if (self.state.stage == SPUUserUpdateStageNotDownloaded) { + if (self.state.stage == SPUUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. This is an important update; would you like to download it now?", @"Description text for SUUpdateAlert when the critical update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { finalString = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! This is an important update; would you like to install it and relaunch %1$@ now?", @"Description text for SUUpdateAlert when the critical update has already been downloaded and ready to install."), self.host.name, updateItemVersion]; } } else { - if (self.state.stage == SPUUserUpdateStageNotDownloaded) { + if (self.state.stage == SPUUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", @"Description text for SUUpdateAlert when the update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { finalString = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", @"Description text for SUUpdateAlert when the update has already been downloaded and ready to install."), self.host.name, updateItemVersion]; diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index a72f923f..21a785c3 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -133,10 +133,10 @@ }]; } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { switch (state.stage) { - case SPUUserUpdateStageInformational: + case SPUUpdateStageInformational: // Todo: show user interface for this NSLog(@"Found info URL: %@", appcastItem.infoURL); @@ -146,9 +146,9 @@ reply(SPUUserUpdateChoiceDismiss); break; - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageInstalling: + case SPUUpdateStageNotDownloaded: + case SPUUpdateStageDownloaded: + case SPUUpdateStageInstalling: [self showUpdateWithAppcastItem:appcastItem reply:reply]; break; } From 90bdd84832efca218a4e8b67dc43a04fa3669fb2 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 00:13:07 -0700 Subject: [PATCH 03/29] Move SPUUserUpdateChoice into its own header --- Sparkle.xcodeproj/project.pbxproj | 6 ++++++ Sparkle/SPUCoreBasedUpdateDriver.h | 1 + Sparkle/SPUStandardUserDriver.m | 1 + Sparkle/SPUUpdateState.h | 6 ------ Sparkle/SPUUserDriver.h | 4 ++-- Sparkle/SPUUserUpdateChoice.h | 18 ++++++++++++++++++ Sparkle/SUUpdateAlert.h | 2 +- Sparkle/Sparkle.h | 1 + Sparkle/SparkleCore.h | 1 + sparkle-cli/SPUCommandLineUserDriver.m | 10 +++++----- 10 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 Sparkle/SPUUserUpdateChoice.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 7ff6de0d..67c98f1c 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -327,6 +327,8 @@ 729E1D17266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */; }; 729E1D18266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */; }; 729E1D19266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */; }; + 729E1D1B2664C2C500BF3EFB /* SPUUserUpdateChoice.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 729E1D1C2664C34000BF3EFB /* SPUUserUpdateChoice.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A1C2631CD6849C004CD282 /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; }; 72A450531C69A68900D67EEA /* SUUpdatePermissionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A450541C69A68900D67EEA /* SUUpdatePermissionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */; }; @@ -1300,6 +1302,7 @@ 729BB3D11D503826007C4276 /* org.sparkle-project.Downloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "org.sparkle-project.Downloader.entitlements"; path = "Downloader/org.sparkle-project.Downloader.entitlements"; sourceTree = SOURCE_ROOT; }; 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemSelection.h; sourceTree = ""; }; 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemSelection.m; sourceTree = ""; }; + 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUUserUpdateChoice.h; sourceTree = ""; }; 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = ""; }; 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdatePermissionResponse.h; sourceTree = ""; }; @@ -2160,6 +2163,7 @@ 725CB9591C7121830064365A /* SPUStandardUserDriver.m */, 726E4A361C89116000C57C6A /* SPUStandardUserDriverDelegate.h */, 725CB9561C7120410064365A /* SPUUserDriver.h */, + 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */, ); name = "User Driver"; sourceTree = ""; @@ -2408,6 +2412,7 @@ buildActionMask = 2147483647; files = ( 729E1D17266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */, + 729E1D1C2664C34000BF3EFB /* SPUUserUpdateChoice.h in Headers */, 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */, 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */, 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, @@ -2439,6 +2444,7 @@ 72B767D61C9C8B5C00A07552 /* SPUBasicUpdateDriver.h in Headers */, 72B767E21C9CE90A00A07552 /* SPUCoreBasedUpdateDriver.h in Headers */, 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */, + 729E1D1B2664C2C500BF3EFB /* SPUUserUpdateChoice.h in Headers */, 7229E1BD1C98EFF200CB50D0 /* SPUDownloadDriver.h in Headers */, 7267E5FD1D3DD1B700D1BF90 /* SPUResumableUpdate.h in Headers */, 7267E5B61D3D8AEE00D1BF90 /* SPUInstallationInfo.h in Headers */, diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 3eec77d8..b52e4c95 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -9,6 +9,7 @@ #import #import "SPUUpdateState.h" #import "SPUUpdateDriver.h" +#import "SPUUserUpdateChoice.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 66a04762..d0faf60d 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -17,6 +17,7 @@ #import "SULocalizations.h" #import "SUApplicationInfo.h" #import "SUOperatingSystem.h" +#import "SPUUpdateState.h" @interface SPUStandardUserDriver () diff --git a/Sparkle/SPUUpdateState.h b/Sparkle/SPUUpdateState.h index 034b6495..fd16f377 100644 --- a/Sparkle/SPUUpdateState.h +++ b/Sparkle/SPUUpdateState.h @@ -22,12 +22,6 @@ NS_ASSUME_NONNULL_BEGIN -typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { - SPUUserUpdateChoiceSkip, - SPUUserUpdateChoiceInstall, - SPUUserUpdateChoiceDismiss, -}; - typedef NS_ENUM(NSInteger, SPUUpdateStage) { SPUUpdateStageNotDownloaded, SPUUpdateStageDownloaded, diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index f606a958..38b7f051 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -15,12 +15,12 @@ #import #endif -#import "SPUUpdateState.h" +#import "SPUUserUpdateChoice.h" #import "SUExport.h" NS_ASSUME_NONNULL_BEGIN -@class SPUUpdatePermissionRequest, SUUpdatePermissionResponse, SUAppcastItem, SPUDownloadData; +@class SPUUpdatePermissionRequest, SUUpdatePermissionResponse, SUAppcastItem, SPUDownloadData, SPUUpdateState; /*! The API in Sparkle for controlling the user interaction. diff --git a/Sparkle/SPUUserUpdateChoice.h b/Sparkle/SPUUserUpdateChoice.h new file mode 100644 index 00000000..194ff871 --- /dev/null +++ b/Sparkle/SPUUserUpdateChoice.h @@ -0,0 +1,18 @@ +// +// SPUUserUpdateChoice.h +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#ifndef SPUUserUpdateChoice_h +#define SPUUserUpdateChoice_h + +typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { + SPUUserUpdateChoiceSkip, + SPUUserUpdateChoiceInstall, + SPUUserUpdateChoiceDismiss, +}; + +#endif /* SPUUserUpdateChoice_h */ diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 6e610f4d..db2a5a3b 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -11,7 +11,7 @@ #import #import "SUVersionDisplayProtocol.h" -#import "SPUUpdateState.h" +#import "SPUUserUpdateChoice.h" @protocol SUUpdateAlertDelegate; diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index 8ec3e01e..bd72a9f5 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -30,6 +30,7 @@ #import "SPUUpdatePermissionRequest.h" #import "SUUpdatePermissionResponse.h" #import "SPUUserDriver.h" +#import "SPUUpdateState.h" #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" #import "SPUDownloadData.h" diff --git a/Sparkle/SparkleCore.h b/Sparkle/SparkleCore.h index 118672aa..d151ca6f 100644 --- a/Sparkle/SparkleCore.h +++ b/Sparkle/SparkleCore.h @@ -29,6 +29,7 @@ #import "SPUUpdatePermissionRequest.h" #import "SUUpdatePermissionResponse.h" #import "SPUUserDriver.h" +#import "SPUUpdateState.h" #import "SPUDownloadData.h" #pragma clang diagnostic pop diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index cceb6c06..dd04d442 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -97,18 +97,18 @@ } } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { switch (state.stage) { - case SPUUserUpdateStageNotDownloaded: + case SPUUpdateStageNotDownloaded: [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; reply(SPUUserUpdateChoiceInstall); break; - case SPUUserUpdateStageDownloaded: + case SPUUpdateStageDownloaded: [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; reply(SPUUserUpdateChoiceInstall); break; - case SPUUserUpdateStageInstalling: + case SPUUpdateStageInstalling: if (self.deferInstallation) { if (self.verbose) { fprintf(stderr, "Deferring Installation.\n"); @@ -118,7 +118,7 @@ reply(SPUUserUpdateChoiceInstall); } break; - case SPUUserUpdateStageInformational: + case SPUUpdateStageInformational: fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); reply(SPUUserUpdateChoiceDismiss); break; From 1cc11d76a2de14948af53268480d8fb749780832 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 00:14:55 -0700 Subject: [PATCH 04/29] Fix SPUUpdateState reference --- Sparkle/SUAppcastItem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 7c8b9f00..2700407d 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -43,7 +43,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly, nullable) NSString *minimumAutoupdateVersion; @property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; -@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate __deprecated_msg("Use SPUUserUpdateState.criticalUpdate instead"); +@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate __deprecated_msg("Use -SPUUpdateState.criticalUpdate instead"); @property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; From 60bbb373e2b01fffa340707defcf11e9c3a43dd1 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 00:17:08 -0700 Subject: [PATCH 05/29] Add comments on legacy critical update path --- Sparkle/SUAppcastItem.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 0d5c44da..e82ea99c 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -198,6 +198,8 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT return criticalUpdateDictionary; } + // Check legacy / deprecated path where critical update used to be a tag + // This path does not support specifying which version became critical NSArray *tags = [self.propertiesDictionary objectForKey:SUAppcastElementTags]; if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { return @{}; From 0e264dae2f07220bc8eac1f4acf6c7723cb72824 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 00:20:11 -0700 Subject: [PATCH 06/29] Add comments on critical testing functions --- Sparkle/SPUAppcastItemSelection.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sparkle/SPUAppcastItemSelection.m b/Sparkle/SPUAppcastItemSelection.m index 89ff0956..9117206c 100644 --- a/Sparkle/SPUAppcastItemSelection.m +++ b/Sparkle/SPUAppcastItemSelection.m @@ -19,6 +19,8 @@ #include "AppKitPrevention.h" +// Returns the critical update version string if available, otherwise returns +// a result (in isCriticalWithoutVersion) if the update is critical (without a version specified) static NSString * _Nullable SPUAppcastItemCriticalUpdateVersion(SUAppcastItem *appcastItem, BOOL *isCriticalWithoutVersion) { NSDictionary *criticalUpdateDictionary = appcastItem.criticalUpdateDictionary; @@ -36,6 +38,7 @@ static NSString * _Nullable SPUAppcastItemCriticalUpdateVersion(SUAppcastItem *a return criticalVersion; } +// Given a host version, is this update version considered critical? static BOOL SPUCriticalUpdateTest(id versionComparator, NSString *hostVersion, NSString *criticalVersion) { return ([versionComparator compareVersion:hostVersion toVersion:criticalVersion] == NSOrderedAscending); From fabf4159991c47bb3d7e9b4de0b9018901311187 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 09:27:21 -0700 Subject: [PATCH 07/29] Resolve appcast item properties from external environment at init --- Sparkle.xcodeproj/project.pbxproj | 40 +++++--- Sparkle/SPUAppcastItemSelection.h | 30 ------ Sparkle/SPUAppcastItemSelection.m | 85 ----------------- Sparkle/SPUAppcastItemState.h | 27 ++++++ Sparkle/SPUAppcastItemState.m | 64 +++++++++++++ Sparkle/SPUAppcastItemStateResolver.h | 27 ++++++ Sparkle/SPUAppcastItemStateResolver.m | 102 +++++++++++++++++++++ Sparkle/SPUAutomaticUpdateDriver.m | 3 +- Sparkle/SPUUIBasedUpdateDriver.m | 3 +- Sparkle/SPUUpdater.m | 3 +- Sparkle/SUAppcast+Private.h | 8 +- Sparkle/SUAppcast.m | 10 +- Sparkle/SUAppcastDriver.m | 45 ++++----- Sparkle/SUAppcastItem+Private.h | 8 +- Sparkle/SUAppcastItem.h | 6 +- Sparkle/SUAppcastItem.m | 69 +++++++++----- Tests/Sparkle Unit Tests-Bridging-Header.h | 3 +- 17 files changed, 342 insertions(+), 191 deletions(-) delete mode 100644 Sparkle/SPUAppcastItemSelection.h delete mode 100644 Sparkle/SPUAppcastItemSelection.m create mode 100644 Sparkle/SPUAppcastItemState.h create mode 100644 Sparkle/SPUAppcastItemState.m create mode 100644 Sparkle/SPUAppcastItemStateResolver.h create mode 100644 Sparkle/SPUAppcastItemStateResolver.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 67c98f1c..085caf98 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -323,12 +323,18 @@ 7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 7293A1B11CEE9B9F00B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 729924941DF4A45000DBCDF5 /* SUUpdateValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */; }; - 729E1D16266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */; }; - 729E1D17266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */; }; - 729E1D18266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */; }; - 729E1D19266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */; }; 729E1D1B2664C2C500BF3EFB /* SPUUserUpdateChoice.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */; settings = {ATTRIBUTES = (Public, ); }; }; 729E1D1C2664C34000BF3EFB /* SPUUserUpdateChoice.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 729E1D1F26651CF500BF3EFB /* SPUAppcastItemState.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */; }; + 729E1D2026651CF500BF3EFB /* SPUAppcastItemState.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */; }; + 729E1D2126651CF500BF3EFB /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */; }; + 729E1D2226651CF500BF3EFB /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */; }; + 729E1D232665231700BF3EFB /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */; }; + 729E1D242665234700BF3EFB /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */; }; + 729E1D2726652DCF00BF3EFB /* SPUAppcastItemStateResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D2526652DCF00BF3EFB /* SPUAppcastItemStateResolver.h */; }; + 729E1D2826652DCF00BF3EFB /* SPUAppcastItemStateResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D2526652DCF00BF3EFB /* SPUAppcastItemStateResolver.h */; }; + 729E1D2926652DCF00BF3EFB /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D2626652DCF00BF3EFB /* SPUAppcastItemStateResolver.m */; }; + 729E1D2A26652DCF00BF3EFB /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D2626652DCF00BF3EFB /* SPUAppcastItemStateResolver.m */; }; 72A1C2631CD6849C004CD282 /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; }; 72A450531C69A68900D67EEA /* SUUpdatePermissionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A450541C69A68900D67EEA /* SUUpdatePermissionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */; }; @@ -1300,9 +1306,11 @@ 729924921DF4A45000DBCDF5 /* SUUpdateValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUUpdateValidator.h; path = Sparkle/SUUpdateValidator.h; sourceTree = SOURCE_ROOT; }; 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUUpdateValidator.m; path = Sparkle/SUUpdateValidator.m; sourceTree = SOURCE_ROOT; }; 729BB3D11D503826007C4276 /* org.sparkle-project.Downloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "org.sparkle-project.Downloader.entitlements"; path = "Downloader/org.sparkle-project.Downloader.entitlements"; sourceTree = SOURCE_ROOT; }; - 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemSelection.h; sourceTree = ""; }; - 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemSelection.m; sourceTree = ""; }; 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUUserUpdateChoice.h; sourceTree = ""; }; + 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemState.h; sourceTree = ""; }; + 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemState.m; sourceTree = ""; }; + 729E1D2526652DCF00BF3EFB /* SPUAppcastItemStateResolver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemStateResolver.h; sourceTree = ""; }; + 729E1D2626652DCF00BF3EFB /* SPUAppcastItemStateResolver.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemStateResolver.m; sourceTree = ""; }; 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = ""; }; 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdatePermissionResponse.h; sourceTree = ""; }; @@ -1886,8 +1894,10 @@ 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */, 725DED73263D123900E7FA8F /* SUAppcastItem+Private.h */, 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */, - 729E1D14266490FE00BF3EFB /* SPUAppcastItemSelection.h */, - 729E1D15266490FE00BF3EFB /* SPUAppcastItemSelection.m */, + 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */, + 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */, + 729E1D2526652DCF00BF3EFB /* SPUAppcastItemStateResolver.h */, + 729E1D2626652DCF00BF3EFB /* SPUAppcastItemStateResolver.m */, 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */, 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */, 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */, @@ -2411,7 +2421,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 729E1D17266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */, + 729E1D2826652DCF00BF3EFB /* SPUAppcastItemStateResolver.h in Headers */, 729E1D1C2664C34000BF3EFB /* SPUUserUpdateChoice.h in Headers */, 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */, 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */, @@ -2426,6 +2436,7 @@ 72A5D5E31D692B770009E5AC /* SPUUpdaterSettings.h in Headers */, 72A5D5E91D692BC80009E5AC /* SPUUserDriver.h in Headers */, 72A5D5DF1D692B570009E5AC /* SUAppcast.h in Headers */, + 729E1D2026651CF500BF3EFB /* SPUAppcastItemState.h in Headers */, 72A5D5E01D692B570009E5AC /* SUAppcastItem.h in Headers */, 72A5D5E61D692BA20009E5AC /* SUErrors.h in Headers */, 72A5D5F81D692F2B0009E5AC /* SUExport.h in Headers */, @@ -2455,6 +2466,7 @@ 728337A61C9E6FF40085AA99 /* SPUProbeInstallStatus.h in Headers */, 723C8A541E2D60DB00C14942 /* SUTouchBarButtonGroup.h in Headers */, 72B767D21C9C7B9300A07552 /* SPUProbingUpdateDriver.h in Headers */, + 729E1D2726652DCF00BF3EFB /* SPUAppcastItemStateResolver.h in Headers */, 7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */, 726E075C1CA3A6D6001A286B /* SPUSecureCoding.h in Headers */, 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */, @@ -2468,7 +2480,6 @@ 720E217B1D0D00BF003A311C /* SPUUpdaterCycle.h in Headers */, 72F9EC481D5EA904004AC8B6 /* SPUUpdaterDelegate.h in Headers */, 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */, - 729E1D16266490FE00BF3EFB /* SPUAppcastItemSelection.h in Headers */, 72F9EC3F1D5E823F004AC8B6 /* SPUUpdaterTimer.h in Headers */, 7269E494264798200088C213 /* SPUSkippedUpdate.h in Headers */, 723ABFC4259D4CB300BDB4FA /* SUWKWebView.h in Headers */, @@ -2478,6 +2489,7 @@ 72F94F581CC44DE1002DEE68 /* SPUXPCServiceInfo.h in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, 72B767CA1C9B707000A07552 /* SUAppcastDriver.h in Headers */, + 729E1D1F26651CF500BF3EFB /* SPUAppcastItemState.h in Headers */, 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, 725602D51C83551C00DAA70E /* SUApplicationInfo.h in Headers */, 7214B8811D456A8500CB5CED /* SUBundleIcon.h in Headers */, @@ -3447,6 +3459,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 729E1D242665234700BF3EFB /* SPUAppcastItemState.m in Sources */, 720AC2DC2618E8A500E25A3E /* SPUSecureCoding.m in Sources */, 720AC2C92618E89500E25A3E /* SUAppcastItem.m in Sources */, 720AC2A42618E85700E25A3E /* SPUInstallationInfo.m in Sources */, @@ -3575,6 +3588,7 @@ 72A5D5AD1D6929F80009E5AC /* SPUXPCServiceInfo.m in Sources */, 72A5D5B91D6929F80009E5AC /* SUAppcast.m in Sources */, 72A5D5D11D6929F80009E5AC /* SUAppcastDriver.m in Sources */, + 729E1D2A26652DCF00BF3EFB /* SPUAppcastItemStateResolver.m in Sources */, 72A5D5BA1D6929F80009E5AC /* SUAppcastItem.m in Sources */, 72A5D5FB1D69312F0009E5AC /* SUBundleIcon.m in Sources */, 72A5D5DC1D692A4E0009E5AC /* SUCodeSigningVerifier.m in Sources */, @@ -3590,8 +3604,8 @@ 72A5D5C51D6929F80009E5AC /* SULog.m in Sources */, 72A5D5C61D6929F80009E5AC /* SUOperatingSystem.m in Sources */, 72A5D5BE1D6929F80009E5AC /* SUStandardVersionComparator.m in Sources */, - 729E1D19266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */, 72A5D5BF1D6929F80009E5AC /* SUSystemProfiler.m in Sources */, + 729E1D2226651CF500BF3EFB /* SPUAppcastItemState.m in Sources */, 72A5D5D71D6929F80009E5AC /* SUUpdatePermissionResponse.m in Sources */, 72A5D5B11D6929F80009E5AC /* SUXPCInstallerConnection.m in Sources */, 72A5D5B31D6929F80009E5AC /* SUXPCInstallerStatus.m in Sources */, @@ -3602,6 +3616,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 729E1D232665231700BF3EFB /* SPUAppcastItemState.m in Sources */, 72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */, 7267E5A81D3D8A9900D1BF90 /* AgentConnection.m in Sources */, 7267E5A21D3D8A7E00D1BF90 /* AppInstaller.m in Sources */, @@ -3663,6 +3678,7 @@ 7229E1BE1C98EFF200CB50D0 /* SPUDownloadDriver.m in Sources */, 723B5DAA1CF7AB6A00365F95 /* SPUDownloader.m in Sources */, 7267E5B71D3D8AEE00D1BF90 /* SPUInstallationInfo.m in Sources */, + 729E1D2926652DCF00BF3EFB /* SPUAppcastItemStateResolver.m in Sources */, 7267E5DF1D3D8FFA00D1BF90 /* SPUInstallationInputData.m in Sources */, 72B767CF1C9B924900A07552 /* SPUInstallerDriver.m in Sources */, 721BC20F1D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */, @@ -3691,7 +3707,6 @@ 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */, 7269E49A2648F7C00088C213 /* SPUUpdateState.m in Sources */, 725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */, - 729E1D18266490FE00BF3EFB /* SPUAppcastItemSelection.m in Sources */, 7214B8821D456A8500CB5CED /* SUBundleIcon.m in Sources */, 72DBA37F1D62C23E002594A8 /* SUCodeSigningVerifier.m in Sources */, 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */, @@ -3700,6 +3715,7 @@ 724BB3891D32B915005D534A /* SUInstallerConnection.m in Sources */, 72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */, 724BB3AA1D3347C2005D534A /* SUInstallerStatus.m in Sources */, + 729E1D2126651CF500BF3EFB /* SPUAppcastItemState.m in Sources */, 55C14F07136EF6DB00649790 /* SULog.m in Sources */, 726F2CE61BC9C33D001971A4 /* SUOperatingSystem.m in Sources */, 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, diff --git a/Sparkle/SPUAppcastItemSelection.h b/Sparkle/SPUAppcastItemSelection.h deleted file mode 100644 index bc2ec307..00000000 --- a/Sparkle/SPUAppcastItemSelection.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// SPUAppcastItemSelection.h -// Sparkle -// -// Created by Mayur Pawashe on 5/30/21. -// Copyright © 2021 Sparkle Project. All rights reserved. -// - -#import - -@class SUAppcastItem; -@class SUHost; -@class SPUUpdater; - -@protocol SPUUpdaterDelegate; -@protocol SUVersionComparison; - -NS_ASSUME_NONNULL_BEGIN - -// Functions for querying if appcast item properties that depend on current host version - -BOOL SPUAppcastItemIsCriticalWithComparator(SUAppcastItem *appcastItem, NSString *hostVersion, id versionComparator); - -BOOL SPUAppcastItemIsCritical(SUAppcastItem *appcastItem, NSString *hostVersion, SPUUpdater *updater, id _Nullable updaterDelegate); - -id SPUVersionComparator(SPUUpdater *updater, id _Nullable updaterDelegate); - -BOOL SPUAppcastItemContainsCriticalTag(SUAppcastItem *appcastItem); - -NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemSelection.m b/Sparkle/SPUAppcastItemSelection.m deleted file mode 100644 index 9117206c..00000000 --- a/Sparkle/SPUAppcastItemSelection.m +++ /dev/null @@ -1,85 +0,0 @@ -// -// SPUAppcastItemSelection.m -// Sparkle -// -// Created by Mayur Pawashe on 5/30/21. -// Copyright © 2021 Sparkle Project. All rights reserved. -// - -#import "SPUAppcastItemSelection.h" -#import "SUHost.h" -#import "SUAppcastItem.h" -#import "SUAppcastItem+Private.h" -#import "SPUUpdater.h" -#import "SPUUpdaterDelegate.h" -#import "SUStandardVersionComparator.h" -#import "SUVersionComparisonProtocol.h" -#import "SUConstants.h" - - -#include "AppKitPrevention.h" - -// Returns the critical update version string if available, otherwise returns -// a result (in isCriticalWithoutVersion) if the update is critical (without a version specified) -static NSString * _Nullable SPUAppcastItemCriticalUpdateVersion(SUAppcastItem *appcastItem, BOOL *isCriticalWithoutVersion) -{ - NSDictionary *criticalUpdateDictionary = appcastItem.criticalUpdateDictionary; - if (criticalUpdateDictionary == nil) { - *isCriticalWithoutVersion = NO; - return nil; - } - - NSString *criticalVersion = criticalUpdateDictionary[SUAppcastAttributeVersion]; - if (criticalVersion == nil || ![criticalVersion isKindOfClass:[NSString class]]) { - *isCriticalWithoutVersion = YES; - return nil; - } - - return criticalVersion; -} - -// Given a host version, is this update version considered critical? -static BOOL SPUCriticalUpdateTest(id versionComparator, NSString *hostVersion, NSString *criticalVersion) -{ - return ([versionComparator compareVersion:hostVersion toVersion:criticalVersion] == NSOrderedAscending); -} - -BOOL SPUAppcastItemIsCriticalWithComparator(SUAppcastItem *appcastItem, NSString *hostVersion, id versionComparator) -{ - BOOL isCriticalWithoutVersion = NO; - NSString *criticalVersion = SPUAppcastItemCriticalUpdateVersion(appcastItem, &isCriticalWithoutVersion); - if (criticalVersion == nil) { - return isCriticalWithoutVersion; - } - - return SPUCriticalUpdateTest(versionComparator, hostVersion, criticalVersion); -} - -BOOL SPUAppcastItemIsCritical(SUAppcastItem *appcastItem, NSString *hostVersion, SPUUpdater *updater, id _Nullable updaterDelegate) -{ - BOOL isCriticalWithoutVersion = NO; - NSString *criticalVersion = SPUAppcastItemCriticalUpdateVersion(appcastItem, &isCriticalWithoutVersion); - if (criticalVersion == nil) { - return isCriticalWithoutVersion; - } - - id versionComparator = SPUVersionComparator(updater, updaterDelegate); - return SPUCriticalUpdateTest(versionComparator, hostVersion, criticalVersion); -} - -id SPUVersionComparator(SPUUpdater *updater, id _Nullable updaterDelegate) -{ - id comparator = nil; - - // Give the delegate a chance to provide a custom version comparator - if ([updaterDelegate respondsToSelector:@selector((versionComparatorForUpdater:))]) { - comparator = [updaterDelegate versionComparatorForUpdater:(id _Nonnull)updater]; - } - - // If we don't get a comparator from the delegate, use the default comparator - if (comparator == nil) { - comparator = [SUStandardVersionComparator defaultComparator]; - } - - return comparator; -} diff --git a/Sparkle/SPUAppcastItemState.h b/Sparkle/SPUAppcastItemState.h new file mode 100644 index 00000000..48bccb13 --- /dev/null +++ b/Sparkle/SPUAppcastItemState.h @@ -0,0 +1,27 @@ +// +// SPUAppcastItemState.h +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +// Appcast Item state that contains properties that depends on a host +@interface SPUAppcastItemState : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK; + +@property (nonatomic, readonly) BOOL majorUpgrade; +@property (nonatomic, readonly) BOOL criticalUpdate; +@property (nonatomic, readonly) BOOL minimumOperatingSystemVersionIsOK; +@property (nonatomic, readonly) BOOL maximumOperatingSystemVersionIsOK; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemState.m b/Sparkle/SPUAppcastItemState.m new file mode 100644 index 00000000..12df1934 --- /dev/null +++ b/Sparkle/SPUAppcastItemState.m @@ -0,0 +1,64 @@ +// +// SPUAppcastItemState.m +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUAppcastItemState.h" + + +#include "AppKitPrevention.h" + +#define SPUAppcastItemStateMajorUpgradeKey @"SPUAppcastItemStateMajorUpgrade" +#define SPUAppcastItemStateCriticalUpdateKey @"SPUAppcastItemStateCriticalUpdate" +#define SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey @"SPUAppcastItemStateMinimumOperatingSystemVersionIsOK" +#define SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey @"SPUAppcastItemStateMaximumOperatingSystemVersionIsOK" + +@interface SPUAppcastItemState () +@end + +@implementation SPUAppcastItemState + +@synthesize majorUpgrade = _majorUpgrade; +@synthesize criticalUpdate = _criticalUpdate; +@synthesize minimumOperatingSystemVersionIsOK = _minimumOperatingSystemVersionIsOK; +@synthesize maximumOperatingSystemVersionIsOK = _maximumOperatingSystemVersionIsOK; + +- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK +{ + self = [super init]; + if (self != nil) { + _majorUpgrade = majorUpgrade; + _criticalUpdate = criticalUpdate; + _minimumOperatingSystemVersionIsOK = minimumOperatingSystemVersionIsOK; + _maximumOperatingSystemVersionIsOK = maximumOperatingSystemVersionIsOK; + } + return self; +} + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (void)encodeWithCoder:(NSCoder *)encoder +{ + [encoder encodeBool:self.majorUpgrade forKey:SPUAppcastItemStateMajorUpgradeKey]; + [encoder encodeBool:self.criticalUpdate forKey:SPUAppcastItemStateCriticalUpdateKey]; + [encoder encodeBool:self.minimumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey]; + [encoder encodeBool:self.maximumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey]; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + BOOL majorUpgrade = [decoder decodeBoolForKey:SPUAppcastItemStateMajorUpgradeKey]; + BOOL criticalUpdate = [decoder decodeBoolForKey:SPUAppcastItemStateCriticalUpdateKey]; + BOOL minimumOperatingSystemVersionIsOK = [decoder decodeBoolForKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey]; + BOOL maximumOperatingSystemVersionIsOK = [decoder decodeBoolForKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey]; + + return [self initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; +} + +@end diff --git a/Sparkle/SPUAppcastItemStateResolver.h b/Sparkle/SPUAppcastItemStateResolver.h new file mode 100644 index 00000000..4851a22b --- /dev/null +++ b/Sparkle/SPUAppcastItemStateResolver.h @@ -0,0 +1,27 @@ +// +// SPUAppcastItemStateResolver.h +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class SUStandardVersionComparator, SPUAppcastItemState; +@protocol SUVersionComparison; + +// Class used to resolve Appcast Item properties that rely on external factors such as a host +@interface SPUAppcastItemStateResolver : NSObject + +- (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator; + +- (SPUAppcastItemState *)resolveStateWithMinimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary; + ++ (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemStateResolver.m b/Sparkle/SPUAppcastItemStateResolver.m new file mode 100644 index 00000000..ffad603f --- /dev/null +++ b/Sparkle/SPUAppcastItemStateResolver.m @@ -0,0 +1,102 @@ +// +// SPUAppcastItemStateResolver.m +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemState.h" +#import "SUVersionComparisonProtocol.h" +#import "SUStandardVersionComparator.h" +#import "SUConstants.h" +#import "SUOperatingSystem.h" + + +#include "AppKitPrevention.h" + +@interface SPUAppcastItemStateResolver () + +@property (nonatomic, readonly) NSString *hostVersion; +@property (nonatomic, readonly) id applicationVersionComparator; +@property (nonatomic, readonly) SUStandardVersionComparator *standardVersionComparator; + +@end + +@implementation SPUAppcastItemStateResolver + +@synthesize hostVersion = _hostVersion; +@synthesize applicationVersionComparator = _applicationVersionComparator; +@synthesize standardVersionComparator = _standardVersionComparator; + +- (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator +{ + self = [super init]; + if (self != nil) { + _hostVersion = [hostVersion copy]; + _applicationVersionComparator = applicationVersionComparator; + _standardVersionComparator = standardVersionComparator; + } + return self; +} + +- (BOOL)isMinimumOperatingSystemVersionOK:(NSString * _Nullable)minimumSystemVersion +{ + BOOL minimumVersionOK = YES; + if (minimumSystemVersion != nil && ![minimumSystemVersion isEqualToString:@""]) { + minimumVersionOK = [self.standardVersionComparator compareVersion:(NSString * _Nonnull)minimumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending; + } + return minimumVersionOK; +} + +- (BOOL)isMaximumOperatingSystemVersionOK:(NSString * _Nullable)maximumSystemVersion +{ + BOOL maximumVersionOK = YES; + if (maximumSystemVersion != nil && ![maximumSystemVersion isEqualToString:@""]) { + maximumVersionOK = [self.standardVersionComparator compareVersion:(NSString * _Nonnull)maximumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending; + } + return maximumVersionOK; +} + ++ (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator + { + return (minimumAutoupdateVersion.length == 0 || ([versionComparator compareVersion:hostVersion toVersion:(NSString * _Nonnull)minimumAutoupdateVersion] != NSOrderedAscending)); + } + +- (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion + { + return [[self class] isMinimumAutoupdateVersionOK:minimumAutoupdateVersion hostVersion:self.hostVersion versionComparator:self.applicationVersionComparator]; + } + +- (BOOL)isCriticalUpdateWithCriticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary +{ + // Check if any critical update info is provided + if (criticalUpdateDictionary == nil) { + return NO; + } + + // If no critical version is supplied, then it is critical + NSString *criticalVersion = criticalUpdateDictionary[SUAppcastAttributeVersion]; + if (criticalVersion == nil || ![criticalVersion isKindOfClass:[NSString class]]) { + return YES; + } + + // Update is only critical when coming from previous versions + return ([self.applicationVersionComparator compareVersion:self.hostVersion toVersion:criticalVersion] == NSOrderedAscending); +} + +- (SPUAppcastItemState *)resolveStateWithMinimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary +{ + BOOL minimumOperatingSystemVersionIsOK = [self isMinimumOperatingSystemVersionOK:minimumOperatingSystemVersion]; + + BOOL maximumOperatingSystemVersionIsOK = [self isMaximumOperatingSystemVersionOK:minimumOperatingSystemVersion];; + + BOOL majorUpgrade = ![self isMinimumAutoupdateVersionOK:minimumAutoupdateVersion]; + + BOOL criticalUpdate = [self isCriticalUpdateWithCriticalUpdateDictionary:criticalUpdateDictionary]; + + return [[SPUAppcastItemState alloc] initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; +} + +@end diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 2635762f..9fd685fa 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -15,7 +15,6 @@ #import "SUAppcastItem.h" #import "SPUUserDriver.h" #import "SUErrors.h" -#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @@ -137,7 +136,7 @@ - (void)abortUpdateWithError:(NSError *)error { - BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || SPUAppcastItemIsCritical(self.updateItem, self.host.version, self.updater, self.updaterDelegate) || self.updateItem.isInformationOnlyUpdate); + BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate || self.updateItem.isInformationOnlyUpdate); [self.coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error]; } diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 6bb22416..fbd1c538 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -19,7 +19,6 @@ #import "SPUDownloadDriver.h" #import "SPUSkippedUpdate.h" #import "SPUUpdateState+Private.h" -#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @@ -182,7 +181,7 @@ } BOOL majorUpgrade = preventsAutoupdate; - BOOL criticalUpdate = SPUAppcastItemIsCritical(updateItem, self.host.version, self.updater, self.updaterDelegate); + BOOL criticalUpdate = updateItem.isCriticalUpdate; SPUUpdateState *state = [[SPUUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 2adb175e..89a8800c 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -30,7 +30,6 @@ #import "SPUUpdaterTimer.h" #import "SPUResumableUpdate.h" #import "SUSignatures.h" -#import "SPUAppcastItemSelection.h" #include "AppKitPrevention.h" @@ -885,7 +884,7 @@ static NSString *escapeURLComponent(NSString *str) { // Proceed as normal if there's no resumable updates completionHandler(regularCheckInterval); } else { - if (!installationInfo.canSilentlyInstall || SPUAppcastItemIsCritical(((SPUInstallationInfo * _Nonnull)installationInfo).appcastItem, self.host.version, self, self.delegate) || [installationInfo.appcastItem isInformationOnlyUpdate]) { + if (!installationInfo.canSilentlyInstall || [installationInfo.appcastItem isCriticalUpdate] || [installationInfo.appcastItem isInformationOnlyUpdate]) { completionHandler(MIN(regularCheckInterval, SUImpatientUpdateCheckInterval)); } else { completionHandler(MAX(regularCheckInterval, SUImpatientUpdateCheckInterval)); diff --git a/Sparkle/SUAppcast+Private.h b/Sparkle/SUAppcast+Private.h index c3fea632..30a22e71 100644 --- a/Sparkle/SUAppcast+Private.h +++ b/Sparkle/SUAppcast+Private.h @@ -6,8 +6,6 @@ // Copyright © 2021 Sparkle Project. All rights reserved. // -NS_ASSUME_NONNULL_BEGIN - #if __has_feature(modules) #if __has_warning("-Watimport-in-framework-header") #pragma clang diagnostic ignored "-Watimport-in-framework-header" @@ -17,9 +15,13 @@ NS_ASSUME_NONNULL_BEGIN #import #endif +NS_ASSUME_NONNULL_BEGIN + +@class SPUAppcastItemStateResolver; + @interface SUAppcast (Private) -- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL error:(NSError * __autoreleasing *)error; +- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver error:(NSError * __autoreleasing *)error; - (SUAppcast *)copyByFilteringItems:(BOOL (^)(SUAppcastItem *))filterBlock; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 2fafa686..3c977c8e 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -9,6 +9,7 @@ #import "SUExport.h" #import "SUAppcast.h" #import "SUAppcast+Private.h" +#import "SPUAppcastItemState.h" #import "SUAppcastItem.h" #import "SUAppcastItem+Private.h" #import "SUVersionComparisonProtocol.h" @@ -30,11 +31,11 @@ @synthesize items = _items; -- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL error:(NSError * __autoreleasing *)error +- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver error:(NSError * __autoreleasing *)error { self = [super init]; if (self != nil) { - _items = [self parseAppcastItemsFromXMLData:xmlData relativeToURL:relativeURL error:error]; + _items = [self parseAppcastItemsFromXMLData:xmlData relativeToURL:relativeURL stateResolver:stateResolver error:error]; if (_items == nil) { return nil; } @@ -72,7 +73,7 @@ } } --(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData relativeToURL:(NSURL * _Nullable)appcastURL error:(NSError *__autoreleasing*)errorp { +-(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver error:(NSError *__autoreleasing*)errorp { if (errorp) { *errorp = nil; } @@ -164,7 +165,8 @@ } NSString *errString; - SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict relativeToURL:appcastURL failureReason:&errString]; + SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict relativeToURL:appcastURL stateResolver:stateResolver failureReason:&errString]; + if (anItem) { [appcastItems addObject:anItem]; } diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 42627d7d..e8fd3620 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -23,7 +23,8 @@ #import "SPUDownloadData.h" #import "SULocalizations.h" #import "SUErrors.h" -#import "SPUAppcastItemSelection.h" +#import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemState.h" #include "AppKitPrevention.h" @@ -73,8 +74,10 @@ - (void)downloadDriverDidDownloadData:(SPUDownloadData *)downloadData { + SPUAppcastItemStateResolver *stateResolver = [[SPUAppcastItemStateResolver alloc] initWithHostVersion:self.host.version applicationVersionComparator:[self versionComparator] standardVersionComparator:[SUStandardVersionComparator defaultComparator]]; + NSError *appcastError = nil; - SUAppcast *appcast = [[SUAppcast alloc] initWithXMLData:downloadData.data relativeToURL:downloadData.URL error:&appcastError]; + SUAppcast *appcast = [[SUAppcast alloc] initWithXMLData:downloadData.data relativeToURL:downloadData.URL stateResolver:stateResolver error:&appcastError]; if (appcast == nil) { NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while parsing the update feed.", nil) forKey:NSLocalizedDescriptionKey]; @@ -196,7 +199,7 @@ if ([self isItemNewer:finalPrimaryItem]) { // We found a suitable update - BOOL preventsAutoupdate = ![[self class] isItemMinimumAutoupdateVersionOK:finalPrimaryItem.minimumAutoupdateVersion hostVersion:self.host.version versionComparator:applicationVersionComparator]; + BOOL preventsAutoupdate = finalPrimaryItem.majorUpgrade; [self.delegate didFindValidUpdateWithAppcastItem:finalPrimaryItem secondaryAppcastItem:finalSecondaryItem preventsAutoupdate:preventsAutoupdate]; } else { @@ -229,18 +232,18 @@ } // This method is used by unit tests -+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion { NSDate *currentDate = [NSDate date]; - BOOL hostPassesSkippedMajorVersion = [self isItemMinimumAutoupdateVersionOK:skippedUpdate.majorVersion hostVersion:hostVersion versionComparator:versionComparator]; + BOOL hostPassesSkippedMajorVersion = [SPUAppcastItemStateResolver isMinimumAutoupdateVersionOK:skippedUpdate.majorVersion hostVersion:hostVersion versionComparator:versionComparator]; return [appcast copyByFilteringItems:^(SUAppcastItem *item) { - BOOL passesOSVersion = (!testOSVersion || [self isItemMinimumAndMaximumOperatingSystemVersionOK:item]); + BOOL passesOSVersion = (!testOSVersion || (item.state.minimumOperatingSystemVersionIsOK && item.state.maximumOperatingSystemVersionIsOK)); BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate hostVersion:hostVersion versionComparator:versionComparator]; - BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || hostVersion == nil || versionComparator == nil || [self isItemMinimumAutoupdateVersionOK:item.minimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]); + BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || !item.majorUpgrade); BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdate:skippedUpdate hostPassesSkippedMajorVersion:hostPassesSkippedMajorVersion versionComparator:versionComparator]); @@ -297,21 +300,21 @@ return maximumVersionOK; } -+ (BOOL)isItemMinimumAndMaximumOperatingSystemVersionOK:(SUAppcastItem *)ui -{ - SUStandardVersionComparator *versionComparator = [[SUStandardVersionComparator alloc] init]; - - return [self isItemMinimumOperatingSystemVersionOK:ui versionComparator:versionComparator] && [self isItemMaximumOperatingSystemVersionOK:ui versionComparator:versionComparator]; -} - -+ (BOOL)isItemMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator - { - return (minimumAutoupdateVersion.length == 0 || ([versionComparator compareVersion:hostVersion toVersion:(NSString * _Nonnull)minimumAutoupdateVersion] != NSOrderedAscending)); - } - - (id)versionComparator { - return SPUVersionComparator(self.updater, self.updaterDelegate); + id comparator = nil; + + // Give the delegate a chance to provide a custom version comparator + if ([self.updaterDelegate respondsToSelector:@selector((versionComparatorForUpdater:))]) { + comparator = [self.updaterDelegate versionComparatorForUpdater:self.updater]; + } + + // If we don't get a comparator from the delegate, use the default comparator + if (comparator == nil) { + comparator = [SUStandardVersionComparator defaultComparator]; + } + + return comparator; } - (BOOL)isItemNewer:(SUAppcastItem *)ui @@ -342,7 +345,7 @@ + (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator { - if (phasedUpdateGroup == nil || SPUAppcastItemIsCriticalWithComparator(ui, hostVersion, versionComparator)) { + if (phasedUpdateGroup == nil || ui.criticalUpdate) { return YES; } diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h index 1c939cf0..55932309 100644 --- a/Sparkle/SUAppcastItem+Private.h +++ b/Sparkle/SUAppcastItem+Private.h @@ -18,12 +18,16 @@ #import #endif +#import "SUAppcastItem.h" + NS_ASSUME_NONNULL_BEGIN +@class SPUAppcastItemState, SPUAppcastItemStateResolver; + @interface SUAppcastItem (Private) -// Initializes with data from a dictionary provided by the RSS class. -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; +// Initializes with data from a dictionary provided by the RSS class and state resolver +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; @property (nullable, nonatomic, readonly) NSDictionary *criticalUpdateDictionary; diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 2700407d..11bdb916 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -19,6 +19,7 @@ #endif #import "SUExport.h" @class SUSignatures; +@class SPUAppcastItemState; NS_ASSUME_NONNULL_BEGIN @@ -43,10 +44,13 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly, nullable) NSString *minimumAutoupdateVersion; @property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; -@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate __deprecated_msg("Use -SPUUpdateState.criticalUpdate instead"); +@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate; +@property (getter=isMajorUpgrade, readonly) BOOL majorUpgrade; @property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; +@property (nonatomic, readonly) SPUAppcastItemState *state; + // Returns the dictionary representing the appcast item; this might be useful later for extensions. @property (readonly, copy) NSDictionary *propertiesDictionary; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index e82ea99c..6158804c 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -13,6 +13,8 @@ #import "SUConstants.h" #import "SUSignatures.h" #import "SPUInstallationType.h" +#import "SPUAppcastItemState.h" +#import "SPUAppcastItemStateResolver.h" #include "AppKitPrevention.h" @@ -31,6 +33,7 @@ static NSString *SUAppcastItemTitleKey = @"title"; static NSString *SUAppcastItemVersionStringKey = @"versionString"; static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationType"; +static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; @implementation SUAppcastItem @@ -52,6 +55,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT @synthesize installationType = _installationType; @synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion; @synthesize phasedRolloutInterval = _phasedRolloutInterval; +@synthesize state = _state; + (BOOL)supportsSecureCoding { @@ -80,6 +84,12 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT return nil; } + SPUAppcastItemState *state = [decoder decodeObjectOfClass:[SPUAppcastItemState class] forKey:SUAppcastItemStateKey]; + if (state == nil) { + return nil; + } + _state = state; + _installationType = [installationType copy]; _itemDescription = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionKey] copy]; @@ -151,6 +161,8 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT [encoder encodeObject:self.minimumAutoupdateVersion forKey:SUAppcastElementMinimumAutoupdateVersion]; } + [encoder encodeObject:self.state forKey:SUAppcastItemStateKey]; + if (self.releaseNotesURL != nil) { [encoder encodeObject:self.releaseNotesURL forKey:SUAppcastItemReleaseNotesURLKey]; } @@ -188,30 +200,12 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT - (BOOL)isCriticalUpdate { - return self.criticalUpdateDictionary != nil; + return self.state.criticalUpdate; } -- (NSDictionary * _Nullable)criticalUpdateDictionary +- (BOOL)isMajorUpgrade { - NSDictionary *criticalUpdateDictionary = self.propertiesDictionary[SUAppcastElementCriticalUpdate]; - if (criticalUpdateDictionary != nil) { - return criticalUpdateDictionary; - } - - // Check legacy / deprecated path where critical update used to be a tag - // This path does not support specifying which version became critical - NSArray *tags = [self.propertiesDictionary objectForKey:SUAppcastElementTags]; - if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { - return @{}; - } - - return nil; -} - -- (BOOL)containsCriticalUpdateTag -{ - NSArray *tags = [self.propertiesDictionary objectForKey:SUAppcastElementTags]; - return [tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]; + return self.state.majorUpgrade; } - (BOOL)isMacOsUpdate @@ -238,12 +232,17 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT return self.infoURL && !self.fileURL; } -- (instancetype)initWithDictionary:(NSDictionary *)dict +- (instancetype)initWithDictionary:(NSDictionary *)dict state:(SPUAppcastItemState *)state { - return [self initWithDictionary:dict relativeToURL:nil failureReason:nil]; + return [self initWithDictionary:dict relativeToURL:nil stateResolver:nil resolvedState:state failureReason:nil]; } -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString *__autoreleasing *)error +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver failureReason:(NSString *__autoreleasing *)error +{ + return [self initWithDictionary:dict relativeToURL:appcastURL stateResolver:stateResolver resolvedState:nil failureReason:error]; +} + +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver * _Nullable)stateResolver resolvedState:(SPUAppcastItemState * _Nullable)resolvedState failureReason:(NSString *__autoreleasing *)error { self = [super init]; if (self) { @@ -343,6 +342,26 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT _maximumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMaximumSystemVersion] copy]; _minimumAutoupdateVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumAutoupdateVersion] copy]; + if (stateResolver != nil) { + NSDictionary * _Nullable criticalUpdateDictionaryFromAppcast = (NSDictionary *)[dict objectForKey:SUAppcastElementCriticalUpdate]; + NSArray *tags = [dict objectForKey:SUAppcastElementTags]; + + NSDictionary * _Nullable criticalUpdateDictionary; + if (criticalUpdateDictionaryFromAppcast != nil) { + criticalUpdateDictionary = criticalUpdateDictionaryFromAppcast; + } else if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { + // Legacy path where critical update used to be a tag without a specified version + criticalUpdateDictionary = @{}; + } else { + criticalUpdateDictionary = nil; + } + + _state = [(SPUAppcastItemStateResolver * _Nonnull)stateResolver resolveStateWithMinimumOperatingSystemVersion:_minimumSystemVersion maximumOperatingSystemVersion:_maximumSystemVersion minimumAutoupdateVersion:_minimumAutoupdateVersion criticalUpdateDictionary:criticalUpdateDictionary]; + } else { + assert(resolvedState != nil); + _state = (SPUAppcastItemState * _Nonnull)resolvedState; + } + NSString* rolloutIntervalString = [(NSString *)[dict objectForKey:SUAppcastElementPhasedRolloutInterval] copy]; if (rolloutIntervalString != nil) { _phasedRolloutInterval = @(rolloutIntervalString.integerValue); @@ -415,7 +434,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT NSMutableDictionary *fakeAppCastDict = [dict mutableCopy]; [fakeAppCastDict removeObjectForKey:SUAppcastElementDeltas]; [fakeAppCastDict setObject:deltaDictionary forKey:SURSSElementEnclosure]; - SUAppcastItem *deltaItem = [[SUAppcastItem alloc] initWithDictionary:fakeAppCastDict]; + SUAppcastItem *deltaItem = [[SUAppcastItem alloc] initWithDictionary:fakeAppCastDict state:_state]; if (deltaItem != nil) { [deltas setObject:deltaItem forKey:deltaFrom]; diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 2142332e..35445d27 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -20,7 +20,6 @@ #import "SPUSkippedUpdate.h" #import "SUSignatures.h" #import "SPUInstallationType.h" -#import "SPUAppcastItemSelection.h" NS_ASSUME_NONNULL_BEGIN @@ -40,7 +39,7 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; + (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem *_Nullable __autoreleasing *_Nullable)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator; -+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; @end From 63e0b47c9826694de0c62abd6b14ce318db92008 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 09:32:00 -0700 Subject: [PATCH 08/29] Don't expose appcast item state publicly --- Sparkle/SUAppcastDriver.m | 3 ++- Sparkle/SUAppcastItem+Private.h | 4 +++- Sparkle/SUAppcastItem.h | 2 -- Sparkle/SUAppcastItem.m | 6 ++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index e8fd3620..78c24c0f 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -10,6 +10,7 @@ #import "SUAppcast.h" #import "SUAppcast+Private.h" #import "SUAppcastItem.h" +#import "SUAppcastItem+Private.h" #import "SUVersionComparisonProtocol.h" #import "SUStandardVersionComparator.h" #import "SUOperatingSystem.h" @@ -243,7 +244,7 @@ BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate hostVersion:hostVersion versionComparator:versionComparator]; - BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || !item.majorUpgrade); + BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || !item.state.majorUpgrade); BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdate:skippedUpdate hostPassesSkippedMajorVersion:hostPassesSkippedMajorVersion versionComparator:versionComparator]); diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h index 55932309..df503533 100644 --- a/Sparkle/SUAppcastItem+Private.h +++ b/Sparkle/SUAppcastItem+Private.h @@ -29,7 +29,9 @@ NS_ASSUME_NONNULL_BEGIN // Initializes with data from a dictionary provided by the RSS class and state resolver - (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; -@property (nullable, nonatomic, readonly) NSDictionary *criticalUpdateDictionary; +// Convenience wrapper properties (such as isCriticalUpdate) should be added to SUAppcastItem rather than +// exposing the state as public API +@property (nonatomic, readonly) SPUAppcastItemState *state; @end diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 11bdb916..54b5e168 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -49,8 +49,6 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; -@property (nonatomic, readonly) SPUAppcastItemState *state; - // Returns the dictionary representing the appcast item; this might be useful later for extensions. @property (readonly, copy) NSDictionary *propertiesDictionary; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 6158804c..6294e153 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -35,6 +35,12 @@ static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationType"; static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; +@interface SUAppcastItem () + +@property (nonatomic, readonly) SPUAppcastItemState *state; + +@end + @implementation SUAppcastItem @synthesize dateString = _dateString; From 8f488c6ffd8a2deda32e20cad3ec76e570f60eb3 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 09:58:09 -0700 Subject: [PATCH 09/29] Fix unit tests --- Sparkle/SPUAppcastItemStateResolver.m | 2 +- Sparkle/SUAppcastDriver.m | 27 +-------- Tests/SUAppcastTest.swift | 65 +++++++++++++++------- Tests/Sparkle Unit Tests-Bridging-Header.h | 1 + 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/Sparkle/SPUAppcastItemStateResolver.m b/Sparkle/SPUAppcastItemStateResolver.m index ffad603f..5a61c888 100644 --- a/Sparkle/SPUAppcastItemStateResolver.m +++ b/Sparkle/SPUAppcastItemStateResolver.m @@ -90,7 +90,7 @@ { BOOL minimumOperatingSystemVersionIsOK = [self isMinimumOperatingSystemVersionOK:minimumOperatingSystemVersion]; - BOOL maximumOperatingSystemVersionIsOK = [self isMaximumOperatingSystemVersionOK:minimumOperatingSystemVersion];; + BOOL maximumOperatingSystemVersionIsOK = [self isMaximumOperatingSystemVersionOK:maximumOperatingSystemVersion];; BOOL majorUpgrade = ![self isMinimumAutoupdateVersionOK:minimumAutoupdateVersion]; diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 78c24c0f..816b7337 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -216,11 +216,9 @@ hostToLatestAppcastItemComparisonResult = [applicationVersionComparator compareVersion:self.host.version toVersion:notFoundPrimaryItem.versionString]; - SUStandardVersionComparator *standardVersionComparator = [[SUStandardVersionComparator alloc] init]; + passesMinOSVersion = notFoundPrimaryItem.state.minimumOperatingSystemVersionIsOK; - passesMinOSVersion = [[self class] isItemMinimumOperatingSystemVersionOK:notFoundPrimaryItem versionComparator:standardVersionComparator]; - - passesMaxOSVersion = [[self class] isItemMaximumOperatingSystemVersionOK:notFoundPrimaryItem versionComparator:standardVersionComparator]; + passesMaxOSVersion = notFoundPrimaryItem.state.maximumOperatingSystemVersionIsOK; } else { notFoundPrimaryItem = nil; hostToLatestAppcastItemComparisonResult = 0; @@ -280,27 +278,6 @@ return item; } -+ (BOOL)isItemMinimumOperatingSystemVersionOK:(SUAppcastItem *)ui versionComparator:(SUStandardVersionComparator *)versionComparator -{ - BOOL minimumVersionOK = YES; - NSString *minimumSystemVersion = ui.minimumSystemVersion; - if (minimumSystemVersion != nil && ![minimumSystemVersion isEqualToString:@""]) { - minimumVersionOK = [versionComparator compareVersion:minimumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending; - } - return minimumVersionOK; -} - -// We don't want to use delegate's comparator for comparing OS versions -+ (BOOL)isItemMaximumOperatingSystemVersionOK:(SUAppcastItem *)ui versionComparator:(SUStandardVersionComparator *)versionComparator -{ - BOOL maximumVersionOK = YES; - NSString *maximumSystemVersion = ui.maximumSystemVersion; - if (maximumSystemVersion != nil && ![maximumSystemVersion isEqualToString:@""]) { - maximumVersionOK = [versionComparator compareVersion:maximumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending; - } - return maximumVersionOK; -} - - (id)versionComparator { id comparator = nil; diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 54c8ba1a..b8896f8c 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -17,42 +17,39 @@ class SUAppcastTest: XCTestCase { do { let testData = try Data(contentsOf: testURL) - let appcast = try SUAppcast(xmlData: testData, relativeTo: nil) + let versionComparator = SUStandardVersionComparator.default() + let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual(4, items.count) - - let standardComparator = SUStandardVersionComparator() XCTAssertEqual("Version 2.0", items[0].title) XCTAssertEqual("desc", items[0].itemDescription) XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString) - XCTAssertTrue(SPUAppcastItemIsCriticalWithComparator(items[0], "1.0", standardComparator)) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[0], "1.5", standardComparator)) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[0], "2.0", standardComparator)) + XCTAssertTrue(items[0].isCriticalUpdate) // This is the best release matching our system version XCTAssertEqual("Version 3.0", items[1].title) XCTAssertNil(items[1].itemDescription) XCTAssertNil(items[1].dateString) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[1], "1.0", standardComparator)) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[1], "2.0", standardComparator)) + XCTAssertFalse(items[1].isCriticalUpdate) XCTAssertEqual(items[1].phasedRolloutInterval, 86400) XCTAssertEqual("Version 4.0", items[2].title) XCTAssertNil(items[2].itemDescription) XCTAssertEqual("Sat, 26 Jul 2014 15:20:13 +0000", items[2].dateString) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[2], "1.0", standardComparator)) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[2], "2.0", standardComparator)) + XCTAssertFalse(items[2].isCriticalUpdate) XCTAssertEqual("Version 5.0", items[3].title) XCTAssertNil(items[3].itemDescription) XCTAssertNil(items[3].dateString) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[3], "1.0", standardComparator)) - XCTAssertFalse(SPUAppcastItemIsCriticalWithComparator(items[3], "2.0", standardComparator)) + XCTAssertFalse(items[3].isCriticalUpdate) // Test best appcast item & a delta update item - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) let supportedAppcastItems = supportedAppcast.items @@ -85,16 +82,26 @@ class SUAppcastTest: XCTestCase { do { let testData = try Data(contentsOf: testURL) - let appcast = try SUAppcast(xmlData: testData, relativeTo: nil) - - XCTAssertEqual(2, appcast.items.count) - let versionComparator = SUStandardVersionComparator() + do { + // Test appcast without a filter + + let hostVersion = "1.0" + + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertEqual(2, appcast.items.count) + } + // Because 3.0 has minimum autoupdate version of 2.0, we should be offered 2.0 do { let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(1, supportedAppcast.items.count) @@ -108,6 +115,9 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -121,6 +131,9 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.5" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -134,6 +147,9 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + // There should be no items if 2.0 is skipped from 1.0 and 3.0 fails minimum autoupdate version do { let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.0", majorVersion: nil) @@ -256,9 +272,12 @@ class SUAppcastTest: XCTestCase { let testFileUrl = URL(fileURLWithPath: testFile) XCTAssertNotNil(testFileUrl) - do { + do { let testFileData = try Data(contentsOf: testFileUrl) - let appcast = try SUAppcast(xmlData: testFileData, relativeTo: testFileUrl) + + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default(), standardVersionComparator: SUStandardVersionComparator.default()) + + let appcast = try SUAppcast(xmlData: testFileData, relativeTo: testFileUrl, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual("https://sparkle-project.org/#localized_notes_link_works", items[0].releaseNotesURL!.absoluteString) } catch let err as NSError { @@ -272,7 +291,9 @@ class SUAppcastTest: XCTestCase { let testData = NSData(contentsOfFile: testFile)! do { - let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: nil) + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default(), standardVersionComparator: SUStandardVersionComparator.default()) + + let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: nil, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual(2, items.count) @@ -294,7 +315,9 @@ class SUAppcastTest: XCTestCase { do { let baseURL = URL(string: "https://fake.sparkle-project.org/updates/index.xml")! - let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL) + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default(), standardVersionComparator: SUStandardVersionComparator.default()) + + let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual(2, items.count) diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 35445d27..d0e9251e 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -20,6 +20,7 @@ #import "SPUSkippedUpdate.h" #import "SUSignatures.h" #import "SPUInstallationType.h" +#import "SPUAppcastItemStateResolver.h" NS_ASSUME_NONNULL_BEGIN From 8fb44df0b76b3bc0705721e4608d0ece2cc7e4e8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 10:16:04 -0700 Subject: [PATCH 10/29] Add unit tests for critical updates --- Tests/Resources/testappcast.xml | 2 ++ Tests/SUAppcastTest.swift | 42 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index 7121e47a..f78862d1 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -13,6 +13,8 @@ Version 3.0 86400 + + Date: Mon, 31 May 2021 10:22:55 -0700 Subject: [PATCH 11/29] Remove critical and major upgrade properties from SPUUpdateState --- Sparkle/SPUSkippedUpdate.h | 2 +- Sparkle/SPUSkippedUpdate.m | 4 ++-- Sparkle/SPUUIBasedUpdateDriver.m | 7 ++----- Sparkle/SPUUpdateState+Private.h | 2 +- Sparkle/SPUUpdateState.h | 2 -- Sparkle/SPUUpdateState.m | 15 +++++---------- Sparkle/SUAppcastDriver.m | 2 +- Sparkle/SUUpdateAlert.m | 8 ++++---- 8 files changed, 16 insertions(+), 26 deletions(-) diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h index 40259373..ebf44aad 100644 --- a/Sparkle/SPUSkippedUpdate.h +++ b/Sparkle/SPUSkippedUpdate.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN + (void)clearSkippedUpdateForHost:(SUHost *)host; -+ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade; ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host; // At least one of minorVersion or majorVersion should be non-nil - (instancetype)initWithMinorVersion:(nullable NSString *)minorVersion majorVersion:(nullable NSString *)majorVersion; diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m index e8791413..c3d61bed 100644 --- a/Sparkle/SPUSkippedUpdate.m +++ b/Sparkle/SPUSkippedUpdate.m @@ -49,9 +49,9 @@ [host setObject:nil forUserDefaultsKey:SUSkippedMajorVersionKey]; } -+ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host { - if (majorUpgrade) { + if (updateItem.majorUpgrade) { NSString *majorVersion = updateItem.minimumAutoupdateVersion; assert(majorVersion != nil); diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index fbd1c538..4dd0bcfc 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -180,10 +180,7 @@ stage = SPUUpdateStageNotDownloaded; } - BOOL majorUpgrade = preventsAutoupdate; - BOOL criticalUpdate = updateItem.isCriticalUpdate; - - SPUUpdateState *state = [[SPUUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; + SPUUpdateState *state = [[SPUUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -215,7 +212,7 @@ break; } case SPUUserUpdateChoiceSkip: { - [SPUSkippedUpdate skipUpdate:updateItem host:self.host majorUpgrade:majorUpgrade]; + [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; diff --git a/Sparkle/SPUUpdateState+Private.h b/Sparkle/SPUUpdateState+Private.h index ed040132..1c2ab7e8 100644 --- a/Sparkle/SPUUpdateState+Private.h +++ b/Sparkle/SPUUpdateState+Private.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUUpdateState (Private) -- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate; +- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated; @end diff --git a/Sparkle/SPUUpdateState.h b/Sparkle/SPUUpdateState.h index fd16f377..60f8826e 100644 --- a/Sparkle/SPUUpdateState.h +++ b/Sparkle/SPUUpdateState.h @@ -33,8 +33,6 @@ SU_EXPORT @interface SPUUpdateState : NSObject @property (nonatomic, readonly) SPUUpdateStage stage; @property (nonatomic, readonly) BOOL userInitiated; -@property (nonatomic, readonly) BOOL majorUpgrade; -@property (nonatomic, readonly) BOOL criticalUpdate; @end diff --git a/Sparkle/SPUUpdateState.m b/Sparkle/SPUUpdateState.m index a86a8d4e..19e5c400 100644 --- a/Sparkle/SPUUpdateState.m +++ b/Sparkle/SPUUpdateState.m @@ -17,21 +17,20 @@ #define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" #define SPUUserUpdateStateCriticalUpdateKey @"SPUUserUpdateStateCriticalUpdate" +@interface SPUUpdateState () +@end + @implementation SPUUpdateState @synthesize stage = _stage; @synthesize userInitiated = _userInitiated; -@synthesize majorUpgrade = _majorUpgrade; -@synthesize criticalUpdate = _criticalUpdate; -- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate +- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated { self = [super init]; if (self != nil) { _stage = stage; _userInitiated = userInitiated; - _majorUpgrade = majorUpgrade; - _criticalUpdate = criticalUpdate; } return self; } @@ -40,18 +39,14 @@ { [encoder encodeInteger:self.stage forKey:SPUUserUpdateStateStageKey]; [encoder encodeBool:self.userInitiated forKey:SPUUserUpdateStateUserInitiatedKey]; - [encoder encodeBool:self.majorUpgrade forKey:SPUUserUpdateStateMajorUpgradeKey]; - [encoder encodeBool:self.criticalUpdate forKey:SPUUserUpdateStateCriticalUpdateKey]; } - (instancetype)initWithCoder:(NSCoder *)decoder { SPUUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; BOOL userInitiated = [decoder decodeBoolForKey:SPUUserUpdateStateUserInitiatedKey]; - BOOL majorUpgrade = [decoder decodeBoolForKey:SPUUserUpdateStateMajorUpgradeKey]; - BOOL criticalUpdate = [decoder decodeBoolForKey:SPUUserUpdateStateCriticalUpdateKey]; - return [self initWithStage:stage userInitiated:userInitiated majorUpgrade:majorUpgrade criticalUpdate:criticalUpdate]; + return [self initWithStage:stage userInitiated:userInitiated]; } + (BOOL)supportsSecureCoding diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 816b7337..1ea31a7c 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -242,7 +242,7 @@ BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate hostVersion:hostVersion versionComparator:versionComparator]; - BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || !item.state.majorUpgrade); + BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || !item.majorUpgrade); BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdate:skippedUpdate hostPassesSkippedMajorVersion:hostPassesSkippedMajorVersion versionComparator:versionComparator]); diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index bd105384..cb830306 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -139,7 +139,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (IBAction)skipThisVersion:(id)__unused sender { - if (self.state.majorUpgrade) { + if (self.updateItem.majorUpgrade) { NSAlert *alert = [[NSAlert alloc] init]; alert.alertStyle = NSAlertStyleInformational; alert.informativeText = SULocalizedString(@"Skipping this major upgrade will opt out of alerts for future updates.", nil); @@ -381,7 +381,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); } - if (self.state.criticalUpdate && !self.state.majorUpgrade) { + if (self.updateItem.criticalUpdate && !self.updateItem.majorUpgrade) { self.skipButton.hidden = YES; self.laterButton.hidden = YES; } @@ -407,7 +407,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (NSString *)titleText { - if (self.state.criticalUpdate) + if (self.updateItem.criticalUpdate) { return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [self.host name]]; } @@ -438,7 +438,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE if (self.state.stage == SPUUpdateStageInformational) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; - } else if (self.state.criticalUpdate) { + } else if (self.updateItem.criticalUpdate) { if (self.state.stage == SPUUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. This is an important update; would you like to download it now?", @"Description text for SUUpdateAlert when the critical update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { From 062bfaaa97f3cdfe466379ded0df0621676b2498 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 10:59:35 -0700 Subject: [PATCH 12/29] Remove old code passing min/max OS tests --- Sparkle/SPUBasicUpdateDriver.m | 8 +++++--- Sparkle/SUAppcastDriver.h | 2 +- Sparkle/SUAppcastDriver.m | 10 +--------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index c0b2459a..173bde88 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -18,6 +18,8 @@ #import "SPUProbeInstallStatus.h" #import "SPUInstallationInfo.h" #import "SPUResumableUpdate.h" +#import "SPUAppcastItemState.h" +#import "SUAppcastItem+Private.h" #include "AppKitPrevention.h" @@ -157,7 +159,7 @@ [self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem preventsAutoupdate:preventsAutoupdate systemDomain:nil]; } -- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult passesMinOSVersion:(BOOL)passesMinOSVersion passesMaxOSVersion:(BOOL)passesMaxOSVersion +- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult { if (!self.aborted) { if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) { @@ -185,11 +187,11 @@ break; case NSOrderedAscending: // This means a new update doesn't match the OS requirements - if (!passesMinOSVersion) { + if (!latestAppcastItem.state.minimumOperatingSystemVersionIsOK) { 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]; - } else if (!passesMaxOSVersion) { + } else if (!latestAppcastItem.state.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]; diff --git a/Sparkle/SUAppcastDriver.h b/Sparkle/SUAppcastDriver.h index cc142d72..12509e3a 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 *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; -- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult passesMinOSVersion:(BOOL)passesMinOSVersion passesMaxOSVersion:(BOOL)passesMaxOSVersion; +- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult; @end diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 1ea31a7c..b8ff51ab 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -209,24 +209,16 @@ // We only need to do this if an update is being checked by the user manually SUAppcastItem *notFoundPrimaryItem; NSComparisonResult hostToLatestAppcastItemComparisonResult; - BOOL passesMinOSVersion; - BOOL passesMaxOSVersion; if (!background) { notFoundPrimaryItem = [self retrieveBestAppcastItemFromAppcast:macOSAppcast versionComparator:applicationVersionComparator secondaryUpdate:nil]; hostToLatestAppcastItemComparisonResult = [applicationVersionComparator compareVersion:self.host.version toVersion:notFoundPrimaryItem.versionString]; - - passesMinOSVersion = notFoundPrimaryItem.state.minimumOperatingSystemVersionIsOK; - - passesMaxOSVersion = notFoundPrimaryItem.state.maximumOperatingSystemVersionIsOK; } else { notFoundPrimaryItem = nil; hostToLatestAppcastItemComparisonResult = 0; - passesMinOSVersion = YES; - passesMaxOSVersion = YES; } - [self.delegate didNotFindUpdateWithLatestAppcastItem:notFoundPrimaryItem hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult passesMinOSVersion:passesMinOSVersion passesMaxOSVersion:passesMaxOSVersion]; + [self.delegate didNotFindUpdateWithLatestAppcastItem:notFoundPrimaryItem hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult]; } } From ee5e98d3dd9384a79bc2950fa119a889e393e765 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 11:12:27 -0700 Subject: [PATCH 13/29] Rename SPUUpdateState back to SPUUserUpdateState --- Sparkle.xcodeproj/project.pbxproj | 34 ++++++------- Sparkle/SPUCoreBasedUpdateDriver.h | 3 +- Sparkle/SPUStandardUserDriver.m | 4 +- Sparkle/SPUUIBasedUpdateDriver.m | 40 +++++++-------- Sparkle/SPUUpdateState+Private.h | 22 --------- Sparkle/SPUUpdateState.h | 41 ---------------- Sparkle/SPUUserDriver.h | 6 +-- Sparkle/SPUUserUpdateChoice.h | 18 ------- Sparkle/SPUUserUpdateState+Private.h | 24 +++++++++ Sparkle/SPUUserUpdateState.h | 49 +++++++++++++++++++ ...{SPUUpdateState.m => SPUUserUpdateState.m} | 12 ++--- Sparkle/SUUpdateAlert.h | 6 +-- Sparkle/SUUpdateAlert.m | 20 ++++---- Sparkle/Sparkle.h | 2 +- TestApplication/SUPopUpTitlebarUserDriver.m | 10 ++-- 15 files changed, 138 insertions(+), 153 deletions(-) delete mode 100644 Sparkle/SPUUpdateState+Private.h delete mode 100644 Sparkle/SPUUpdateState.h delete mode 100644 Sparkle/SPUUserUpdateChoice.h create mode 100644 Sparkle/SPUUserUpdateState+Private.h create mode 100644 Sparkle/SPUUserUpdateState.h rename Sparkle/{SPUUpdateState.m => SPUUserUpdateState.m} (77%) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 085caf98..ecb65e20 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -289,9 +289,9 @@ 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; 7269E497264798200088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; 7269E4982648D3460088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; - 7269E49A2648F7C00088C213 /* SPUUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUpdateState.m */; }; - 7269E49B2648F7C00088C213 /* SPUUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUpdateState.m */; }; - 726DF88E1C84277600188804 /* SPUUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7269E49A2648F7C00088C213 /* SPUUserUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */; }; + 7269E49B2648F7C00088C213 /* SPUUserUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */; }; + 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUserUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E075C1CA3A6D6001A286B /* SPUSecureCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */; }; 726E075D1CA3A6D6001A286B /* SPUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */; }; 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E078B1CA891E9001A286B /* SPUUpdaterSettings.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -323,8 +323,6 @@ 7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 7293A1B11CEE9B9F00B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 729924941DF4A45000DBCDF5 /* SUUpdateValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */; }; - 729E1D1B2664C2C500BF3EFB /* SPUUserUpdateChoice.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 729E1D1C2664C34000BF3EFB /* SPUUserUpdateChoice.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */; settings = {ATTRIBUTES = (Public, ); }; }; 729E1D1F26651CF500BF3EFB /* SPUAppcastItemState.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */; }; 729E1D2026651CF500BF3EFB /* SPUAppcastItemState.h in Headers */ = {isa = PBXBuildFile; fileRef = 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */; }; 729E1D2126651CF500BF3EFB /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */; }; @@ -399,7 +397,7 @@ 72A5D5F41D692CF50009E5AC /* SparkleCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72A5D59C1D6927730009E5AC /* SparkleCore.framework */; }; 72A5D5F51D692CFE0009E5AC /* SparkleCore.framework in Copy Sparkle */ = {isa = PBXBuildFile; fileRef = 72A5D59C1D6927730009E5AC /* SparkleCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 72A5D5F81D692F2B0009E5AC /* SUExport.h in Headers */ = {isa = PBXBuildFile; fileRef = 14652F8319A9759F00959E44 /* SUExport.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 72A5D5F91D692F4C0009E5AC /* SPUUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 72A5D5F91D692F4C0009E5AC /* SPUUserUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUserUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5FB1D69312F0009E5AC /* SUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SUBundleIcon.m */; }; 72A6F98A1C94E2D6005F404C /* SUUpdaterDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A6F9891C94E2D6005F404C /* SUUpdaterDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72AC6B261B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */; }; @@ -1265,10 +1263,10 @@ 7267E5FB1D3DD1B700D1BF90 /* SPUResumableUpdate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUResumableUpdate.h; sourceTree = ""; }; 7269E492264798200088C213 /* SPUSkippedUpdate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUSkippedUpdate.h; sourceTree = ""; }; 7269E493264798200088C213 /* SPUSkippedUpdate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUSkippedUpdate.m; sourceTree = ""; }; - 7269E4992648F7C00088C213 /* SPUUpdateState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUUpdateState.m; sourceTree = ""; }; - 7269E49C2648FC6C0088C213 /* SPUUpdateState+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUUpdateState+Private.h"; sourceTree = ""; }; + 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUUserUpdateState.m; sourceTree = ""; }; + 7269E49C2648FC6C0088C213 /* SPUUserUpdateState+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUUserUpdateState+Private.h"; sourceTree = ""; }; 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 726DF88D1C84277500188804 /* SPUUpdateState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdateState.h; sourceTree = ""; }; + 726DF88D1C84277500188804 /* SPUUserUpdateState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUserUpdateState.h; sourceTree = ""; }; 726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUSecureCoding.h; path = Sparkle/SPUSecureCoding.h; sourceTree = SOURCE_ROOT; }; 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUSecureCoding.m; path = Sparkle/SPUSecureCoding.m; sourceTree = SOURCE_ROOT; }; 726E07681CA616A4001A286B /* libxar.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxar.tbd; path = usr/lib/libxar.tbd; sourceTree = SDKROOT; }; @@ -1306,7 +1304,6 @@ 729924921DF4A45000DBCDF5 /* SUUpdateValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUUpdateValidator.h; path = Sparkle/SUUpdateValidator.h; sourceTree = SOURCE_ROOT; }; 729924931DF4A45000DBCDF5 /* SUUpdateValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUUpdateValidator.m; path = Sparkle/SUUpdateValidator.m; sourceTree = SOURCE_ROOT; }; 729BB3D11D503826007C4276 /* org.sparkle-project.Downloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "org.sparkle-project.Downloader.entitlements"; path = "Downloader/org.sparkle-project.Downloader.entitlements"; sourceTree = SOURCE_ROOT; }; - 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUUserUpdateChoice.h; sourceTree = ""; }; 729E1D1D26651CF500BF3EFB /* SPUAppcastItemState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemState.h; sourceTree = ""; }; 729E1D1E26651CF500BF3EFB /* SPUAppcastItemState.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemState.m; sourceTree = ""; }; 729E1D2526652DCF00BF3EFB /* SPUAppcastItemStateResolver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemStateResolver.h; sourceTree = ""; }; @@ -2065,9 +2062,6 @@ 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */, 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */, 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */, - 726DF88D1C84277500188804 /* SPUUpdateState.h */, - 7269E49C2648FC6C0088C213 /* SPUUpdateState+Private.h */, - 7269E4992648F7C00088C213 /* SPUUpdateState.m */, ); name = "Update Control"; sourceTree = ""; @@ -2173,7 +2167,9 @@ 725CB9591C7121830064365A /* SPUStandardUserDriver.m */, 726E4A361C89116000C57C6A /* SPUStandardUserDriverDelegate.h */, 725CB9561C7120410064365A /* SPUUserDriver.h */, - 729E1D1A2664C1F800BF3EFB /* SPUUserUpdateChoice.h */, + 726DF88D1C84277500188804 /* SPUUserUpdateState.h */, + 7269E49C2648FC6C0088C213 /* SPUUserUpdateState+Private.h */, + 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */, ); name = "User Driver"; sourceTree = ""; @@ -2422,13 +2418,12 @@ buildActionMask = 2147483647; files = ( 729E1D2826652DCF00BF3EFB /* SPUAppcastItemStateResolver.h in Headers */, - 729E1D1C2664C34000BF3EFB /* SPUUserUpdateChoice.h in Headers */, 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */, 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */, 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */, 721D588E25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */, - 72A5D5F91D692F4C0009E5AC /* SPUUpdateState.h in Headers */, + 72A5D5F91D692F4C0009E5AC /* SPUUserUpdateState.h in Headers */, 72A5D5E71D692BB00009E5AC /* SPUUpdatePermissionRequest.h in Headers */, EA1E286F22B6661D004AA304 /* SUSignatures.h in Headers */, 72A5D5E21D692B770009E5AC /* SPUUpdater.h in Headers */, @@ -2455,7 +2450,6 @@ 72B767D61C9C8B5C00A07552 /* SPUBasicUpdateDriver.h in Headers */, 72B767E21C9CE90A00A07552 /* SPUCoreBasedUpdateDriver.h in Headers */, 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */, - 729E1D1B2664C2C500BF3EFB /* SPUUserUpdateChoice.h in Headers */, 7229E1BD1C98EFF200CB50D0 /* SPUDownloadDriver.h in Headers */, 7267E5FD1D3DD1B700D1BF90 /* SPUResumableUpdate.h in Headers */, 7267E5B61D3D8AEE00D1BF90 /* SPUInstallationInfo.h in Headers */, @@ -2472,7 +2466,7 @@ 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */, 725CB95A1C7121830064365A /* SPUStandardUserDriver.h in Headers */, 726E4A371C89116000C57C6A /* SPUStandardUserDriverDelegate.h in Headers */, - 726DF88E1C84277600188804 /* SPUUpdateState.h in Headers */, + 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */, 72B767DA1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.h in Headers */, 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */, 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */, @@ -3599,7 +3593,7 @@ 72A5D5B01D6929F80009E5AC /* SUInstallerConnection.m in Sources */, 72A5D5AE1D6929F80009E5AC /* SUInstallerLauncher.m in Sources */, 72B3DED01E23479000457642 /* SPUInformationalUpdate.m in Sources */, - 7269E49B2648F7C00088C213 /* SPUUpdateState.m in Sources */, + 7269E49B2648F7C00088C213 /* SPUUserUpdateState.m in Sources */, 72A5D5B21D6929F80009E5AC /* SUInstallerStatus.m in Sources */, 72A5D5C51D6929F80009E5AC /* SULog.m in Sources */, 72A5D5C61D6929F80009E5AC /* SUOperatingSystem.m in Sources */, @@ -3705,7 +3699,7 @@ 72B767CB1C9B707000A07552 /* SUAppcastDriver.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */, - 7269E49A2648F7C00088C213 /* SPUUpdateState.m in Sources */, + 7269E49A2648F7C00088C213 /* SPUUserUpdateState.m in Sources */, 725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */, 7214B8821D456A8500CB5CED /* SUBundleIcon.m in Sources */, 72DBA37F1D62C23E002594A8 /* SUCodeSigningVerifier.m in Sources */, diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index b52e4c95..833ff946 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -7,9 +7,8 @@ // #import -#import "SPUUpdateState.h" #import "SPUUpdateDriver.h" -#import "SPUUserUpdateChoice.h" +#import "SPUUserUpdateState.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index d0faf60d..78198e98 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -17,7 +17,7 @@ #import "SULocalizations.h" #import "SUApplicationInfo.h" #import "SUOperatingSystem.h" -#import "SPUUpdateState.h" +#import "SPUUserUpdateState.h" @interface SPUStandardUserDriver () @@ -116,7 +116,7 @@ #pragma mark Update Found -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { assert(NSThread.isMainThread); diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 4dd0bcfc..ed8f958c 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -18,7 +18,7 @@ #import "SPUResumableUpdate.h" #import "SPUDownloadDriver.h" #import "SPUSkippedUpdate.h" -#import "SPUUpdateState+Private.h" +#import "SPUUserUpdateState+Private.h" #include "AppKitPrevention.h" @@ -169,25 +169,25 @@ id updaterDelegate = self.updaterDelegate; - SPUUpdateStage stage; + SPUUserUpdateStage stage; if (updateItem.isInformationOnlyUpdate) { - stage = SPUUpdateStageInformational; + stage = SPUUserUpdateStageInformational; } else if (self.resumingDownloadedUpdate) { - stage = SPUUpdateStageDownloaded; + stage = SPUUserUpdateStageDownloaded; } else if (self.resumingInstallingUpdate) { - stage = SPUUpdateStageInstalling; + stage = SPUUserUpdateStageInstalling; } else { - stage = SPUUpdateStageNotDownloaded; + stage = SPUUserUpdateStageNotDownloaded; } - SPUUpdateState *state = [[SPUUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated]; + SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ // Rule out invalid choices SPUUserUpdateChoice validatedChoice; - if (stage == SPUUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { + if (stage == SPUUserUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { validatedChoice = SPUUserUpdateChoiceDismiss; } else { validatedChoice = userChoice; @@ -196,16 +196,16 @@ switch (validatedChoice) { case SPUUserUpdateChoiceInstall: { switch (stage) { - case SPUUpdateStageDownloaded: + case SPUUserUpdateStageDownloaded: [self.coreDriver extractDownloadedUpdate]; break; - case SPUUpdateStageInstalling: + case SPUUserUpdateStageInstalling: [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; - case SPUUpdateStageNotDownloaded: + case SPUUserUpdateStageNotDownloaded: [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:NO]; break; - case SPUUpdateStageInformational: + case SPUUserUpdateStageInformational: assert(false); break; } @@ -219,9 +219,9 @@ } switch (stage) { - case SPUUpdateStageDownloaded: - case SPUUpdateStageNotDownloaded: - case SPUUpdateStageInformational: + case SPUUserUpdateStageDownloaded: + case SPUUserUpdateStageNotDownloaded: + case SPUUserUpdateStageInformational: // Informational updates can be resumed too, so make sure we check // self.resumingDownloadedUpdate instead of the stage we pass to user driver if (self.resumingDownloadedUpdate) { @@ -231,7 +231,7 @@ [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break; - case SPUUpdateStageInstalling: + case SPUUserUpdateStageInstalling: [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; } @@ -240,13 +240,13 @@ } case SPUUserUpdateChoiceDismiss: { switch (stage) { - case SPUUpdateStageDownloaded: - case SPUUpdateStageNotDownloaded: - case SPUUpdateStageInformational: { + case SPUUserUpdateStageDownloaded: + case SPUUserUpdateStageNotDownloaded: + case SPUUserUpdateStageInformational: { [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break; } - case SPUUpdateStageInstalling: { + case SPUUserUpdateStageInstalling: { [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; } diff --git a/Sparkle/SPUUpdateState+Private.h b/Sparkle/SPUUpdateState+Private.h deleted file mode 100644 index 1c2ab7e8..00000000 --- a/Sparkle/SPUUpdateState+Private.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// SPUUpdateState+Private.h -// Sparkle -// -// Created by Mayur Pawashe on 5/9/21. -// Copyright © 2021 Sparkle Project. All rights reserved. -// - -#ifndef SPUUpdateState_Private_h -#define SPUUpdateState_Private_h - -NS_ASSUME_NONNULL_BEGIN - -@interface SPUUpdateState (Private) - -- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated; - -@end - -NS_ASSUME_NONNULL_END - -#endif /* SPUUpdateState_Private_h */ diff --git a/Sparkle/SPUUpdateState.h b/Sparkle/SPUUpdateState.h deleted file mode 100644 index 60f8826e..00000000 --- a/Sparkle/SPUUpdateState.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// SPUUpdateState.h -// Sparkle -// -// Created by Mayur Pawashe on 2/29/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#ifndef SPUUpdateState_h -#define SPUUpdateState_h - -#if __has_feature(modules) -#if __has_warning("-Watimport-in-framework-header") -#pragma clang diagnostic ignored "-Watimport-in-framework-header" -#endif -@import Foundation; -#else -#import -#endif - -#import "SUExport.h" - -NS_ASSUME_NONNULL_BEGIN - -typedef NS_ENUM(NSInteger, SPUUpdateStage) { - SPUUpdateStageNotDownloaded, - SPUUpdateStageDownloaded, - SPUUpdateStageInstalling, - SPUUpdateStageInformational -}; - -SU_EXPORT @interface SPUUpdateState : NSObject - -@property (nonatomic, readonly) SPUUpdateStage stage; -@property (nonatomic, readonly) BOOL userInitiated; - -@end - -NS_ASSUME_NONNULL_END - -#endif /* SPUUpdateState_h */ diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 38b7f051..6b6e80af 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -15,12 +15,12 @@ #import #endif -#import "SPUUserUpdateChoice.h" +#import "SPUUserUpdateState.h" #import "SUExport.h" NS_ASSUME_NONNULL_BEGIN -@class SPUUpdatePermissionRequest, SUUpdatePermissionResponse, SUAppcastItem, SPUDownloadData, SPUUpdateState; +@class SPUUpdatePermissionRequest, SUUpdatePermissionResponse, SUAppcastItem, SPUDownloadData; /*! The API in Sparkle for controlling the user interaction. @@ -83,7 +83,7 @@ SU_EXPORT @protocol SPUUserDriver * If state.majorUpgrade is YES, the major update and any minor updates to that major release are skipped. * If the state.stage is SPUUpdateStateInstalling, the installation is also canceled when the update is skipped. */ -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; /*! * Show the user the release notes for the new update diff --git a/Sparkle/SPUUserUpdateChoice.h b/Sparkle/SPUUserUpdateChoice.h deleted file mode 100644 index 194ff871..00000000 --- a/Sparkle/SPUUserUpdateChoice.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// SPUUserUpdateChoice.h -// Sparkle -// -// Created by Mayur Pawashe on 5/31/21. -// Copyright © 2021 Sparkle Project. All rights reserved. -// - -#ifndef SPUUserUpdateChoice_h -#define SPUUserUpdateChoice_h - -typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { - SPUUserUpdateChoiceSkip, - SPUUserUpdateChoiceInstall, - SPUUserUpdateChoiceDismiss, -}; - -#endif /* SPUUserUpdateChoice_h */ diff --git a/Sparkle/SPUUserUpdateState+Private.h b/Sparkle/SPUUserUpdateState+Private.h new file mode 100644 index 00000000..578fc98d --- /dev/null +++ b/Sparkle/SPUUserUpdateState+Private.h @@ -0,0 +1,24 @@ +// +// SPUUserUpdateState+Private.h +// Sparkle +// +// Created by Mayur Pawashe on 5/9/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#ifndef SPUUserUpdateState_Private_h +#define SPUUserUpdateState_Private_h + +#import "SPUUserUpdateState.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SPUUserUpdateState (Private) + +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUUserUpdateState_Private_h */ diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUserUpdateState.h new file mode 100644 index 00000000..0b004ae7 --- /dev/null +++ b/Sparkle/SPUUserUpdateState.h @@ -0,0 +1,49 @@ +// +// SPUUserUpdateState.h +// Sparkle +// +// Created by Mayur Pawashe on 2/29/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#ifndef SPUUpdateState_h +#define SPUUpdateState_h + +#if __has_feature(modules) +#if __has_warning("-Watimport-in-framework-header") +#pragma clang diagnostic ignored "-Watimport-in-framework-header" +#endif +@import Foundation; +#else +#import +#endif + +#import "SUExport.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { + SPUUserUpdateChoiceSkip, + SPUUserUpdateChoiceInstall, + SPUUserUpdateChoiceDismiss, +}; + +typedef NS_ENUM(NSInteger, SPUUserUpdateStage) { + SPUUserUpdateStageNotDownloaded, + SPUUserUpdateStageDownloaded, + SPUUserUpdateStageInstalling, + SPUUserUpdateStageInformational +}; + +SU_EXPORT @interface SPUUserUpdateState : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +@property (nonatomic, readonly) SPUUserUpdateStage stage; +@property (nonatomic, readonly) BOOL userInitiated; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUUserUpdateState_h */ diff --git a/Sparkle/SPUUpdateState.m b/Sparkle/SPUUserUpdateState.m similarity index 77% rename from Sparkle/SPUUpdateState.m rename to Sparkle/SPUUserUpdateState.m index 19e5c400..32654807 100644 --- a/Sparkle/SPUUpdateState.m +++ b/Sparkle/SPUUserUpdateState.m @@ -6,8 +6,8 @@ // Copyright © 2021 Sparkle Project. All rights reserved. // -#import "SPUUpdateState.h" -#import "SPUUpdateState+Private.h" +#import "SPUUserUpdateState.h" +#import "SPUUserUpdateState+Private.h" #include "AppKitPrevention.h" @@ -17,15 +17,15 @@ #define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" #define SPUUserUpdateStateCriticalUpdateKey @"SPUUserUpdateStateCriticalUpdate" -@interface SPUUpdateState () +@interface SPUUserUpdateState () @end -@implementation SPUUpdateState +@implementation SPUUserUpdateState @synthesize stage = _stage; @synthesize userInitiated = _userInitiated; -- (instancetype)initWithStage:(SPUUpdateStage)stage userInitiated:(BOOL)userInitiated +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated { self = [super init]; if (self != nil) { @@ -43,7 +43,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder { - SPUUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; + SPUUserUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; BOOL userInitiated = [decoder decodeBoolForKey:SPUUserUpdateStateUserInitiatedKey]; return [self initWithStage:stage userInitiated:userInitiated]; diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index db2a5a3b..41ee55bd 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -11,16 +11,16 @@ #import #import "SUVersionDisplayProtocol.h" -#import "SPUUserUpdateChoice.h" +#import "SPUUserUpdateState.h" @protocol SUUpdateAlertDelegate; -@class SUAppcastItem, SPUDownloadData, SUHost, SPUUpdateState; +@class SUAppcastItem, SPUDownloadData, SUHost; @interface SUUpdateAlert : NSWindowController @property (nonatomic, weak, readonly) id versionDisplayer; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block; - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; - (void)showReleaseNotesFailedToDownload; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index cb830306..633676c8 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -27,7 +27,7 @@ #import "SUTouchBarForwardDeclarations.h" #import "SUTouchBarButtonGroup.h" #import "SPUXPCServiceInfo.h" -#import "SPUUpdateState.h" +#import "SPUUserUpdateState.h" static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdateAlert"; @@ -37,7 +37,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @property (strong) SUHost *host; @property (nonatomic) BOOL allowsAutomaticUpdates; @property (nonatomic, copy, nullable) void(^completionBlock)(SPUUserUpdateChoice); -@property (nonatomic) SPUUpdateState *state; +@property (nonatomic) SPUUserUpdateState *state; @property (strong) NSProgressIndicator *releaseNotesSpinner; @@ -81,7 +81,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @synthesize webView = _webView; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; if (self != nil) { @@ -93,7 +93,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE _completionBlock = [block copy]; SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; - _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && state.stage != SPUUpdateStageInformational; + _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && state.stage != SPUUserUpdateStageInformational; [self setShouldCascadeWindows:NO]; } return self; @@ -339,7 +339,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE [self.window setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! } - if (self.state.stage == SPUUpdateStageInformational) { + if (self.state.stage == SPUUserUpdateStageInformational) { [self.installButton setTitle:SULocalizedString(@"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed.")]; [self.installButton setAction:@selector(openInfoURL:)]; } @@ -373,7 +373,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } } - if (self.state.stage == SPUUpdateStageInstalling) { + if (self.state.stage == SPUUserUpdateStageInstalling) { // We're going to be relaunching pretty instantaneously self.installButton.title = SULocalizedString(@"Install and Relaunch", nil); @@ -411,7 +411,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE { return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [self.host name]]; } - else if (self.state.stage == SPUUpdateStageDownloaded || self.state.stage == SPUUpdateStageInstalling) + else if (self.state.stage == SPUUserUpdateStageDownloaded || self.state.stage == SPUUserUpdateStageInstalling) { return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [self.host name]]; } @@ -436,16 +436,16 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We display a different summary depending on if it's an "info-only" item, or a "critical update" item, or if we've already downloaded the update and just need to relaunch NSString *finalString = nil; - if (self.state.stage == SPUUpdateStageInformational) { + if (self.state.stage == SPUUserUpdateStageInformational) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; } else if (self.updateItem.criticalUpdate) { - if (self.state.stage == SPUUpdateStageNotDownloaded) { + if (self.state.stage == SPUUserUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. This is an important update; would you like to download it now?", @"Description text for SUUpdateAlert when the critical update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { finalString = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! This is an important update; would you like to install it and relaunch %1$@ now?", @"Description text for SUUpdateAlert when the critical update has already been downloaded and ready to install."), self.host.name, updateItemVersion]; } } else { - if (self.state.stage == SPUUpdateStageNotDownloaded) { + if (self.state.stage == SPUUserUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", @"Description text for SUUpdateAlert when the update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { finalString = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", @"Description text for SUUpdateAlert when the update has already been downloaded and ready to install."), self.host.name, updateItemVersion]; diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index bd72a9f5..d451c9a1 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -30,7 +30,7 @@ #import "SPUUpdatePermissionRequest.h" #import "SUUpdatePermissionResponse.h" #import "SPUUserDriver.h" -#import "SPUUpdateState.h" +#import "SPUUserUpdateState.h" #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" #import "SPUDownloadData.h" diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 21a785c3..a72f923f 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -133,10 +133,10 @@ }]; } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { switch (state.stage) { - case SPUUpdateStageInformational: + case SPUUserUpdateStageInformational: // Todo: show user interface for this NSLog(@"Found info URL: %@", appcastItem.infoURL); @@ -146,9 +146,9 @@ reply(SPUUserUpdateChoiceDismiss); break; - case SPUUpdateStageNotDownloaded: - case SPUUpdateStageDownloaded: - case SPUUpdateStageInstalling: + case SPUUserUpdateStageNotDownloaded: + case SPUUserUpdateStageDownloaded: + case SPUUserUpdateStageInstalling: [self showUpdateWithAppcastItem:appcastItem reply:reply]; break; } From 88f678ebe694bfb1f0562b872f9eafff6af055aa Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 11:24:32 -0700 Subject: [PATCH 14/29] Remove SPUUserUpdateStageInformational --- Sparkle/SPUUIBasedUpdateDriver.m | 13 ++---- Sparkle/SPUUserDriver.h | 14 +++--- Sparkle/SPUUserUpdateState.h | 3 +- Sparkle/SUUpdateAlert.m | 6 +-- Sparkle/Sparkle.h | 1 - Sparkle/SparkleCore.h | 1 - TestApplication/SUPopUpTitlebarUserDriver.m | 26 +++++------- sparkle-cli/SPUCommandLineUserDriver.m | 47 +++++++++++---------- 8 files changed, 49 insertions(+), 62 deletions(-) diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index ed8f958c..775c01c9 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -170,9 +170,7 @@ id updaterDelegate = self.updaterDelegate; SPUUserUpdateStage stage; - if (updateItem.isInformationOnlyUpdate) { - stage = SPUUserUpdateStageInformational; - } else if (self.resumingDownloadedUpdate) { + if (self.resumingDownloadedUpdate) { stage = SPUUserUpdateStageDownloaded; } else if (self.resumingInstallingUpdate) { stage = SPUUserUpdateStageInstalling; @@ -187,7 +185,7 @@ // Rule out invalid choices SPUUserUpdateChoice validatedChoice; - if (stage == SPUUserUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { + if (updateItem.isInformationOnlyUpdate && userChoice == SPUUserUpdateChoiceInstall) { validatedChoice = SPUUserUpdateChoiceDismiss; } else { validatedChoice = userChoice; @@ -205,9 +203,6 @@ case SPUUserUpdateStageNotDownloaded: [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:NO]; break; - case SPUUserUpdateStageInformational: - assert(false); - break; } break; } @@ -221,7 +216,6 @@ switch (stage) { case SPUUserUpdateStageDownloaded: case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageInformational: // Informational updates can be resumed too, so make sure we check // self.resumingDownloadedUpdate instead of the stage we pass to user driver if (self.resumingDownloadedUpdate) { @@ -241,8 +235,7 @@ case SPUUserUpdateChoiceDismiss: { switch (stage) { case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageInformational: { + case SPUUserUpdateStageNotDownloaded: { [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break; } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 6b6e80af..6bb4259a 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -60,27 +60,29 @@ SU_EXPORT @protocol SPUUserDriver * * @param appcastItem The Appcast Item containing information that reflects the new update. * - * @param state The current state of the update. + * @param state The current state of the user update. * The state.stage values are: * SPUUpdateStateNotDownloaded - Update has not been downloaded yet. * SPUUpdateStateDownloaded - Update has already been downloaded but not started installing yet. * SPUUpdateStateInstalling - Update has been downloaded and already started installing. - * SPUUpdateStateInformational - Update is only informational and has no download. You can direct the user to the infoURL property of the appcastItem in their web browser. Use this to check if an update is informational, instead of using the informationOnlyUpdate property of the appcast item. * * state.userInitiated indicates if the update was initiated by the user or if it was automatically scheduled in the background. - * state.majorUpgrade indicates if the update is a major or paid upgrade. - * state.criticalUpdate indicates if the update is a critical update. + * + * 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. + * appcastItem.majorUpgrade indicates if the update is a major or paid upgrade. + * appcastItem.criticalUpdate indicates if the update is a critical update. * * @param reply * A reply of SPUUserUpdateChoiceInstall begins or resumes downloading or installing the update. - * If the state.stage is SPUUserUpdateStateInstalling, this may send a quit event to the application and relaunch it immediately (in this state, this behaves as a fast "install and Relaunch"). + * If the state.stage is SPUUserUpdateStateInstalling, this may send a quit event to the application and relaunch it immediately (in this state, this behaves as a fast "install and Relaunch"). Do not use this reply if appcastItem.informationOnlyUpdate is YES. * * A reply of SPUUserUpdateChoiceDismiss dismisses the update for the time being. The user may be reminded of the update at a later point. * If the state.stage is SPUUserUpdateStateDownloaded, the downloaded update is kept after dismissing until the next time an update is shown to the user. * If the state.stage is SPUUserUpdateStateInstalling, the installing update is also preserved after dismissing. In this state however, the update will also still be installed after the application is terminated. * * A reply of SPUUserUpdateChoiceSkip skips this particular version and won't notify the user again, unless they initiate an update check themselves. - * If state.majorUpgrade is YES, the major update and any minor updates to that major release are skipped. + * If appcastItem.majorUpgrade is YES, the major update and any future minor updates to that major release are skipped. * If the state.stage is SPUUpdateStateInstalling, the installation is also canceled when the update is skipped. */ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUserUpdateState.h index 0b004ae7..6c41c1e8 100644 --- a/Sparkle/SPUUserUpdateState.h +++ b/Sparkle/SPUUserUpdateState.h @@ -31,8 +31,7 @@ typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { typedef NS_ENUM(NSInteger, SPUUserUpdateStage) { SPUUserUpdateStageNotDownloaded, SPUUserUpdateStageDownloaded, - SPUUserUpdateStageInstalling, - SPUUserUpdateStageInformational + SPUUserUpdateStageInstalling }; SU_EXPORT @interface SPUUserUpdateState : NSObject diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 633676c8..713913ec 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -93,7 +93,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE _completionBlock = [block copy]; SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; - _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && state.stage != SPUUserUpdateStageInformational; + _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && !item.informationOnlyUpdate; [self setShouldCascadeWindows:NO]; } return self; @@ -339,7 +339,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE [self.window setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! } - if (self.state.stage == SPUUserUpdateStageInformational) { + if (self.updateItem.isInformationOnlyUpdate) { [self.installButton setTitle:SULocalizedString(@"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed.")]; [self.installButton setAction:@selector(openInfoURL:)]; } @@ -436,7 +436,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We display a different summary depending on if it's an "info-only" item, or a "critical update" item, or if we've already downloaded the update and just need to relaunch NSString *finalString = nil; - if (self.state.stage == SPUUserUpdateStageInformational) { + if (self.updateItem.isInformationOnlyUpdate) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; } else if (self.updateItem.criticalUpdate) { if (self.state.stage == SPUUserUpdateStageNotDownloaded) { diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index d451c9a1..8ec3e01e 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -30,7 +30,6 @@ #import "SPUUpdatePermissionRequest.h" #import "SUUpdatePermissionResponse.h" #import "SPUUserDriver.h" -#import "SPUUserUpdateState.h" #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" #import "SPUDownloadData.h" diff --git a/Sparkle/SparkleCore.h b/Sparkle/SparkleCore.h index d151ca6f..118672aa 100644 --- a/Sparkle/SparkleCore.h +++ b/Sparkle/SparkleCore.h @@ -29,7 +29,6 @@ #import "SPUUpdatePermissionRequest.h" #import "SUUpdatePermissionResponse.h" #import "SPUUserDriver.h" -#import "SPUUpdateState.h" #import "SPUDownloadData.h" #pragma clang diagnostic pop diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index a72f923f..0775d967 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -135,22 +135,16 @@ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { - switch (state.stage) { - case SPUUserUpdateStageInformational: - // Todo: show user interface for this - NSLog(@"Found info URL: %@", appcastItem.infoURL); - - // Remove UI from user initiated check - [self removeUpdateButton]; - - reply(SPUUserUpdateChoiceDismiss); - - break; - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageInstalling: - [self showUpdateWithAppcastItem:appcastItem reply:reply]; - break; + if (appcastItem.informationOnlyUpdate) { + // Todo: show user interface for this + NSLog(@"Found info URL: %@", appcastItem.infoURL); + + // Remove UI from user initiated check + [self removeUpdateButton]; + + reply(SPUUserUpdateChoiceDismiss); + } else { + [self showUpdateWithAppcastItem:appcastItem reply:reply]; } } diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index dd04d442..8f34027d 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -97,31 +97,32 @@ } } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { - switch (state.stage) { - case SPUUpdateStageNotDownloaded: - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; - reply(SPUUserUpdateChoiceInstall); - break; - case SPUUpdateStageDownloaded: - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; - reply(SPUUserUpdateChoiceInstall); - break; - case SPUUpdateStageInstalling: - if (self.deferInstallation) { - if (self.verbose) { - fprintf(stderr, "Deferring Installation.\n"); - } - reply(SPUUserUpdateChoiceDismiss); - } else { + if (appcastItem.informationOnlyUpdate) { + fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); + reply(SPUUserUpdateChoiceDismiss); + } else { + switch (state.stage) { + case SPUUserUpdateStageNotDownloaded: + [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; reply(SPUUserUpdateChoiceInstall); - } - break; - case SPUUpdateStageInformational: - fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); - reply(SPUUserUpdateChoiceDismiss); - break; + break; + case SPUUserUpdateStageDownloaded: + [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; + reply(SPUUserUpdateChoiceInstall); + break; + case SPUUserUpdateStageInstalling: + if (self.deferInstallation) { + if (self.verbose) { + fprintf(stderr, "Deferring Installation.\n"); + } + reply(SPUUserUpdateChoiceDismiss); + } else { + reply(SPUUserUpdateChoiceInstall); + } + break; + } } } From 5287453cfd71c6bab4f0d9ef232229967f80c8b6 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 11:41:30 -0700 Subject: [PATCH 15/29] Use dot-syntax naming --- Sparkle/SPUAutomaticUpdateDriver.m | 2 +- Sparkle/SUUpdateAlert.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 9fd685fa..7c25b19b 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -136,7 +136,7 @@ - (void)abortUpdateWithError:(NSError *)error { - BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate || self.updateItem.isInformationOnlyUpdate); + BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.criticalUpdate || self.updateItem.isInformationOnlyUpdate); [self.coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error]; } diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 713913ec..7e23df21 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -339,7 +339,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE [self.window setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! } - if (self.updateItem.isInformationOnlyUpdate) { + if (self.updateItem.informationOnlyUpdate) { [self.installButton setTitle:SULocalizedString(@"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed.")]; [self.installButton setAction:@selector(openInfoURL:)]; } @@ -436,7 +436,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We display a different summary depending on if it's an "info-only" item, or a "critical update" item, or if we've already downloaded the update and just need to relaunch NSString *finalString = nil; - if (self.updateItem.isInformationOnlyUpdate) { + if (self.updateItem.informationOnlyUpdate) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; } else if (self.updateItem.criticalUpdate) { if (self.state.stage == SPUUserUpdateStageNotDownloaded) { From 1aadf1b351d85095ecfa1b75d06e95f4252ac369 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 11:57:33 -0700 Subject: [PATCH 16/29] 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 From 1013b2506a2d27c6aa5327d177146e4c1c01857c Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 12:17:43 -0700 Subject: [PATCH 17/29] Remove #warning --- Sparkle/SPUBasicUpdateDriver.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index a03f2e05..94927ba9 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -90,7 +90,6 @@ [self notifyFinishLoadingAppcast]; SUAppcastItem *nonNullUpdateItem = updateItem; -#warning please check this [self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } } From d468757ee1c926af597a4b11a85d8a3616c7a4a2 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 31 May 2021 12:51:09 -0700 Subject: [PATCH 18/29] Revert some unnecessary changes I made --- Sparkle/SPUAutomaticUpdateDriver.m | 3 --- Sparkle/SPUUserUpdateState.h | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 445f2178..c1a9c736 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -21,7 +21,6 @@ @interface SPUAutomaticUpdateDriver () -@property (nonatomic, readonly) SUHost *host; @property (nonatomic, readonly, weak) id updater; @property (nonatomic, readonly, weak) id userDriver; @property (nonatomic, readonly, weak, nullable) id updaterDelegate; @@ -33,7 +32,6 @@ @implementation SPUAutomaticUpdateDriver -@synthesize host = _host; @synthesize updater = _updater; @synthesize userDriver = _userDriver; @synthesize updaterDelegate = _updaterDelegate; @@ -45,7 +43,6 @@ { self = [super init]; if (self != nil) { - _host = host; _updater = updater; // The user driver is only used for a termination callback _userDriver = userDriver; diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUserUpdateState.h index 6c41c1e8..58b59be9 100644 --- a/Sparkle/SPUUserUpdateState.h +++ b/Sparkle/SPUUserUpdateState.h @@ -6,8 +6,8 @@ // Copyright © 2016 Sparkle Project. All rights reserved. // -#ifndef SPUUpdateState_h -#define SPUUpdateState_h +#ifndef SPUUserUpdateState_h +#define SPUUserUpdateState_h #if __has_feature(modules) #if __has_warning("-Watimport-in-framework-header") From fb8a0a02c892543762023473bd4b551079658217 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 20 Jun 2021 20:42:18 -0700 Subject: [PATCH 19/29] Fix typos --- Sparkle/SUAppcastItem.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 331aecaa..9e3af3cd 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -66,9 +66,9 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (readonly, copy) NSDictionary *propertiesDictionary; // Deprecated initializers -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describue your use case."); -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describue your use case."); -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describue your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); @end From 1444561899b7dc6e67d9e6c4ef40349513de4154 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 20 Jun 2021 21:59:05 -0700 Subject: [PATCH 20/29] Add support for selectively choosing what updates are info-only Example: 1.5.0 1.5.1 Means that updating only from versions 1.5.0 and 1.5.1 are shown an informational update (provided there is an info link). Means that updating from any version gets an informational update (provided there is an info link). No presence of this new element falls back to current behavior in Sparkle where an informational update is shown if an enclosure is missing but an info link is provided. --- Sparkle/SPUAppcastItemState.h | 3 ++- Sparkle/SPUAppcastItemState.m | 9 +++++++-- Sparkle/SPUAppcastItemStateResolver.h | 2 +- Sparkle/SPUAppcastItemStateResolver.m | 21 +++++++++++++++++++-- Sparkle/SUAppcast.m | 13 +++++++++++++ Sparkle/SUAppcastItem.m | 21 +++++++++++++++++++-- Sparkle/SUConstants.h | 1 + Sparkle/SUConstants.m | 1 + 8 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Sparkle/SPUAppcastItemState.h b/Sparkle/SPUAppcastItemState.h index 48bccb13..8dcb6e60 100644 --- a/Sparkle/SPUAppcastItemState.h +++ b/Sparkle/SPUAppcastItemState.h @@ -15,10 +15,11 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; -- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK; +- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate informationalUpdate:(BOOL)informationalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK; @property (nonatomic, readonly) BOOL majorUpgrade; @property (nonatomic, readonly) BOOL criticalUpdate; +@property (nonatomic, readonly) BOOL informationalUpdate; @property (nonatomic, readonly) BOOL minimumOperatingSystemVersionIsOK; @property (nonatomic, readonly) BOOL maximumOperatingSystemVersionIsOK; diff --git a/Sparkle/SPUAppcastItemState.m b/Sparkle/SPUAppcastItemState.m index 12df1934..6d6ee1fd 100644 --- a/Sparkle/SPUAppcastItemState.m +++ b/Sparkle/SPUAppcastItemState.m @@ -13,6 +13,7 @@ #define SPUAppcastItemStateMajorUpgradeKey @"SPUAppcastItemStateMajorUpgrade" #define SPUAppcastItemStateCriticalUpdateKey @"SPUAppcastItemStateCriticalUpdate" +#define SPUAppcastItemStateInformationalUpdateKey @"SPUAppcastItemStateInformationalUpdate" #define SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey @"SPUAppcastItemStateMinimumOperatingSystemVersionIsOK" #define SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey @"SPUAppcastItemStateMaximumOperatingSystemVersionIsOK" @@ -23,15 +24,17 @@ @synthesize majorUpgrade = _majorUpgrade; @synthesize criticalUpdate = _criticalUpdate; +@synthesize informationalUpdate = _informationalUpdate; @synthesize minimumOperatingSystemVersionIsOK = _minimumOperatingSystemVersionIsOK; @synthesize maximumOperatingSystemVersionIsOK = _maximumOperatingSystemVersionIsOK; -- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK +- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate informationalUpdate:(BOOL)informationalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK { self = [super init]; if (self != nil) { _majorUpgrade = majorUpgrade; _criticalUpdate = criticalUpdate; + _informationalUpdate = informationalUpdate; _minimumOperatingSystemVersionIsOK = minimumOperatingSystemVersionIsOK; _maximumOperatingSystemVersionIsOK = maximumOperatingSystemVersionIsOK; } @@ -47,6 +50,7 @@ { [encoder encodeBool:self.majorUpgrade forKey:SPUAppcastItemStateMajorUpgradeKey]; [encoder encodeBool:self.criticalUpdate forKey:SPUAppcastItemStateCriticalUpdateKey]; + [encoder encodeBool:self.informationalUpdate forKey:SPUAppcastItemStateInformationalUpdateKey]; [encoder encodeBool:self.minimumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey]; [encoder encodeBool:self.maximumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey]; } @@ -55,10 +59,11 @@ { BOOL majorUpgrade = [decoder decodeBoolForKey:SPUAppcastItemStateMajorUpgradeKey]; BOOL criticalUpdate = [decoder decodeBoolForKey:SPUAppcastItemStateCriticalUpdateKey]; + BOOL informationalUpdate = [decoder decodeBoolForKey:SPUAppcastItemStateInformationalUpdateKey]; BOOL minimumOperatingSystemVersionIsOK = [decoder decodeBoolForKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey]; BOOL maximumOperatingSystemVersionIsOK = [decoder decodeBoolForKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey]; - return [self initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; + return [self initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate informationalUpdate:informationalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; } @end diff --git a/Sparkle/SPUAppcastItemStateResolver.h b/Sparkle/SPUAppcastItemStateResolver.h index 4851a22b..cb5c9a15 100644 --- a/Sparkle/SPUAppcastItemStateResolver.h +++ b/Sparkle/SPUAppcastItemStateResolver.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator; -- (SPUAppcastItemState *)resolveStateWithMinimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary; +- (SPUAppcastItemState *)resolveStateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions minimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary; + (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator; diff --git a/Sparkle/SPUAppcastItemStateResolver.m b/Sparkle/SPUAppcastItemStateResolver.m index 5a61c888..cb7b0f20 100644 --- a/Sparkle/SPUAppcastItemStateResolver.m +++ b/Sparkle/SPUAppcastItemStateResolver.m @@ -86,8 +86,25 @@ return ([self.applicationVersionComparator compareVersion:self.hostVersion toVersion:criticalVersion] == NSOrderedAscending); } -- (SPUAppcastItemState *)resolveStateWithMinimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary +- (BOOL)isInformationalUpdateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions { + if (informationalUpdateVersions == nil) { + return NO; + } + + // Informational only update regardless of version the app is updating from + if (informationalUpdateVersions.count == 0) { + return YES; + } + + // Informational update only for a set of host versions we're updating from + return [informationalUpdateVersions containsObject:self.hostVersion]; +} + +- (SPUAppcastItemState *)resolveStateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions minimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary +{ + BOOL informationalUpdate = [self isInformationalUpdateWithInformationalUpdateVersions:informationalUpdateVersions]; + BOOL minimumOperatingSystemVersionIsOK = [self isMinimumOperatingSystemVersionOK:minimumOperatingSystemVersion]; BOOL maximumOperatingSystemVersionIsOK = [self isMaximumOperatingSystemVersionOK:maximumOperatingSystemVersion];; @@ -96,7 +113,7 @@ BOOL criticalUpdate = [self isCriticalUpdateWithCriticalUpdateDictionary:criticalUpdateDictionary]; - return [[SPUAppcastItemState alloc] initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; + return [[SPUAppcastItemState alloc] initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate informationalUpdate:informationalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; } @end diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 3c977c8e..c3d927cc 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -154,6 +154,19 @@ } } [dict setObject:tags forKey:name]; + } + else if ([name isEqualToString:SUAppcastElementInformationalUpdate]) { + NSMutableSet *informationalUpdateVersions = [NSMutableSet set]; + NSEnumerator *childEnum = [[node children] objectEnumerator]; + for (NSXMLNode *child in childEnum) { + if ([child.name isEqualToString:SUAppcastAttributeVersion]) { + NSString *version = child.stringValue; + if (version != nil) { + [informationalUpdateVersions addObject:version]; + } + } + } + [dict setObject:[informationalUpdateVersions copy] forKey:name]; } else if (name != nil) { // add all other values as strings diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index e3001c6e..f030bc60 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -44,6 +44,9 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; // Indicates if we have any critical information. Used as a fallback if state is nil @property (nonatomic, readonly) BOOL hasCriticalInformation; +// Indicates the versions we update from that are informational-only +@property (nonatomic, readonly, nullable) NSSet *informationalUpdateVersions; + @end @implementation SUAppcastItem @@ -68,6 +71,7 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; @synthesize phasedRolloutInterval = _phasedRolloutInterval; @synthesize state = _state; @synthesize hasCriticalInformation = _hasCriticalInformation; +@synthesize informationalUpdateVersions = _informationalUpdateVersions; + (BOOL)supportsSecureCoding { @@ -266,7 +270,11 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; - (BOOL)isInformationOnlyUpdate { - return self.infoURL && !self.fileURL; + if (self.state != nil) { + return self.state.informationalUpdate; + } else { + return (self.informationalUpdateVersions != nil && self.informationalUpdateVersions.count == 0); + } } // Used for making delta items @@ -362,6 +370,15 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; } return nil; } + + if (theInfoURL != nil) { + // If enclosure doesn't exist, the update must be an informational update + // Otherwise check presence of informational update element + _informationalUpdateVersions = (enclosure != nil) ? [dict objectForKey:SUAppcastElementInformationalUpdate] : [NSSet set]; + } else { + // Not an informational update + _informationalUpdateVersions = nil; + } NSString *enclosureURLString = [enclosure objectForKey:SURSSAttributeURL]; if (!enclosureURLString && !theInfoURL) { @@ -415,7 +432,7 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; _hasCriticalInformation = (criticalUpdateDictionary != nil); - _state = [(SPUAppcastItemStateResolver * _Nonnull)stateResolver resolveStateWithMinimumOperatingSystemVersion:_minimumSystemVersion maximumOperatingSystemVersion:_maximumSystemVersion minimumAutoupdateVersion:_minimumAutoupdateVersion criticalUpdateDictionary:criticalUpdateDictionary]; + _state = [(SPUAppcastItemStateResolver * _Nonnull)stateResolver resolveStateWithInformationalUpdateVersions:_informationalUpdateVersions minimumOperatingSystemVersion:_minimumSystemVersion maximumOperatingSystemVersion:_maximumSystemVersion minimumAutoupdateVersion:_minimumAutoupdateVersion criticalUpdateDictionary:criticalUpdateDictionary]; } else { // Note state still may be nil if a deprecated initializer is used _state = resolvedState; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 46327f0c..a1e65b66 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -85,6 +85,7 @@ extern NSString *const SUAppcastElementMaximumSystemVersion; extern NSString *const SUAppcastElementReleaseNotesLink; extern NSString *const SUAppcastElementTags; extern NSString *const SUAppcastElementPhasedRolloutInterval; +extern NSString *const SUAppcastElementInformationalUpdate; extern NSString *const SURSSAttributeURL; extern NSString *const SURSSAttributeLength; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 94a4fda4..0a60324e 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -79,6 +79,7 @@ NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVe NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink"; NSString *const SUAppcastElementTags = @"sparkle:tags"; NSString *const SUAppcastElementPhasedRolloutInterval = @"sparkle:phasedRolloutInterval"; +NSString *const SUAppcastElementInformationalUpdate = @"sparkle:informationalUpdate"; NSString *const SURSSAttributeURL = @"url"; NSString *const SURSSAttributeLength = @"length"; From da30373a30ebd8fa1f45500b1e6d85b5fd243ca2 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 20 Jun 2021 23:10:20 -0700 Subject: [PATCH 21/29] Clarify informationOnlyUpdate description in user driver docs --- Sparkle/SPUUserDriver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 06853f0d..c8086eb5 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -69,7 +69,7 @@ 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 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.informationOnlyUpdate indicates if the update is only informational and should not be downloaded. 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. * From 686fd05fce33c2a6e1f9d77eb0d232d293ff508d Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 20 Jun 2021 23:11:02 -0700 Subject: [PATCH 22/29] Add tests for informational only updates --- Sparkle.xcodeproj/project.pbxproj | 4 ++ Tests/Resources/testappcast_info_updates.xml | 52 ++++++++++++++++ Tests/SUAppcastTest.swift | 63 ++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 Tests/Resources/testappcast_info_updates.xml diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 69ef9330..45337eed 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -161,6 +161,7 @@ 721D8A811D498B9B0032E472 /* Updater.app in Copy Tools */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 721D8A861D4ADFEB0032E472 /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; }; 721D8A871D4C5BF10032E472 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; + 722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */ = {isa = PBXBuildFile; fileRef = 722545B526805FF80036465C /* testappcast_info_updates.xml */; }; 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */; }; 7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B71C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h */; }; 7229E1BA1C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7229E1B81C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m */; }; @@ -957,6 +958,7 @@ 722194521D3BFEB7004C34FF /* SUInstallerAgentInitiationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SUInstallerAgentInitiationProtocol.h; path = Sparkle/InstallerProgress/SUInstallerAgentInitiationProtocol.h; sourceTree = SOURCE_ROOT; }; 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; + 722545B526805FF80036465C /* testappcast_info_updates.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_info_updates.xml; sourceTree = ""; }; 722589B51E0A24B9005EA0B9 /* Security.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Security.md; sourceTree = ""; }; 722589B61E0A24C6005EA0B9 /* Design Practices.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Design Practices.md"; sourceTree = ""; }; 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdateDriver.h; sourceTree = ""; }; @@ -1683,6 +1685,7 @@ 5AF6C74E1AEA46D10014A3AB /* test.pkg */, 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */, 725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */, + 722545B526805FF80036465C /* testappcast_info_updates.xml */, 5F1510A11C96E591006E1629 /* testnamespaces.xml */, FA30773C24CBC295007BA37D /* testlocalizedreleasenotesappcast.xml */, 5A5DD41B249F0F4B0045EB3E /* test-relative-urls.xml */, @@ -2944,6 +2947,7 @@ 5AF6C74F1AEA46D10014A3AB /* test.pkg in Resources */, 5AD0FA7F1C73F2E2004BCEFF /* testappcast.xml in Resources */, FA30773D24CBC295007BA37D /* testlocalizedreleasenotesappcast.xml in Resources */, + 722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */, 5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/Resources/testappcast_info_updates.xml b/Tests/Resources/testappcast_info_updates.xml new file mode 100644 index 00000000..e1e5074e --- /dev/null +++ b/Tests/Resources/testappcast_info_updates.xml @@ -0,0 +1,52 @@ + + + + For unit test only + + + Version 2.0 + desc + Sat, 26 Jul 2014 15:20:11 +0000 + + + + + Version 3.0 + + + 2.5 + 2.4 + + http://sparkle-project.org + + + + Version 4.0 + Sat, 26 Jul 2014 15:20:13 +0000 + + + http://sparkle-project.org + + + + + + + + + Version 5.0 + 5.0 + http://sparkle-project.org + + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 640a7177..d3c25fd9 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -116,6 +116,69 @@ class SUAppcastTest: XCTestCase { } } + func testInformationalUpdateVersions() { + let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_info_updates", withExtension: "xml")! + + do { + let testData = try Data(contentsOf: testURL) + + let versionComparator = SUStandardVersionComparator.default() + + // Test informational updates from version 1.0 + do { + let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertFalse(appcast.items[0].isInformationOnlyUpdate) + XCTAssertFalse(appcast.items[1].isInformationOnlyUpdate) + XCTAssertTrue(appcast.items[2].isInformationOnlyUpdate) + XCTAssertTrue(appcast.items[3].isInformationOnlyUpdate) + + // Test delta updates inheriting informational only updates + do { + let deltaUpdate = appcast.items[2].deltaUpdates!["2.0"] as! SUAppcastItem + XCTAssertTrue(deltaUpdate.isInformationOnlyUpdate) + } + } + + // Test informational updates from version 2.4 + do { + let hostVersion = "2.4" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertTrue(appcast.items[1].isInformationOnlyUpdate) + } + + // Test informational updates from version 2.5 + do { + let hostVersion = "2.5" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertTrue(appcast.items[1].isInformationOnlyUpdate) + } + + // Test informational updates from version 2.6 + do { + let hostVersion = "2.6" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertFalse(appcast.items[1].isInformationOnlyUpdate) + } + + } catch let err as NSError { + NSLog("%@", err) + XCTFail(err.localizedDescription) + } + } + func testMinimumAutoupdateVersion() { let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_minimumAutoupdateVersion", withExtension: "xml")! From 31f6f512e103e704d30447297c741ed2c0579e99 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 20 Jun 2021 23:55:40 -0700 Subject: [PATCH 23/29] Export SUAppcastItem designated initializer to PrivateHeaders Clients can use this header if they need to, but they should first talk to us / explore other avenues. --- Sparkle.xcodeproj/project.pbxproj | 10 ++++---- Sparkle/SPUAppcastItemStateResolver+Private.h | 24 +++++++++++++++++++ Sparkle/SPUAppcastItemStateResolver.h | 15 ++++++++---- Sparkle/SPUAppcastItemStateResolver.m | 1 + Sparkle/SUAppcastDriver.m | 1 + Sparkle/SUAppcastItem+Private.h | 9 ++++--- Sparkle/SUAppcastItem.m | 1 + 7 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 Sparkle/SPUAppcastItemStateResolver+Private.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 45337eed..91729ac5 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -365,7 +365,7 @@ 72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */; }; 72EB87EB1CB8859100C37F42 /* Updater.app in Copy Tools */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 72EB87EC1CB8887E00C37F42 /* SUStatus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BD8136EF00C00649790 /* SUStatus.xib */; }; - 72EF30BE2675CF38008CE987 /* SPUAppcastItemStateResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30BA2675CF38008CE987 /* SPUAppcastItemStateResolver.h */; }; + 72EF30BE2675CF38008CE987 /* SPUAppcastItemStateResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30BA2675CF38008CE987 /* SPUAppcastItemStateResolver.h */; settings = {ATTRIBUTES = (Private, ); }; }; 72EF30BF2675CF38008CE987 /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */; }; 72EF30C02675CF38008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; }; 72EF30C12675CF38008CE987 /* SPUAppcastItemState.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30BD2675CF38008CE987 /* SPUAppcastItemState.h */; }; @@ -373,7 +373,7 @@ 72EF30C32675CF67008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; }; 72EF30C42675CFA1008CE987 /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */; }; 72EF30C52675CFA1008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; }; - 72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */; }; + 72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 72F94F581CC44DE1002DEE68 /* SPUXPCServiceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F94F561CC44DE1002DEE68 /* SPUXPCServiceInfo.h */; }; 72F94F591CC44DE1002DEE68 /* SPUXPCServiceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F94F571CC44DE1002DEE68 /* SPUXPCServiceInfo.m */; }; 72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */; }; @@ -959,6 +959,7 @@ 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; 722545B526805FF80036465C /* testappcast_info_updates.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_info_updates.xml; sourceTree = ""; }; + 722545B72680699D0036465C /* SPUAppcastItemStateResolver+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUAppcastItemStateResolver+Private.h"; sourceTree = ""; }; 722589B51E0A24B9005EA0B9 /* Security.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Security.md; sourceTree = ""; }; 722589B61E0A24C6005EA0B9 /* Design Practices.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Design Practices.md"; sourceTree = ""; }; 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdateDriver.h; sourceTree = ""; }; @@ -1789,6 +1790,7 @@ 72EF30BD2675CF38008CE987 /* SPUAppcastItemState.h */, 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */, 72EF30BA2675CF38008CE987 /* SPUAppcastItemStateResolver.h */, + 722545B72680699D0036465C /* SPUAppcastItemStateResolver+Private.h */, 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */, 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */, 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */, @@ -2332,18 +2334,18 @@ 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */, 725CB95A1C7121830064365A /* SPUStandardUserDriver.h in Headers */, 726E4A371C89116000C57C6A /* SPUStandardUserDriverDelegate.h in Headers */, + 72EF30BE2675CF38008CE987 /* SPUAppcastItemStateResolver.h in Headers */, + 72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */, 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */, 72B767DA1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.h in Headers */, 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */, 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */, 61B5F8ED09C4CE3C00B25A18 /* SPUUpdater.h in Headers */, - 72EF30BE2675CF38008CE987 /* SPUAppcastItemStateResolver.h in Headers */, 720E217B1D0D00BF003A311C /* SPUUpdaterCycle.h in Headers */, 72F9EC481D5EA904004AC8B6 /* SPUUpdaterDelegate.h in Headers */, 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */, 72F9EC3F1D5E823F004AC8B6 /* SPUUpdaterTimer.h in Headers */, 7269E494264798200088C213 /* SPUSkippedUpdate.h in Headers */, - 72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */, 723ABFC4259D4CB300BDB4FA /* SUWKWebView.h in Headers */, 7293A1AE1CEE933800B957A7 /* SPUURLRequest.h in Headers */, 725CB9571C7120410064365A /* SPUUserDriver.h in Headers */, diff --git a/Sparkle/SPUAppcastItemStateResolver+Private.h b/Sparkle/SPUAppcastItemStateResolver+Private.h new file mode 100644 index 00000000..4b1ec78b --- /dev/null +++ b/Sparkle/SPUAppcastItemStateResolver+Private.h @@ -0,0 +1,24 @@ +// +// SPUAppcastItemStateResolver+Private.h +// Sparkle +// +// Created by Mayur Pawashe on 6/20/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#ifndef SPUAppcastItemStateResolver_Private_h +#define SPUAppcastItemStateResolver_Private_h + +NS_ASSUME_NONNULL_BEGIN + +@interface SPUAppcastItemStateResolver () + +- (SPUAppcastItemState *)resolveStateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions minimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary; + ++ (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUAppcastItemStateResolver_Private_h */ diff --git a/Sparkle/SPUAppcastItemStateResolver.h b/Sparkle/SPUAppcastItemStateResolver.h index cb5c9a15..1accdde5 100644 --- a/Sparkle/SPUAppcastItemStateResolver.h +++ b/Sparkle/SPUAppcastItemStateResolver.h @@ -6,7 +6,16 @@ // Copyright © 2021 Sparkle Project. All rights reserved. // +#if __has_feature(modules) +#if __has_warning("-Watimport-in-framework-header") +#pragma clang diagnostic ignored "-Watimport-in-framework-header" +#endif +@import Foundation; +#else #import +#endif + +#import NS_ASSUME_NONNULL_BEGIN @@ -14,14 +23,10 @@ NS_ASSUME_NONNULL_BEGIN @protocol SUVersionComparison; // Class used to resolve Appcast Item properties that rely on external factors such as a host -@interface SPUAppcastItemStateResolver : NSObject +SU_EXPORT @interface SPUAppcastItemStateResolver : NSObject - (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator; -- (SPUAppcastItemState *)resolveStateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions minimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary; - -+ (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator; - @end NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemStateResolver.m b/Sparkle/SPUAppcastItemStateResolver.m index cb7b0f20..0ce4f90c 100644 --- a/Sparkle/SPUAppcastItemStateResolver.m +++ b/Sparkle/SPUAppcastItemStateResolver.m @@ -7,6 +7,7 @@ // #import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemStateResolver+Private.h" #import "SPUAppcastItemState.h" #import "SUVersionComparisonProtocol.h" #import "SUStandardVersionComparator.h" diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 7dc5c806..82834df5 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -25,6 +25,7 @@ #import "SULocalizations.h" #import "SUErrors.h" #import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemStateResolver+Private.h" #import "SPUAppcastItemState.h" diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h index 5073cf3e..e13e15c1 100644 --- a/Sparkle/SUAppcastItem+Private.h +++ b/Sparkle/SUAppcastItem+Private.h @@ -18,15 +18,18 @@ #import #endif -#import "SUAppcastItem.h" - NS_ASSUME_NONNULL_BEGIN @class SPUAppcastItemStateResolver; @interface SUAppcastItem (Private) -// Initializes with data from a dictionary provided by the RSS class and state resolver +/*! + Initializes with data from a dictionary provided by the RSS class and state resolver + + This initializer method is intended to be marked "private" and discouraged from public usage. + This method is available however. Talk to us to describe your use case and if you need to construct appcast items yourself. + */ - (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; @end diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index f030bc60..32ebb63a 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -14,6 +14,7 @@ #import "SPUInstallationType.h" #import "SPUAppcastItemState.h" #import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemStateResolver+Private.h" #include "AppKitPrevention.h" From 6e3cd6b313836aa8627c9e55591b6a42e211549f Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 21 Jun 2021 00:11:06 -0700 Subject: [PATCH 24/29] Mark init methods as unavailable --- Sparkle/SPUAppcastItemStateResolver.h | 2 ++ Sparkle/SUAppcastItem.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Sparkle/SPUAppcastItemStateResolver.h b/Sparkle/SPUAppcastItemStateResolver.h index 1accdde5..e05779f7 100644 --- a/Sparkle/SPUAppcastItemStateResolver.h +++ b/Sparkle/SPUAppcastItemStateResolver.h @@ -25,6 +25,8 @@ NS_ASSUME_NONNULL_BEGIN // Class used to resolve Appcast Item properties that rely on external factors such as a host SU_EXPORT @interface SPUAppcastItemStateResolver : NSObject +- (instancetype)init NS_UNAVAILABLE; + - (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator; @end diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 9e3af3cd..453c650c 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -65,6 +65,8 @@ SU_EXPORT @interface SUAppcastItem : NSObject // Returns the dictionary representing the appcast item; this might be useful later for extensions. @property (readonly, copy) NSDictionary *propertiesDictionary; +- (instancetype)init NS_UNAVAILABLE; + // Deprecated initializers - (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); - (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); From 25e0de59887d6cbb5a3f5ca9061e76ef6d6bbad0 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 25 Jun 2021 22:17:29 -0700 Subject: [PATCH 25/29] Fix analyzer warnings --- Configurations/ed25519-Shared.xcconfig | 3 +++ Sparkle/Base.lproj/Sparkle.strings | 4 ++++ Sparkle/SPUAutomaticUpdateDriver.m | 2 +- Sparkle/SPUBasicUpdateDriver.h | 2 +- Sparkle/SPUBasicUpdateDriver.m | 6 +++--- Sparkle/SPUCoreBasedUpdateDriver.h | 4 ++-- Sparkle/SPUCoreBasedUpdateDriver.m | 6 +++--- Sparkle/SPUDownloadDriver.m | 2 +- Sparkle/SPUInformationalUpdate.h | 2 +- Sparkle/SPUInformationalUpdate.m | 2 +- Sparkle/SPUProbingUpdateDriver.m | 2 +- Sparkle/SPUStandardUpdaterController.m | 6 +++--- Sparkle/SPUUIBasedUpdateDriver.m | 2 +- Sparkle/SUAppcastDriver.h | 2 +- Sparkle/SUHost.m | 4 ++-- 15 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Configurations/ed25519-Shared.xcconfig b/Configurations/ed25519-Shared.xcconfig index 91faa52d..22d08a7d 100644 --- a/Configurations/ed25519-Shared.xcconfig +++ b/Configurations/ed25519-Shared.xcconfig @@ -12,3 +12,6 @@ ALWAYS_SEARCH_USER_PATHS = NO // Disable Warnings - this is a third-party project, and we'll trust that the maintainers know what they're doing. WARNING_CFLAGS = $(inherited) -Wno-cast-qual -Wno-conversion -Wno-sign-conversion + +// Disable dead stores analyzer warning +CLANG_ANALYZER_DEADCODE_DEADSTORES = NO diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 4b305e80..86423b2a 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -66,6 +66,10 @@ "An important update to %@ is ready to install" = "An important update to %@ is ready to install"; +"Unable to Check For Updates" = "Unable to Check For Updates"; + +"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version" = "The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version"; + /* the unit for bytes */ "B" = "B"; diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 90240adb..34ee64e5 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -83,7 +83,7 @@ SULog(SULogLevelError, @"Error: resumeDownloadedUpdate:completion: called on SPUAutomaticUpdateDriver"); } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { self.updateItem = updateItem; diff --git a/Sparkle/SPUBasicUpdateDriver.h b/Sparkle/SPUBasicUpdateDriver.h index afe99e8d..f4d791d3 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 * _Nullable)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain; - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index c0b2459a..6443cd9b 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -79,7 +79,7 @@ } } -- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem *)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain +- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain { if (updateItem == nil) { [self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]]; @@ -137,7 +137,7 @@ } } -- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain +- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain { if (!self.aborted) { [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -152,7 +152,7 @@ } } -- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate { [self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem preventsAutoupdate:preventsAutoupdate systemDomain:nil]; } diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 85805166..f8789ea4 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 * _Nullable)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; - (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 * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate; - (void)extractDownloadedUpdate; diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 551fd2c2..75381ee9 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -32,7 +32,7 @@ @property (nonatomic, readonly) SPUInstallerDriver *installerDriver; @property (nonatomic, weak, readonly) id delegate; @property (nonatomic) SUAppcastItem *updateItem; -@property (nonatomic) SUAppcastItem *secondaryUpdateItem; +@property (nonatomic, nullable) SUAppcastItem *secondaryUpdateItem; @property (nonatomic) id resumableUpdate; @property (nonatomic) SPUDownloadedUpdate *downloadedUpdateForRemoval; @@ -149,7 +149,7 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain { self.updateItem = updateItem; self.secondaryUpdateItem = secondaryUpdateItem; @@ -225,7 +225,7 @@ [self extractUpdate:downloadedUpdate]; } -- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; } diff --git a/Sparkle/SPUDownloadDriver.m b/Sparkle/SPUDownloadDriver.m index 46c449a2..b34bdc32 100644 --- a/Sparkle/SPUDownloadDriver.m +++ b/Sparkle/SPUDownloadDriver.m @@ -28,7 +28,7 @@ @property (nonatomic) id downloader; @property (nonatomic) NSXPCConnection *connection; @property (nonatomic, readonly) SUAppcastItem *updateItem; -@property (nonatomic, readonly) SUAppcastItem *secondaryUpdateItem; +@property (nonatomic, readonly, nullable) SUAppcastItem *secondaryUpdateItem; @property (nonatomic, readonly) SUHost *host; @property (nonatomic, copy) NSString *temporaryDirectory; @property (nonatomic, copy) NSString *downloadName; diff --git a/Sparkle/SPUInformationalUpdate.h b/Sparkle/SPUInformationalUpdate.h index 0d54f99d..9006e9b4 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 * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate; @end diff --git a/Sparkle/SPUInformationalUpdate.m b/Sparkle/SPUInformationalUpdate.m index e9eec62f..07de3556 100644 --- a/Sparkle/SPUInformationalUpdate.m +++ b/Sparkle/SPUInformationalUpdate.m @@ -19,7 +19,7 @@ @synthesize secondaryUpdateItem = _secondaryUpdateItem; @synthesize preventsAutoupdate = _preventsAutoupdate; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { self = [super init]; if (self != nil) { diff --git a/Sparkle/SPUProbingUpdateDriver.m b/Sparkle/SPUProbingUpdateDriver.m index 71257a36..288ee506 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 * _Nullable)__unused secondaryAppcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate systemDomain:(NSNumber * _Nullable)__unused systemDomain { // Stop as soon as we have an answer [self abortUpdate]; diff --git a/Sparkle/SPUStandardUpdaterController.m b/Sparkle/SPUStandardUpdaterController.m index c8adff8a..03488d51 100644 --- a/Sparkle/SPUStandardUpdaterController.m +++ b/Sparkle/SPUStandardUpdaterController.m @@ -14,6 +14,7 @@ #import "SPUStandardUserDriver.h" #import "SUConstants.h" #import "SULog.h" +#import "SULocalizations.h" #import static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; @@ -76,9 +77,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // Delay the alert four seconds so it doesn't show RIGHT as the app launches, but also doesn't interrupt the user once they really get to work. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSAlert *alert = [[NSAlert alloc] init]; - alert.messageText = @"Unable to Check For Updates"; - alert.informativeText = @"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version."; - [alert addButtonWithTitle:@"OK"]; + alert.messageText = SULocalizedString(@"Unable to Check For Updates", nil); + alert.informativeText = SULocalizedString(@"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version.", nil); [alert runModal]; }); } diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index dc2ce766..d11cfa99 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -170,7 +170,7 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { if (self.userInitiated) { [SPUSkippedUpdate clearSkippedUpdateForHost:self.host]; diff --git a/Sparkle/SUAppcastDriver.h b/Sparkle/SUAppcastDriver.h index cc142d72..0ef38428 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 * _Nullable)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; - (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult passesMinOSVersion:(BOOL)passesMinOSVersion passesMaxOSVersion:(BOOL)passesMaxOSVersion; @end diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index c3da0893..518039bf 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -93,12 +93,12 @@ NS_ASSUME_NONNULL_BEGIN return [self isValidVersion:[self _version]]; } -- (BOOL)isValidVersion:(NSString *)version +- (BOOL)isValidVersion:(NSString * _Nullable)version { return (version != nil && version.length != 0); } -- (NSString *)_version +- (NSString * _Nullable)_version { NSString *version = [self objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; return ([self isValidVersion:version] ? version : nil); From 3d8e00eecdd2c3e101e324cd4844c3c231576017 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 25 Jun 2021 22:26:52 -0700 Subject: [PATCH 26/29] Annotate SUAppcastItem initializers as nullable Also mark -init as unavailable. --- Sparkle/SUAppcastItem.h | 6 ++++-- Sparkle/SUAppcastItem.m | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index b1fce84d..6511c6de 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -60,9 +60,11 @@ SU_EXPORT @interface SUAppcastItem : NSObject // Returns the dictionary representing the appcast item; this might be useful later for extensions. @property (readonly, copy) NSDictionary *propertiesDictionary; +- (instancetype)init NS_UNAVAILABLE; + // Initializes with data from a dictionary provided by the RSS class. -- (instancetype)initWithDictionary:(NSDictionary *)dict; -- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict; +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; - (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; @end diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 519ff1c7..2874a7a6 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -214,12 +214,12 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT return self.infoURL && !self.fileURL; } -- (instancetype)initWithDictionary:(NSDictionary *)dict +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict { return [self initWithDictionary:dict relativeToURL:nil failureReason:nil]; } -- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString *__autoreleasing *)error +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString *__autoreleasing *)error { return [self initWithDictionary:dict relativeToURL:nil failureReason:error]; } From 50df5ed4382ef59245c90116657a907c638a6b69 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 01:21:14 -0700 Subject: [PATCH 27/29] Retrieve critical update info even if stateResolver == nil --- Sparkle/SUAppcastItem.m | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 32ebb63a..036d2d09 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -279,7 +279,7 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; } // Used for making delta items -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL state:(SPUAppcastItemState *)state +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL state:(SPUAppcastItemState * _Nullable)state { return [self initWithDictionary:dict relativeToURL:nil stateResolver:nil resolvedState:state failureReason:nil]; } @@ -417,22 +417,24 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; _maximumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMaximumSystemVersion] copy]; _minimumAutoupdateVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumAutoupdateVersion] copy]; + // Grab critical update information + NSDictionary * _Nullable criticalUpdateDictionaryFromAppcast = (NSDictionary *)[dict objectForKey:SUAppcastElementCriticalUpdate]; + NSArray *tags = [dict objectForKey:SUAppcastElementTags]; + + NSDictionary * _Nullable criticalUpdateDictionary; + if (criticalUpdateDictionaryFromAppcast != nil) { + criticalUpdateDictionary = criticalUpdateDictionaryFromAppcast; + } else if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { + // Legacy path where critical update used to be a tag without a specified version + criticalUpdateDictionary = @{}; + } else { + // No critical info present + criticalUpdateDictionary = nil; + } + + _hasCriticalInformation = (criticalUpdateDictionary != nil); + if (stateResolver != nil) { - NSDictionary * _Nullable criticalUpdateDictionaryFromAppcast = (NSDictionary *)[dict objectForKey:SUAppcastElementCriticalUpdate]; - NSArray *tags = [dict objectForKey:SUAppcastElementTags]; - - NSDictionary * _Nullable criticalUpdateDictionary; - if (criticalUpdateDictionaryFromAppcast != nil) { - criticalUpdateDictionary = criticalUpdateDictionaryFromAppcast; - } else if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { - // Legacy path where critical update used to be a tag without a specified version - criticalUpdateDictionary = @{}; - } else { - criticalUpdateDictionary = nil; - } - - _hasCriticalInformation = (criticalUpdateDictionary != nil); - _state = [(SPUAppcastItemStateResolver * _Nonnull)stateResolver resolveStateWithInformationalUpdateVersions:_informationalUpdateVersions minimumOperatingSystemVersion:_minimumSystemVersion maximumOperatingSystemVersion:_maximumSystemVersion minimumAutoupdateVersion:_minimumAutoupdateVersion criticalUpdateDictionary:criticalUpdateDictionary]; } else { // Note state still may be nil if a deprecated initializer is used From 4780cfccd504f5af5788473ec111e70b5e95a724 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 01:36:54 -0700 Subject: [PATCH 28/29] Reword initializer deprecation messages --- Sparkle/SUAppcastItem.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 453c650c..4d3efba1 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -68,9 +68,9 @@ SU_EXPORT @interface SUAppcastItem : NSObject - (instancetype)init NS_UNAVAILABLE; // Deprecated initializers -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Extended properties that depend on the system or application version are not supported when used with this deprecated initializer. Please adopt supported APIs instead or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case."); @end From ba5d895e8f2428af9be223efb8b01d416ff3a66e Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 10:05:25 -0700 Subject: [PATCH 29/29] Document where to find SPUAppcastItemStateResolver --- Sparkle/SPUAppcastItemStateResolver.h | 5 ++++- Sparkle/SUAppcastItem+Private.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sparkle/SPUAppcastItemStateResolver.h b/Sparkle/SPUAppcastItemStateResolver.h index e05779f7..d80f7b96 100644 --- a/Sparkle/SPUAppcastItemStateResolver.h +++ b/Sparkle/SPUAppcastItemStateResolver.h @@ -22,7 +22,10 @@ NS_ASSUME_NONNULL_BEGIN @class SUStandardVersionComparator, SPUAppcastItemState; @protocol SUVersionComparison; -// Class used to resolve Appcast Item properties that rely on external factors such as a host +/*! + Private exposed class used to resolve Appcast Item properties that rely on external factors such as a host. + This resolver is used for constructing appcast items. + */ SU_EXPORT @interface SPUAppcastItemStateResolver : NSObject - (instancetype)init NS_UNAVAILABLE; diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h index e13e15c1..c7db2590 100644 --- a/Sparkle/SUAppcastItem+Private.h +++ b/Sparkle/SUAppcastItem+Private.h @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN +// Available in SPUAppcastItemStateResolver.h (a private exposed header) @class SPUAppcastItemStateResolver; @interface SUAppcastItem (Private)