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