From 6d6cc2d05281302103d44455a256a2178cc67f27 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 19:30:44 -0700 Subject: [PATCH 01/17] Add support for skipping major and minor updates separately --- Sparkle.xcodeproj/project.pbxproj | 12 +++ Sparkle/SPUSkippedUpdate.h | 28 +++++++ Sparkle/SPUSkippedUpdate.m | 123 ++++++++++++++++++++++++++++++ Sparkle/SPUUIBasedUpdateDriver.m | 11 +-- Sparkle/SUAppcastDriver.m | 44 +++++++---- 5 files changed, 200 insertions(+), 18 deletions(-) create mode 100644 Sparkle/SPUSkippedUpdate.h create mode 100644 Sparkle/SPUSkippedUpdate.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index fcf6c1ee..97b9c4e2 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -284,6 +284,10 @@ 7267E5F91D3D92DA00D1BF90 /* Autoupdate in Copy Tools */ = {isa = PBXBuildFile; fileRef = 72B398D21D3D879300EE297F /* Autoupdate */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 7267E5FA1D3DAC3600D1BF90 /* StatusInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5A41D3D8A8A00D1BF90 /* StatusInfo.m */; }; 7267E5FD1D3DD1B700D1BF90 /* SPUResumableUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7267E5FB1D3DD1B700D1BF90 /* SPUResumableUpdate.h */; }; + 7269E494264798200088C213 /* SPUSkippedUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7269E492264798200088C213 /* SPUSkippedUpdate.h */; }; + 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7269E492264798200088C213 /* SPUSkippedUpdate.h */; }; + 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; + 7269E497264798200088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; 726DF88E1C84277600188804 /* SPUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUStatusCompletionResults.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 */; }; @@ -1244,6 +1248,8 @@ 7267E5E31D3D90AA00D1BF90 /* SUFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileManager.h; sourceTree = ""; }; 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileManager.m; sourceTree = ""; }; 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 = ""; }; 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUStatusCompletionResults.h; sourceTree = ""; }; 726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUSecureCoding.h; path = Sparkle/SPUSecureCoding.h; sourceTree = SOURCE_ROOT; }; @@ -1934,6 +1940,8 @@ 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */, 61EF67580E25C5B400F754E0 /* SUHost.h */, 61EF67550E25B58D00F754E0 /* SUHost.m */, + 7269E492264798200088C213 /* SPUSkippedUpdate.h */, + 7269E493264798200088C213 /* SPUSkippedUpdate.m */, 72162B071C82C9600013C1C5 /* SULocalizations.h */, 55C14F04136EF6DB00649790 /* SULog.h */, 55C14F05136EF6DB00649790 /* SULog.m */, @@ -2384,6 +2392,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */, 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */, 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */, @@ -2438,6 +2447,7 @@ 72F9EC481D5EA904004AC8B6 /* SPUUpdaterDelegate.h in Headers */, 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */, 72F9EC3F1D5E823F004AC8B6 /* SPUUpdaterTimer.h in Headers */, + 7269E494264798200088C213 /* SPUSkippedUpdate.h in Headers */, 723ABFC4259D4CB300BDB4FA /* SUWKWebView.h in Headers */, 7293A1AE1CEE933800B957A7 /* SPUURLRequest.h in Headers */, 725CB9571C7120410064365A /* SPUUserDriver.h in Headers */, @@ -3443,6 +3453,7 @@ 72A5D5BD1D6929F80009E5AC /* SPUDownloadData.m in Sources */, 72A5D5D01D6929F80009E5AC /* SPUDownloadDriver.m in Sources */, EA1E287122B66622004AA304 /* SUSignatures.m in Sources */, + 7269E497264798200088C213 /* SPUSkippedUpdate.m in Sources */, 72A5D5AF1D6929F80009E5AC /* SPUDownloader.m in Sources */, 72A5D5B71D6929F80009E5AC /* SPUInstallationInfo.m in Sources */, 72A5D5B41D6929F80009E5AC /* SPUInstallationInputData.m in Sources */, @@ -3575,6 +3586,7 @@ 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 72B767CB1C9B707000A07552 /* SUAppcastDriver.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, + 7269E496264798200088C213 /* SPUSkippedUpdate.m in Sources */, 725602D61C83551C00DAA70E /* SUApplicationInfo.m in Sources */, 7214B8821D456A8500CB5CED /* SUBundleIcon.m in Sources */, 72DBA37F1D62C23E002594A8 /* SUCodeSigningVerifier.m in Sources */, diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h new file mode 100644 index 00000000..d1124ebd --- /dev/null +++ b/Sparkle/SPUSkippedUpdate.h @@ -0,0 +1,28 @@ +// +// SPUSkippedUpdate.h +// Sparkle +// +// Created by Mayur Pawashe on 5/8/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class SUHost, SUAppcastItem; + +@interface SPUSkippedUpdate : NSObject + +- (instancetype)initWithVersion:(NSString *)version minimumAutoupdateVersion:(nullable NSString *)minimumAutoupdateVersion; + ++ (NSArray *)skippedUpdatesForHost:(SUHost *)host; ++ (void)clearSkippedUpdatesForHost:(SUHost *)host; ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host; + +@property (nonatomic, readonly) NSString *version; +@property (nonatomic, readonly, nullable) NSString *minimumAutoupdateVersion; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m new file mode 100644 index 00000000..5548fd7b --- /dev/null +++ b/Sparkle/SPUSkippedUpdate.m @@ -0,0 +1,123 @@ +// +// SPUSkippedUpdate.m +// Sparkle +// +// Created by Mayur Pawashe on 5/8/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUSkippedUpdate.h" +#import "SUHost.h" +#import "SUConstants.h" +#import "SUAppcastItem.h" + + +#include "AppKitPrevention.h" + +#define SKIPPED_UPDATE_TAG_SEPARATOR @";skip;" + +@implementation SPUSkippedUpdate + +@synthesize version = _version; +@synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion; + +- (instancetype)initWithVersion:(NSString *)version minimumAutoupdateVersion:(nullable NSString *)minimumAutoupdateVersion +{ + self = [super init]; + if (self != nil) { + _version = [version copy]; + _minimumAutoupdateVersion = [minimumAutoupdateVersion copy]; + } + return self; +} + ++ (NSString *)encodeSkippedUpdate:(SPUSkippedUpdate *)skippedUpdate +{ + NSMutableArray *components = [NSMutableArray array]; + + [components addObject:skippedUpdate.version]; + + NSString *minimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; + if (minimumAutoupdateVersion != nil) { + [components addObject:minimumAutoupdateVersion]; + } + + return [components componentsJoinedByString:SKIPPED_UPDATE_TAG_SEPARATOR]; +} + ++ (nullable instancetype)decodeSkippedUpdateFromString:(id)stringObject +{ + if (![(NSObject *)stringObject isKindOfClass:[NSString class]]) { + return nil; + } + + NSString *string = stringObject; + + NSArray *components = [string componentsSeparatedByString:SKIPPED_UPDATE_TAG_SEPARATOR]; + switch (components.count) { + case 1: + return [[self alloc] initWithVersion:components[0] minimumAutoupdateVersion:nil]; + case 2: + return [[self alloc] initWithVersion:components[0] minimumAutoupdateVersion:components[1]]; + default: + return nil; + } +} + ++ (NSArray *)skippedUpdatesForHost:(SUHost *)host +{ + id skippedVersions = [host objectForUserDefaultsKey:SUSkippedVersionKey]; + if ([(NSObject *)skippedVersions isKindOfClass:[NSString class]]) { + SPUSkippedUpdate *skippedUpdate = [SPUSkippedUpdate decodeSkippedUpdateFromString:skippedVersions]; + + return (skippedUpdate != nil) ? @[skippedUpdate] : @[]; + } else if ([(NSObject *)skippedVersions isKindOfClass:[NSArray class]]) { + NSMutableArray *skippedUpdates = [NSMutableArray array]; + for (id skippedUpdateObject in skippedVersions) { + SPUSkippedUpdate *skippedUpdate = [SPUSkippedUpdate decodeSkippedUpdateFromString:skippedUpdateObject]; + + if (skippedUpdate != nil) { + [skippedUpdates addObject:skippedUpdate]; + } + } + return [skippedUpdates copy]; + } else { + return @[]; + } +} + ++ (void)clearSkippedUpdatesForHost:(SUHost *)host +{ + [host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; +} + ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host +{ + NSArray *currentSkippedUpdates = [self skippedUpdatesForHost:host]; + NSMutableArray *newEncodedSkippedUpdates = [NSMutableArray array]; + + NSString *updateItemMinimumAutoupdateVersion = updateItem.minimumAutoupdateVersion; + + for (SPUSkippedUpdate *skippedUpdate in currentSkippedUpdates) { + NSString *skippedUpdateMinimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; + + if ((updateItemMinimumAutoupdateVersion == nil && skippedUpdateMinimumAutoupdateVersion == nil) || (skippedUpdateMinimumAutoupdateVersion != nil && [updateItemMinimumAutoupdateVersion isEqualToString:skippedUpdateMinimumAutoupdateVersion])) { + // On same train, skip adding this old update + // It will be replaced by the new skipped update we will be adding + continue; + } + + // Add everything else that is on a different train + // We should only have an update per train in skipped updates we store/load + [newEncodedSkippedUpdates addObject:[SPUSkippedUpdate encodeSkippedUpdate:skippedUpdate]]; + } + + // Always add the new skipped update + SPUSkippedUpdate *newSkippedUpdate = [[SPUSkippedUpdate alloc] initWithVersion:updateItem.versionString minimumAutoupdateVersion:updateItemMinimumAutoupdateVersion]; + + [newEncodedSkippedUpdates addObject:[SPUSkippedUpdate encodeSkippedUpdate:newSkippedUpdate]]; + + [host setObject:[newEncodedSkippedUpdates copy] forUserDefaultsKey:SUSkippedVersionKey]; +} + +@end diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 77b5a13d..0f7fa37c 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -17,6 +17,7 @@ #import "SPUDownloadData.h" #import "SPUResumableUpdate.h" #import "SPUDownloadDriver.h" +#import "SPUSkippedUpdate.h" #include "AppKitPrevention.h" @@ -174,6 +175,10 @@ state = SPUUserUpdateStateNotDownloaded; } + if (self.userInitiated) { + [SPUSkippedUpdate clearSkippedUpdatesForHost:self.host]; + } + [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -187,8 +192,6 @@ switch (validatedChoice) { case SPUUserUpdateChoiceInstall: { - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - switch (state) { case SPUUserUpdateStateDownloaded: [self.coreDriver extractDownloadedUpdate]; @@ -206,7 +209,7 @@ break; } case SPUUserUpdateChoiceSkip: { - [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; + [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; @@ -233,8 +236,6 @@ break; } case SPUUserUpdateChoiceDismiss: { - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - switch (state) { case SPUUserUpdateStateDownloaded: case SPUUserUpdateStateNotDownloaded: diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 2613bfab..f2409357 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -15,6 +15,7 @@ #import "SUOperatingSystem.h" #import "SPUUpdaterDelegate.h" #import "SUHost.h" +#import "SPUSkippedUpdate.h" #import "SUConstants.h" #import "SUPhasedUpdateGroupInfo.h" #import "SULog.h" @@ -168,13 +169,13 @@ NSNumber *phasedUpdateGroup = background ? @([SUPhasedUpdateGroupInfo updateGroupForHost:self.host]) : nil; - NSString *skippedVersion = background ? [self.host objectForUserDefaultsKey:SUSkippedVersionKey] : nil; + NSArray *skippedUpdates = background ? [SPUSkippedUpdate skippedUpdatesForHost:self.host] : @[]; // First filter out min/max OS version and see if there's an update that passes // the minimum autoupdate version. We filter out updates that fail the minimum // autoupdate version test because we have a preference over minor updates that can be // downloaded and installed with less disturbance - SUAppcast *passesMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedVersion:skippedVersion hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:YES]; + SUAppcast *passesMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdates:skippedUpdates hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:YES]; SUAppcastItem *secondaryItemPassesMinimumAutoupdate = nil; SUAppcastItem *primaryItemPassesMinimumAutoupdate = [self retrieveBestAppcastItemFromAppcast:passesMinimumAutoupdateAppcast versionComparator:applicationVersionComparator secondaryUpdate:&secondaryItemPassesMinimumAutoupdate]; @@ -184,7 +185,7 @@ SUAppcastItem *finalPrimaryItem; SUAppcastItem *finalSecondaryItem = nil; if (![self isItemNewer:primaryItemPassesMinimumAutoupdate]) { - SUAppcast *failsMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedVersion:skippedVersion hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:NO]; + SUAppcast *failsMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdates:skippedUpdates hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:NO]; finalPrimaryItem = [self retrieveBestAppcastItemFromAppcast:failsMinimumAutoupdateAppcast versionComparator:applicationVersionComparator secondaryUpdate:&finalSecondaryItem]; } else { @@ -194,7 +195,7 @@ if ([self isItemNewer:finalPrimaryItem]) { // We found a suitable update - BOOL preventsAutoupdate = ![[self class] isItemMinimumAutoupdateVersionOK:finalPrimaryItem hostVersion:self.host.version versionComparator:applicationVersionComparator]; + BOOL preventsAutoupdate = ![[self class] isItemMinimumAutoupdateVersionOK:finalPrimaryItem.minimumAutoupdateVersion hostVersion:self.host.version versionComparator:applicationVersionComparator]; [self.delegate didFindValidUpdateWithAppcastItem:finalPrimaryItem secondaryAppcastItem:finalSecondaryItem preventsAutoupdate:preventsAutoupdate]; } else { @@ -227,7 +228,7 @@ } // This method is used by unit tests -+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedVersion:(NSString * _Nullable)skippedVersion hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdates:(NSArray *)skippedUpdates hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion { NSDate *currentDate = [NSDate date]; @@ -236,9 +237,9 @@ BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate]; - BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || hostVersion == nil || versionComparator == nil || [self isItemMinimumAutoupdateVersionOK:item hostVersion:hostVersion versionComparator:versionComparator]); + BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || hostVersion == nil || versionComparator == nil || [self isItemMinimumAutoupdateVersionOK:item.minimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]); - BOOL passesSkippedUpdates = (skippedVersion == nil || versionComparator == nil || ![self item:item containsSkippedVersion:(NSString * _Nonnull)skippedVersion versionComparator:versionComparator]); + BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdates:skippedUpdates hostVersion:hostVersion versionComparator:versionComparator]); return (BOOL)(passesOSVersion && passesPhasedRollout && passesMinimumAutoupdateVersion && passesSkippedUpdates); }]; @@ -300,10 +301,9 @@ return [self isItemMinimumOperatingSystemVersionOK:ui versionComparator:versionComparator] && [self isItemMaximumOperatingSystemVersionOK:ui versionComparator:versionComparator]; } -+ (BOOL)isItemMinimumAutoupdateVersionOK:(SUAppcastItem *)ui hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator ++ (BOOL)isItemMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator { - NSString *minimumAutoupdateVersion = ui.minimumAutoupdateVersion; - return (minimumAutoupdateVersion.length == 0 || ([versionComparator compareVersion:hostVersion toVersion:minimumAutoupdateVersion] != NSOrderedAscending)); + return (minimumAutoupdateVersion.length == 0 || ([versionComparator compareVersion:hostVersion toVersion:(NSString * _Nonnull)minimumAutoupdateVersion] != NSOrderedAscending)); } - (id)versionComparator @@ -328,11 +328,29 @@ return ui != nil && [[self versionComparator] compareVersion:self.host.version toVersion:ui.versionString] == NSOrderedAscending; } -+ (BOOL)item:(SUAppcastItem *)ui containsSkippedVersion:(NSString * _Nullable)skippedVersion versionComparator:(id)versionComparator ++ (BOOL)item:(SUAppcastItem *)ui containsSkippedUpdates:(NSArray *)skippedUpdates hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator { - if (skippedVersion == nil) { return NO; } + NSString *itemVersion = ui.versionString; + NSString *itemMinimumAutoupdateVersion = ui.minimumAutoupdateVersion; - return [versionComparator compareVersion:ui.versionString toVersion:(NSString * _Nonnull)skippedVersion] != NSOrderedDescending; + for (SPUSkippedUpdate *skippedUpdate in skippedUpdates) { + NSString *skippedMinimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; + + BOOL hostPassesSkippedMinimumAutoupdateVersion = [self isItemMinimumAutoupdateVersionOK:skippedMinimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]; + + if (!hostPassesSkippedMinimumAutoupdateVersion && itemMinimumAutoupdateVersion != nil && [skippedMinimumAutoupdateVersion isEqualToString:itemMinimumAutoupdateVersion]) { + // Skipped update is on same train as item and we fail minimum autoupdate test + // So we skip all updates with the same minimum autoupdate version that we failed + return YES; + } + + if (hostPassesSkippedMinimumAutoupdateVersion && [versionComparator compareVersion:skippedUpdate.version toVersion:itemVersion] != NSOrderedAscending) { + // If host passes train of this skipped version and skipped version >= item version, then skip the update + return YES; + } + } + + return NO; } + (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate From 0ee12d881dff8154a8670050a187c545acf7c9d6 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 19:53:19 -0700 Subject: [PATCH 02/17] Add and fix unit tests for skipping updates --- Sparkle.xcodeproj/project.pbxproj | 2 + Tests/SUAppcastTest.swift | 134 +++++++++++++++++++-- Tests/Sparkle Unit Tests-Bridging-Header.h | 3 +- 3 files changed, 131 insertions(+), 8 deletions(-) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 97b9c4e2..5be74543 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -288,6 +288,7 @@ 7269E495264798200088C213 /* SPUSkippedUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7269E492264798200088C213 /* SPUSkippedUpdate.h */; }; 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 */; }; 726DF88E1C84277600188804 /* SPUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUStatusCompletionResults.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 */; }; @@ -3270,6 +3271,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7269E4982648D3460088C213 /* SPUSkippedUpdate.m in Sources */, 721D5ABC25C680A300D23BEA /* SUFlatPackageUnarchiver.m in Sources */, 725F97771C8A62F500265BE4 /* SUAdHocCodeSigning.m in Sources */, 5A4094481C74EA5200983BE0 /* SUAppcastTest.swift in Sources */, diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index dfe63735..0ef19e66 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -45,7 +45,7 @@ class SUAppcastTest: XCTestCase { XCTAssertFalse(items[3].isCriticalUpdate) // Test best appcast item & a delta update item - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: nil, hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) let supportedAppcastItems = supportedAppcast.items @@ -88,7 +88,7 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "1.0" - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(1, supportedAppcast.items.count) @@ -101,7 +101,7 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.0" - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -114,7 +114,7 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.5" - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -129,14 +129,18 @@ class SUAppcastTest: XCTestCase { // There should be no items if 2.0 is skipped from 1.0 and 3.0 fails minimum autoupdate version do { - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: "2.0", hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let skippedUpdate = SPUSkippedUpdate(version: "2.0", minimumAutoupdateVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(0, supportedAppcast.items.count) } // Try again but allowing minimum autoupdate version to fail do { - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: "2.0", hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let skippedUpdate = SPUSkippedUpdate(version: "2.0", minimumAutoupdateVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(1, supportedAppcast.items.count) @@ -144,8 +148,124 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual(bestAppcastItem.versionString, "3.0") } + + // Allow minimum autoupdate version to fail and only skip 3.0 + do { + let skippedUpdate = SPUSkippedUpdate(version: "3.0", minimumAutoupdateVersion: "2.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(1, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "2.0") + } + + // Allow minimum autoupdate version to fail skipping both 2.0 and 3.0 + do { + let skippedUpdate = SPUSkippedUpdate(version: "3.0", minimumAutoupdateVersion: "2.0") + let skippedUpdate2 = SPUSkippedUpdate(version: "2.0", minimumAutoupdateVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate, skippedUpdate2], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(0, supportedAppcast.items.count) + } + + // Allow minimum autoupdate version to fail and only skip "2.99.9" which we will treat as same train on 3.0 + // This should implicitly only skip 3.0 + do { + let skippedUpdate = SPUSkippedUpdate(version: "2.99.9", minimumAutoupdateVersion: "2.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(1, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "2.0") + } + + // Allow minimum autoupdate version to fail and only skip "3.1" which we will treat as same train on 3.0 + // This should implicitly only skip 3.0 + do { + let skippedUpdate = SPUSkippedUpdate(version: "3.1", minimumAutoupdateVersion: "2.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(1, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "2.0") + } + + // Allow minimum autoupdate version to fail and only skip "2.5" + // This should implicitly only skip 2.0 + do { + let skippedUpdate = SPUSkippedUpdate(version: "2.5", minimumAutoupdateVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(1, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "3.0") + } + + // This should not skip anything but require passing minimum autoupdate version + do { + let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + + XCTAssertEqual(1, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "2.0") + } + + // This should not skip anything but allow failing minimum autoupdate version + do { + let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(2, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "3.0") + } + + // This should not skip anything but require passing minimum autoupdate version + do { + let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: "1.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + + XCTAssertEqual(1, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "2.0") + } + + // This should not skip anything but allow failing minimum autoupdate version + do { + let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: "1.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + + XCTAssertEqual(2, supportedAppcast.items.count) + + let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) + + XCTAssertEqual(bestAppcastItem.versionString, "3.0") + } } - } catch let err as NSError { NSLog("%@", err) XCTFail(err.localizedDescription) diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 2cc3a9a5..7dac6523 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -17,6 +17,7 @@ #import "SUStandardVersionComparator.h" #import "SUUpdateValidator.h" #import "SUHost.h" +#import "SPUSkippedUpdate.h" #import "SUSignatures.h" #import "SPUInstallationType.h" @@ -38,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 skippedVersion:(NSString * _Nullable)skippedVersion hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdates:(NSArray *)skippedUpdates hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; @end From a79f6b2a851edf0a21d13232e387d59c4dbcea80 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 20:48:32 -0700 Subject: [PATCH 03/17] Add documentation to SPUSkippedUpdate --- Sparkle/SPUSkippedUpdate.h | 6 ++++++ Sparkle/SPUSkippedUpdate.m | 3 +++ 2 files changed, 9 insertions(+) diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h index d1124ebd..0e647301 100644 --- a/Sparkle/SPUSkippedUpdate.h +++ b/Sparkle/SPUSkippedUpdate.h @@ -12,6 +12,12 @@ NS_ASSUME_NONNULL_BEGIN @class SUHost, SUAppcastItem; +/* + A skipped update tracks the version and minimum autoupdate version the user skipped. + Each minimum autoupdate version is tracked as a separate release / train. + The intent is that a user choosing to skip a future major update chooses to skip that train's updates, + but a user choosing to skip a minor update only chooses to skip updates equal or preceding that update. + */ @interface SPUSkippedUpdate : NSObject - (instancetype)initWithVersion:(NSString *)version minimumAutoupdateVersion:(nullable NSString *)minimumAutoupdateVersion; diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m index 5548fd7b..1c732c96 100644 --- a/Sparkle/SPUSkippedUpdate.m +++ b/Sparkle/SPUSkippedUpdate.m @@ -42,6 +42,7 @@ [components addObject:minimumAutoupdateVersion]; } + // We encode the version and minimum autoupdate version in a human readable form with our own separator return [components componentsJoinedByString:SKIPPED_UPDATE_TAG_SEPARATOR]; } @@ -68,10 +69,12 @@ { id skippedVersions = [host objectForUserDefaultsKey:SUSkippedVersionKey]; if ([(NSObject *)skippedVersions isKindOfClass:[NSString class]]) { + // Handle legacy skipped version format with just a single skipped version SPUSkippedUpdate *skippedUpdate = [SPUSkippedUpdate decodeSkippedUpdateFromString:skippedVersions]; return (skippedUpdate != nil) ? @[skippedUpdate] : @[]; } else if ([(NSObject *)skippedVersions isKindOfClass:[NSArray class]]) { + // Handle array of skipped updates NSMutableArray *skippedUpdates = [NSMutableArray array]; for (id skippedUpdateObject in skippedVersions) { SPUSkippedUpdate *skippedUpdate = [SPUSkippedUpdate decodeSkippedUpdateFromString:skippedUpdateObject]; From d193f2e28bb12418c2f398756c8240ec769c6bb2 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 22:42:42 -0700 Subject: [PATCH 04/17] Pass majorUpdate information to user driver We unify the user driver method showing the update to take a generic state object now. The current fields of the state object are its current stage, if it's user initiated, and if the update is a major one. We also remove deprecated code paths that were complex to support and will otherwise generate in compile errors if people adopt the new API. --- Sparkle.xcodeproj/project.pbxproj | 20 +- Sparkle/SPUCoreBasedUpdateDriver.h | 2 +- Sparkle/SPUStandardUserDriver.m | 4 +- Sparkle/SPUStatusCompletionResults.h | 67 ----- Sparkle/SPUUIBasedUpdateDriver.m | 261 ++++++------------ Sparkle/SPUUserDriver.h | 35 +-- Sparkle/SPUUserInitiatedUpdateDriver.m | 24 +- Sparkle/SPUUserUpdateState+Private.h | 22 ++ Sparkle/SPUUserUpdateState.h | 48 ++++ Sparkle/SPUUserUpdateState.m | 32 +++ Sparkle/SUUpdateAlert.h | 4 +- Sparkle/SUUpdateAlert.m | 12 +- .../SUInstallUpdateViewController.h | 2 +- .../SUInstallUpdateViewController.m | 7 +- TestApplication/SUPopUpTitlebarUserDriver.m | 20 +- sparkle-cli/SPUCommandLineUserDriver.m | 12 +- 16 files changed, 246 insertions(+), 326 deletions(-) delete mode 100644 Sparkle/SPUStatusCompletionResults.h create mode 100644 Sparkle/SPUUserUpdateState+Private.h create mode 100644 Sparkle/SPUUserUpdateState.h create mode 100644 Sparkle/SPUUserUpdateState.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 5be74543..0c7ee735 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -289,7 +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 */; }; - 726DF88E1C84277600188804 /* SPUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUStatusCompletionResults.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, ); }; }; @@ -385,7 +387,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 /* SPUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUStatusCompletionResults.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 */; }; @@ -1251,8 +1253,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 = ""; }; 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUStatusCompletionResults.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; }; @@ -2144,7 +2148,9 @@ 725CB9581C7121830064365A /* SPUStandardUserDriver.h */, 725CB9591C7121830064365A /* SPUStandardUserDriver.m */, 726E4A361C89116000C57C6A /* SPUStandardUserDriverDelegate.h */, - 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */, + 726DF88D1C84277500188804 /* SPUUserUpdateState.h */, + 7269E49C2648FC6C0088C213 /* SPUUserUpdateState+Private.h */, + 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */, 725CB9561C7120410064365A /* SPUUserDriver.h */, ); name = "User Driver"; @@ -2398,7 +2404,7 @@ 72B3DECE1E23479000457642 /* SPUInformationalUpdate.h in Headers */, 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */, 721D588E25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h in Headers */, - 72A5D5F91D692F4C0009E5AC /* SPUStatusCompletionResults.h in Headers */, + 72A5D5F91D692F4C0009E5AC /* SPUUserUpdateState.h in Headers */, 72A5D5E71D692BB00009E5AC /* SPUUpdatePermissionRequest.h in Headers */, EA1E286F22B6661D004AA304 /* SUSignatures.h in Headers */, 72A5D5E21D692B770009E5AC /* SPUUpdater.h in Headers */, @@ -2439,7 +2445,7 @@ 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */, 725CB95A1C7121830064365A /* SPUStandardUserDriver.h in Headers */, 726E4A371C89116000C57C6A /* SPUStandardUserDriverDelegate.h in Headers */, - 726DF88E1C84277600188804 /* SPUStatusCompletionResults.h in Headers */, + 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */, 72B767DA1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.h in Headers */, 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */, 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */, @@ -3487,6 +3493,7 @@ 72A5D5B01D6929F80009E5AC /* SUInstallerConnection.m in Sources */, 72A5D5AE1D6929F80009E5AC /* SUInstallerLauncher.m in Sources */, 72B3DED01E23479000457642 /* SPUInformationalUpdate.m in Sources */, + 7269E49B2648F7C00088C213 /* SPUUserUpdateState.m in Sources */, 72A5D5B21D6929F80009E5AC /* SUInstallerStatus.m in Sources */, 72A5D5C51D6929F80009E5AC /* SULog.m in Sources */, 72A5D5C61D6929F80009E5AC /* SUOperatingSystem.m in Sources */, @@ -3589,6 +3596,7 @@ 72B767CB1C9B707000A07552 /* SUAppcastDriver.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 7269E496264798200088C213 /* SPUSkippedUpdate.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 64f8ffb9..85805166 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -7,7 +7,7 @@ // #import -#import "SPUStatusCompletionResults.h" +#import "SPUUserUpdateState.h" #import "SPUUpdateDriver.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 7a81ac40..25a0e8c1 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -115,7 +115,7 @@ #pragma mark Update Found -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { assert(NSThread.isMainThread); @@ -132,7 +132,7 @@ weakSelf.activeUpdateAlert = nil; }]; - [self setUpFocusForActiveUpdateAlertWithUserInitiation:userInitiated]; + [self setUpFocusForActiveUpdateAlertWithUserInitiation:state.userInitiated]; } - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData diff --git a/Sparkle/SPUStatusCompletionResults.h b/Sparkle/SPUStatusCompletionResults.h deleted file mode 100644 index 31fd4ae0..00000000 --- a/Sparkle/SPUStatusCompletionResults.h +++ /dev/null @@ -1,67 +0,0 @@ -// -// SPUStatusCompletionResults.h -// Sparkle -// -// Created by Mayur Pawashe on 2/29/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#ifndef SPUStatusCompletionResults_h -#define SPUStatusCompletionResults_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 - -// The value ordering here intentionally aligns with replacing SPUInstallUpdateStatus -typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { - SPUUserUpdateChoiceSkip, - SPUUserUpdateChoiceInstall, - SPUUserUpdateChoiceDismiss, -}; - -typedef NS_ENUM(NSInteger, SPUUserUpdateState) { - SPUUserUpdateStateNotDownloaded, - SPUUserUpdateStateDownloaded, - SPUUserUpdateStateInstalling, - SPUUserUpdateStateInformational -}; - -// Deprecated -typedef NS_ENUM(NSInteger, SPUInformationalUpdateAlertChoice) { - SPUDismissInformationalNoticeChoice, - SPUSkipThisInformationalVersionChoice -}; - -// Deprecated -typedef NS_ENUM(NSUInteger, SPUInstallUpdateStatus) { - SPUInstallUpdateNow, - SPUInstallAndRelaunchUpdateNow, - SPUDismissUpdateInstallation -}; - -// Deprecated -typedef NS_ENUM(NSInteger, SPUUpdateAlertChoice) { - SPUInstallUpdateChoice, - SPUInstallLaterChoice, - SPUSkipThisVersionChoice -}; - -// Deprecated -typedef NS_ENUM(NSUInteger, SPUUserInitiatedCheckStatus) { - SPUUserInitiatedCheckDone, - SPUUserInitiatedCheckCanceled -}; - -// Deprecated -typedef NS_ENUM(NSUInteger, SPUDownloadUpdateStatus) { - SPUDownloadUpdateDone, - SPUDownloadUpdateCanceled -}; - -#endif /* SPUStatusCompletionResults_h */ diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 0f7fa37c..435a7d9e 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -18,6 +18,7 @@ #import "SPUResumableUpdate.h" #import "SPUDownloadDriver.h" #import "SPUSkippedUpdate.h" +#import "SPUUserUpdateState+Private.h" #include "AppKitPrevention.h" @@ -162,175 +163,100 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { + if (self.userInitiated) { + [SPUSkippedUpdate clearSkippedUpdatesForHost:self.host]; + } + id updaterDelegate = self.updaterDelegate; - if ([self.userDriver respondsToSelector:@selector(showUpdateFoundWithAppcastItem:userInitiated:state:reply:)]) { - SPUUserUpdateState state; - if (updateItem.isInformationOnlyUpdate) { - state = SPUUserUpdateStateInformational; - } else if (self.resumingDownloadedUpdate) { - state = SPUUserUpdateStateDownloaded; - } else if (self.resumingInstallingUpdate) { - state = SPUUserUpdateStateInstalling; - } else { - state = SPUUserUpdateStateNotDownloaded; - } - - if (self.userInitiated) { - [SPUSkippedUpdate clearSkippedUpdatesForHost:self.host]; - } - - [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated state:state reply:^(SPUUserUpdateChoice userChoice) { - dispatch_async(dispatch_get_main_queue(), ^{ - - // Rule out invalid choices - SPUUserUpdateChoice validatedChoice; - if (state == SPUUserUpdateStateInformational && userChoice == SPUUserUpdateChoiceInstall) { - validatedChoice = SPUUserUpdateChoiceDismiss; - } else { - validatedChoice = userChoice; - } - - switch (validatedChoice) { - case SPUUserUpdateChoiceInstall: { - switch (state) { - case SPUUserUpdateStateDownloaded: - [self.coreDriver extractDownloadedUpdate]; - break; - case SPUUserUpdateStateInstalling: - [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; - break; - case SPUUserUpdateStateNotDownloaded: - [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:NO]; - break; - case SPUUserUpdateStateInformational: - assert(false); - break; - } - break; - } - case SPUUserUpdateChoiceSkip: { - [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; - - if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { - [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; - } - - switch (state) { - case SPUUserUpdateStateDownloaded: - case SPUUserUpdateStateNotDownloaded: - case SPUUserUpdateStateInformational: - // Informational updates can be resumed too, so make sure we check - // self.resumingDownloadedUpdate instead of the state we pass to user driver - if (self.resumingDownloadedUpdate) { - [self.coreDriver clearDownloadedUpdate]; - } - - [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; - - break; - case SPUUserUpdateStateInstalling: - [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; - break; - } - - break; - } - case SPUUserUpdateChoiceDismiss: { - switch (state) { - case SPUUserUpdateStateDownloaded: - case SPUUserUpdateStateNotDownloaded: - case SPUUserUpdateStateInformational: { - [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; - break; - } - case SPUUserUpdateStateInstalling: { - [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; - break; - } - } - - break; - } - } - }); - }]; + + SPUUserUpdateStage stage; + if (updateItem.isInformationOnlyUpdate) { + stage = SPUUserUpdateStageInformational; + } else if (self.resumingDownloadedUpdate) { + stage = SPUUserUpdateStageDownloaded; + } else if (self.resumingInstallingUpdate) { + stage = SPUUserUpdateStageInstalling; } else { - // Legacy path that will be removed eventually -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - if (updateItem.isInformationOnlyUpdate) { - assert(!self.resumingDownloadedUpdate); - assert(!self.resumingInstallingUpdate); + stage = SPUUserUpdateStageNotDownloaded; + } + + SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpdate:preventsAutoupdate]; + + [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { + dispatch_async(dispatch_get_main_queue(), ^{ - [self.userDriver showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) { - dispatch_async(dispatch_get_main_queue(), ^{ - switch (choice) { - case SPUSkipThisInformationalVersionChoice: - [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; - - if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { - [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; - } - // Fall through - case SPUDismissInformationalNoticeChoice: - [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; - break; - } - }); - }]; - } else if (self.resumingDownloadedUpdate) { - [self.userDriver showDownloadedUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - switch (choice) { - case SPUInstallUpdateChoice: + // Rule out invalid choices + SPUUserUpdateChoice validatedChoice; + if (stage == SPUUserUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { + validatedChoice = SPUUserUpdateChoiceDismiss; + } else { + validatedChoice = userChoice; + } + + switch (validatedChoice) { + case SPUUserUpdateChoiceInstall: { + switch (stage) { + case SPUUserUpdateStageDownloaded: [self.coreDriver extractDownloadedUpdate]; break; - case SPUSkipThisVersionChoice: - [self.coreDriver clearDownloadedUpdate]; - [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; - - if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { - [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; - } - // Fall through - case SPUInstallLaterChoice: - [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; + case SPUUserUpdateStageInstalling: + [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; - } - }); - }]; - } else if (!self.resumingInstallingUpdate) { - [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - switch (choice) { - case SPUInstallUpdateChoice: + case SPUUserUpdateStageNotDownloaded: [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:NO]; break; - case SPUSkipThisVersionChoice: - [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; - - if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { - [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; - } - // Fall through - case SPUInstallLaterChoice: - [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; + case SPUUserUpdateStageInformational: + assert(false); break; } - }); - }]; - } else { - [self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUserUpdateChoice choice) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - [self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction]; - }); - }]; - } -#pragma clang diagnostic pop - } + break; + } + case SPUUserUpdateChoiceSkip: { + [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; + + if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { + [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; + } + + 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) { + [self.coreDriver clearDownloadedUpdate]; + } + + [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; + + break; + case SPUUserUpdateStageInstalling: + [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; + break; + } + + break; + } + case SPUUserUpdateChoiceDismiss: { + switch (stage) { + case SPUUserUpdateStageDownloaded: + case SPUUserUpdateStageNotDownloaded: + case SPUUserUpdateStageInformational: { + [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; + break; + } + case SPUUserUpdateStageInstalling: { + [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; + break; + } + } + + break; + } + } + }); + }]; if ([self.delegate respondsToSelector:@selector(uiDriverDidShowUpdate)]) { [self.delegate uiDriverDidShowUpdate]; @@ -365,22 +291,7 @@ }); }; - if ([self.userDriver respondsToSelector:@selector(showDownloadInitiatedWithCancellation:)]) { - [self.userDriver showDownloadInitiatedWithCancellation:cancelDownload]; - } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [self.userDriver showDownloadInitiatedWithCompletion:^(SPUDownloadUpdateStatus downloadCompletionStatus) { - switch (downloadCompletionStatus) { -#pragma clang diagnostic pop - case SPUDownloadUpdateDone: - break; - case SPUDownloadUpdateCanceled: - cancelDownload(); - break; - } - }]; - } + [self.userDriver showDownloadInitiatedWithCancellation:cancelDownload]; } - (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 89e2715c..a31eb2f8 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -15,7 +15,7 @@ #import #endif -#import "SPUStatusCompletionResults.h" +#import "SPUUserUpdateState.h" #import "SUExport.h" NS_ASSUME_NONNULL_BEGIN @@ -60,28 +60,31 @@ SU_EXPORT @protocol SPUUserDriver * * @param appcastItem The Appcast Item containing information that reflects the new update. * - * @param userInitiated A flag indicating whether or not a user initiated this update check - * * @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 the infoURL property of the appcastItem in their web browser. The informationOnlyUpdate property of the appcastItem will be YES. + * 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. + * + * state.userInitiated indicates if the update was initiated by the user or if it was automatically scheduled in the background. + * state.majorUpdate 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. * * @param reply * A reply of SPUUserUpdateChoiceInstall begins or resumes downloading or installing the update. - * If the state 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"). * * 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 is SPUUserUpdateStateDownloaded, the downloaded update is kept after dismissing until the next time an update is shown to the user. - * If the state 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. + * 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 the state is SPUUserUpdateStateInstalling, the installation is also canceled when the update is skipped. + * If state.majorUpdate 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. */ -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)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 @@ -256,24 +259,12 @@ SU_EXPORT @protocol SPUUserDriver @optional // Clients should move to non-deprecated methods -// Deprecated methods are only (temporarily) kept around for binary compatibility reasons - -- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion __deprecated_msg("Implement -showUserInitiatedUpdateCheckWithCancellation: instead"); - -- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion __deprecated_msg("Implement -showDownloadInitiatedWithCancellation: instead"); +// Deprecated methods are only (temporarily) kept around for compatibility reasons - (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))acknowledgement __deprecated_msg("Implement -showUpdateNotFoundWithError:acknowledgement: instead"); - (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement __deprecated_msg("Implement -showUpdateInstalledAndRelaunched:acknowledgement: instead"); -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply __deprecated_msg("Implement -showUpdateFoundWithAppcastItem:userInitiated:state:reply: instead"); - -- (void)showDownloadedUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply __deprecated_msg("Implement -showUpdateFoundWithAppcastItem:userInitiated:state:reply: instead"); - -- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUserUpdateChoice))reply __deprecated_msg("Implement -showUpdateFoundWithAppcastItem:userInitiated:state:reply: instead"); - -- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply __deprecated_msg("Implement -showUpdateFoundWithAppcastItem:userInitiated:state:reply: instead"); - - (void)dismissUserInitiatedUpdateCheck __deprecated_msg("Transition to new UI appropriately when a new update is shown, when no update is found, or when an update error occurs.");; @end diff --git a/Sparkle/SPUUserInitiatedUpdateDriver.m b/Sparkle/SPUUserInitiatedUpdateDriver.m index b99d0803..dabf8d21 100644 --- a/Sparkle/SPUUserInitiatedUpdateDriver.m +++ b/Sparkle/SPUUserInitiatedUpdateDriver.m @@ -51,33 +51,15 @@ [self abortUpdateWithError:error]; } else { self.showingUserInitiatedProgress = YES; + self.showingUpdate = YES; - void (^cancelUpdateCheck)(void) = ^{ + [self.userDriver showUserInitiatedUpdateCheckWithCancellation:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (self.showingUserInitiatedProgress) { [self abortUpdate]; } }); - }; - - self.showingUpdate = YES; - - if ([self.userDriver respondsToSelector:@selector(showUserInitiatedUpdateCheckWithCancellation:)]) { - [self.userDriver showUserInitiatedUpdateCheckWithCancellation:cancelUpdateCheck]; - } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [self.userDriver showUserInitiatedUpdateCheckWithCompletion:^(SPUUserInitiatedCheckStatus completionStatus) { -#pragma clang diagnostic pop - switch (completionStatus) { - case SPUUserInitiatedCheckDone: - break; - case SPUUserInitiatedCheckCanceled: - cancelUpdateCheck(); - break; - } - }]; - } + }]; [self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:NO]; } diff --git a/Sparkle/SPUUserUpdateState+Private.h b/Sparkle/SPUUserUpdateState+Private.h new file mode 100644 index 00000000..052d10ce --- /dev/null +++ b/Sparkle/SPUUserUpdateState+Private.h @@ -0,0 +1,22 @@ +// +// 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 majorUpdate:(BOOL)majorUpdate; + +@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..7f2b0040 --- /dev/null +++ b/Sparkle/SPUUserUpdateState.h @@ -0,0 +1,48 @@ +// +// SPUUserUpdateState.h +// Sparkle +// +// Created by Mayur Pawashe on 2/29/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#ifndef SPUUserUpdateState_h +#define SPUUserUpdateState_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 + +@property (nonatomic, readonly) SPUUserUpdateStage stage; +@property (nonatomic, readonly) BOOL userInitiated; +@property (nonatomic, readonly) BOOL majorUpdate; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUUserUpdateState_h */ diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUserUpdateState.m new file mode 100644 index 00000000..a9f7d4cc --- /dev/null +++ b/Sparkle/SPUUserUpdateState.m @@ -0,0 +1,32 @@ +// +// SPUUserUpdateState.m +// Sparkle +// +// Created by Mayur Pawashe on 5/9/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUUserUpdateState.h" +#import "SPUUserUpdateState+Private.h" + + +#include "AppKitPrevention.h" + +@implementation SPUUserUpdateState + +@synthesize stage = _stage; +@synthesize userInitiated = _userInitiated; +@synthesize majorUpdate = _majorUpdate; + +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpdate:(BOOL)majorUpdate +{ + self = [super init]; + if (self != nil) { + _stage = stage; + _userInitiated = userInitiated; + _majorUpdate = majorUpdate; + } + return self; +} + +@end diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 4f7ada7f..41ee55bd 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -11,7 +11,7 @@ #import #import "SUVersionDisplayProtocol.h" -#import "SPUStatusCompletionResults.h" +#import "SPUUserUpdateState.h" @protocol SUUpdateAlertDelegate; @@ -20,7 +20,7 @@ @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:(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 37603cb2..8cca75b4 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -36,7 +36,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) SPUUserUpdateState *state; @property (strong) NSProgressIndicator *releaseNotesSpinner; @@ -80,7 +80,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:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUserUpdateChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; if (self != nil) { @@ -362,7 +362,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } } - if (self.state == SPUUserUpdateStateInstalling) { + if (self.state.stage == SPUUserUpdateStageInstalling) { // We're going to be relaunching pretty instantaneously self.installButton.title = SULocalizedString(@"Install and Relaunch", nil); @@ -400,7 +400,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 == SPUUserUpdateStateDownloaded || self.state == SPUUserUpdateStateInstalling) + 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]]; } @@ -428,13 +428,13 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE 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 isCriticalUpdate]) { - if (self.state == SPUUserUpdateStateNotDownloaded) { + 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 == SPUUserUpdateStateNotDownloaded) { + 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/TestApplication/SUInstallUpdateViewController.h b/TestApplication/SUInstallUpdateViewController.h index 0ae16ea2..a0cfc475 100644 --- a/TestApplication/SUInstallUpdateViewController.h +++ b/TestApplication/SUInstallUpdateViewController.h @@ -11,7 +11,7 @@ @interface SUInstallUpdateViewController : NSViewController -- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SPUUserUpdateChoice))reply; - (void)showReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; diff --git a/TestApplication/SUInstallUpdateViewController.m b/TestApplication/SUInstallUpdateViewController.m index 019860f2..86363981 100644 --- a/TestApplication/SUInstallUpdateViewController.m +++ b/TestApplication/SUInstallUpdateViewController.m @@ -15,7 +15,6 @@ @property (nonatomic, readonly) SUAppcastItem *appcastItem; @property (nonatomic, nullable) NSAttributedString *preloadedReleaseNotes; @property (nonatomic, copy) void (^reply)(SPUUserUpdateChoice); -@property (nonatomic, readonly) BOOL skippable; @end @@ -26,14 +25,12 @@ @synthesize preloadedReleaseNotes = _preloadedReleaseNotes; @synthesize appcastItem = _appcastItem; @synthesize reply = _reply; -@synthesize skippable = _skippable; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply +- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SPUUserUpdateChoice))reply { self = [super initWithNibName:@"SUInstallUpdateViewController" bundle:nil]; if (self != nil) { _appcastItem = appcastItem; - _skippable = skippable; self.reply = reply; } return self; @@ -43,8 +40,6 @@ { [super viewDidLoad]; - self.skipUpdatesButton.enabled = self.skippable; - [[self.textView enclosingScrollView] setDrawsBackground:NO]; [self.textView setDrawsBackground:NO]; diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 6ecb96cd..a72f923f 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -107,7 +107,7 @@ #pragma mark Update Found -- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SPUUserUpdateChoice))reply { NSPopover *popover = [[NSPopover alloc] init]; popover.behavior = NSPopoverBehaviorTransient; @@ -115,7 +115,7 @@ __weak SUPopUpTitlebarUserDriver *weakSelf = self; __block NSButton *actionButton = nil; - SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUserUpdateChoice choice) { + SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem reply:^(SPUUserUpdateChoice choice) { reply(choice); [popover close]; @@ -133,10 +133,10 @@ }]; } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { - switch (state) { - case SPUUserUpdateStateInformational: + switch (state.stage) { + case SPUUserUpdateStageInformational: // Todo: show user interface for this NSLog(@"Found info URL: %@", appcastItem.infoURL); @@ -146,12 +146,10 @@ reply(SPUUserUpdateChoiceDismiss); break; - case SPUUserUpdateStateNotDownloaded: - case SPUUserUpdateStateDownloaded: - [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; - break; - case SPUUserUpdateStateInstalling: - [self showUpdateWithAppcastItem:appcastItem skippable:NO reply:reply]; + case SPUUserUpdateStageNotDownloaded: + case SPUUserUpdateStageDownloaded: + case SPUUserUpdateStageInstalling: + [self showUpdateWithAppcastItem:appcastItem reply:reply]; break; } } diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 3cd22c49..cceb6c06 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 userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { - switch (state) { - case SPUUserUpdateStateNotDownloaded: + switch (state.stage) { + case SPUUserUpdateStageNotDownloaded: [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; reply(SPUUserUpdateChoiceInstall); break; - case SPUUserUpdateStateDownloaded: + case SPUUserUpdateStageDownloaded: [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; reply(SPUUserUpdateChoiceInstall); break; - case SPUUserUpdateStateInstalling: + case SPUUserUpdateStageInstalling: if (self.deferInstallation) { if (self.verbose) { fprintf(stderr, "Deferring Installation.\n"); @@ -118,7 +118,7 @@ reply(SPUUserUpdateChoiceInstall); } break; - case SPUUserUpdateStateInformational: + case SPUUserUpdateStageInformational: fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); reply(SPUUserUpdateChoiceDismiss); break; From 25b3d01efaba18cef13b17eeddee0d4688d833e9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 22:45:40 -0700 Subject: [PATCH 05/17] Rename majorUpdate to majorUpgrade --- Sparkle/SPUUIBasedUpdateDriver.m | 2 +- Sparkle/SPUUserDriver.h | 4 ++-- Sparkle/SPUUserUpdateState+Private.h | 2 +- Sparkle/SPUUserUpdateState.h | 2 +- Sparkle/SPUUserUpdateState.m | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 435a7d9e..a0e8841a 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -180,7 +180,7 @@ stage = SPUUserUpdateStageNotDownloaded; } - SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpdate:preventsAutoupdate]; + SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:preventsAutoupdate]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index a31eb2f8..684cf12d 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -68,7 +68,7 @@ SU_EXPORT @protocol SPUUserDriver * 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. * * state.userInitiated indicates if the update was initiated by the user or if it was automatically scheduled in the background. - * state.majorUpdate indicates if the update is a major or paid upgrade. + * 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. * @@ -81,7 +81,7 @@ SU_EXPORT @protocol SPUUserDriver * 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.majorUpdate is YES, the major update and any minor updates to that major release are skipped. + * 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. */ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; diff --git a/Sparkle/SPUUserUpdateState+Private.h b/Sparkle/SPUUserUpdateState+Private.h index 052d10ce..90e732c4 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 majorUpdate:(BOOL)majorUpdate; +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade; @end diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUserUpdateState.h index 7f2b0040..b1be0c91 100644 --- a/Sparkle/SPUUserUpdateState.h +++ b/Sparkle/SPUUserUpdateState.h @@ -39,7 +39,7 @@ SU_EXPORT @interface SPUUserUpdateState : NSObject @property (nonatomic, readonly) SPUUserUpdateStage stage; @property (nonatomic, readonly) BOOL userInitiated; -@property (nonatomic, readonly) BOOL majorUpdate; +@property (nonatomic, readonly) BOOL majorUpgrade; @end diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUserUpdateState.m index a9f7d4cc..6cef2526 100644 --- a/Sparkle/SPUUserUpdateState.m +++ b/Sparkle/SPUUserUpdateState.m @@ -16,15 +16,15 @@ @synthesize stage = _stage; @synthesize userInitiated = _userInitiated; -@synthesize majorUpdate = _majorUpdate; +@synthesize majorUpgrade = _majorUpgrade; -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpdate:(BOOL)majorUpdate +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade { self = [super init]; if (self != nil) { _stage = stage; _userInitiated = userInitiated; - _majorUpdate = majorUpdate; + _majorUpgrade = majorUpgrade; } return self; } From 1565db3feca0b97b57b8caefffc206f2dfdc9803 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 22:51:50 -0700 Subject: [PATCH 06/17] Add secure coding to SPUUserUpdateState --- Sparkle/SPUUserUpdateState.m | 25 +++++++++++++++++++++++++ Sparkle/SUAppcastItem+Private.h | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUserUpdateState.m index 6cef2526..935f6766 100644 --- a/Sparkle/SPUUserUpdateState.m +++ b/Sparkle/SPUUserUpdateState.m @@ -12,6 +12,10 @@ #include "AppKitPrevention.h" +#define SPUUserUpdateStateStageKey @"SPUUserUpdateStateStage" +#define SPUUserUpdateStateUserInitiatedKey @"SPUUserUpdateStateUserInitiated" +#define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" + @implementation SPUUserUpdateState @synthesize stage = _stage; @@ -29,4 +33,25 @@ return self; } +- (void)encodeWithCoder:(NSCoder *)encoder +{ + [encoder encodeInteger:self.stage forKey:SPUUserUpdateStateStageKey]; + [encoder encodeBool:self.userInitiated forKey:SPUUserUpdateStateUserInitiatedKey]; + [encoder encodeBool:self.majorUpgrade forKey:SPUUserUpdateStateMajorUpgradeKey]; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + SPUUserUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; + BOOL userInitiated = [decoder decodeBoolForKey:SPUUserUpdateStateUserInitiatedKey]; + BOOL majorUpgrade = [decoder decodeBoolForKey:SPUUserUpdateStateMajorUpgradeKey]; + + return [self initWithStage:stage userInitiated:userInitiated majorUpgrade:majorUpgrade]; +} + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + @end diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h index 77f7a017..b368c6a8 100644 --- a/Sparkle/SUAppcastItem+Private.h +++ b/Sparkle/SUAppcastItem+Private.h @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface SUAppcastItem (Private) +@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; From f671b82e50c3844ccf1a102187ae0ff126809021 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 22:53:58 -0700 Subject: [PATCH 07/17] Test against SPUUserUpdateStageInformational --- Sparkle/SUUpdateAlert.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 8cca75b4..c9d5581b 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -92,7 +92,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE _completionBlock = [block copy]; SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; - _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && !item.isInformationOnlyUpdate; + _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && state.stage != SPUUserUpdateStageInformational; [self setShouldCascadeWindows:NO]; } return self; @@ -328,7 +328,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.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:)]; } @@ -425,7 +425,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.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]) { if (self.state.stage == SPUUserUpdateStageNotDownloaded) { From 59fbd37bb1009c73ae6ed31cbb4ef812277743f2 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 23:03:05 -0700 Subject: [PATCH 08/17] Re-title skip button when update is a major one --- Sparkle/Base.lproj/Sparkle.strings | 3 +++ Sparkle/SUUpdateAlert.m | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 71b1c504..4acaed45 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -98,6 +98,9 @@ without a download but with a URL. */ "Learn More..." = "Learn More…"; +/* When the update to download or install is a major (usually paid) one */ +"Skip Major Upgrade" = "Skip Major Upgrade"; + /* the unit for megabytes */ "MB" = "MB"; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index c9d5581b..1d94d12b 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -369,6 +369,10 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We should be explicit that the update will be installed on quit self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); } + + if (self.state.majorUpgrade) { + self.skipButton.title = SULocalizedString(@"Skip Major Upgrade", nil); + } if ([self.updateItem isCriticalUpdate]) { self.skipButton.hidden = YES; From 1f9d76bc13eb482a85feee4115ae81719d4f9bcb Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 May 2021 23:16:01 -0700 Subject: [PATCH 09/17] Retitle install button to "Install Upgrade" for major updates --- Sparkle/Base.lproj/Sparkle.strings | 3 +++ Sparkle/SUUpdateAlert.m | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 4acaed45..2eed321e 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -101,6 +101,9 @@ /* When the update to download or install is a major (usually paid) one */ "Skip Major Upgrade" = "Skip Major Upgrade"; +/* When the update to download or install is a major (usually paid) one */ +"Install Upgrade" = "Install Upgrade"; + /* the unit for megabytes */ "MB" = "MB"; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 1d94d12b..6edcf976 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -368,6 +368,9 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We should be explicit that the update will be installed on quit self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); + } else if (self.state.majorUpgrade) { + // Use "upgrade" instead of "update" to signify a major change + self.installButton.title = SULocalizedString(@"Install Upgrade", nil); } if (self.state.majorUpgrade) { From e91ae897e7f7a98b6f2b3ef3ce88c7b72b40d3ed Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 14 May 2021 18:28:32 -0700 Subject: [PATCH 10/17] Add method to compare two minimum autoupdate versions --- Sparkle/SPUSkippedUpdate.h | 2 ++ Sparkle/SPUSkippedUpdate.m | 18 +++++++++++++++++- Sparkle/SUAppcastDriver.m | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h index 0e647301..9dfe60d6 100644 --- a/Sparkle/SPUSkippedUpdate.h +++ b/Sparkle/SPUSkippedUpdate.h @@ -26,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN + (void)clearSkippedUpdatesForHost:(SUHost *)host; + (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host; ++ (BOOL)minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion isEqual:(NSString * _Nullable)minimumAutoupdateVersion2; + @property (nonatomic, readonly) NSString *version; @property (nonatomic, readonly, nullable) NSString *minimumAutoupdateVersion; diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m index 1c732c96..b2f66d49 100644 --- a/Sparkle/SPUSkippedUpdate.m +++ b/Sparkle/SPUSkippedUpdate.m @@ -94,6 +94,22 @@ [host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; } ++ (BOOL)minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion isEqual:(NSString * _Nullable)minimumAutoupdateVersion2 +{ + // Both are not provided + if (minimumAutoupdateVersion == nil && minimumAutoupdateVersion2 == nil) { + return YES; + } + + // One of them is not provided + if (minimumAutoupdateVersion == nil || minimumAutoupdateVersion2 == nil) { + return NO; + } + + // Both are provided + return [minimumAutoupdateVersion isEqualToString:(NSString * _Nonnull)minimumAutoupdateVersion2]; +} + + (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host { NSArray *currentSkippedUpdates = [self skippedUpdatesForHost:host]; @@ -104,7 +120,7 @@ for (SPUSkippedUpdate *skippedUpdate in currentSkippedUpdates) { NSString *skippedUpdateMinimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; - if ((updateItemMinimumAutoupdateVersion == nil && skippedUpdateMinimumAutoupdateVersion == nil) || (skippedUpdateMinimumAutoupdateVersion != nil && [updateItemMinimumAutoupdateVersion isEqualToString:skippedUpdateMinimumAutoupdateVersion])) { + if ([self minimumAutoupdateVersion:updateItemMinimumAutoupdateVersion isEqual:skippedUpdateMinimumAutoupdateVersion]) { // On same train, skip adding this old update // It will be replaced by the new skipped update we will be adding continue; diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index f2409357..afaaa6bd 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -338,7 +338,7 @@ BOOL hostPassesSkippedMinimumAutoupdateVersion = [self isItemMinimumAutoupdateVersionOK:skippedMinimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]; - if (!hostPassesSkippedMinimumAutoupdateVersion && itemMinimumAutoupdateVersion != nil && [skippedMinimumAutoupdateVersion isEqualToString:itemMinimumAutoupdateVersion]) { + if (!hostPassesSkippedMinimumAutoupdateVersion && [SPUSkippedUpdate minimumAutoupdateVersion:itemMinimumAutoupdateVersion isEqual:skippedMinimumAutoupdateVersion]) { // Skipped update is on same train as item and we fail minimum autoupdate test // So we skip all updates with the same minimum autoupdate version that we failed return YES; From a630614dc4cc26c643a4786c4942b169761751b8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Thu, 27 May 2021 22:26:23 -0700 Subject: [PATCH 11/17] Use "update" still instead of "upgrade" for major updates --- Sparkle/Base.lproj/Sparkle.strings | 5 +---- Sparkle/SUUpdateAlert.m | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 2eed321e..64cb9285 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -99,10 +99,7 @@ "Learn More..." = "Learn More…"; /* When the update to download or install is a major (usually paid) one */ -"Skip Major Upgrade" = "Skip Major Upgrade"; - -/* When the update to download or install is a major (usually paid) one */ -"Install Upgrade" = "Install Upgrade"; +"Skip Major Update" = "Skip Major Update"; /* the unit for megabytes */ "MB" = "MB"; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 6edcf976..3f72971c 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -368,13 +368,10 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We should be explicit that the update will be installed on quit self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); - } else if (self.state.majorUpgrade) { - // Use "upgrade" instead of "update" to signify a major change - self.installButton.title = SULocalizedString(@"Install Upgrade", nil); } if (self.state.majorUpgrade) { - self.skipButton.title = SULocalizedString(@"Skip Major Upgrade", nil); + self.skipButton.title = SULocalizedString(@"Skip Major Update", nil); } if ([self.updateItem isCriticalUpdate]) { From 7d3c7ae78a3510a482e2641fa66190bb52a957bb Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 28 May 2021 17:23:31 -0700 Subject: [PATCH 12/17] Add alert confirmation for skipping major upgrades --- Sparkle/Base.lproj/Sparkle.strings | 15 ++++++++++++--- Sparkle/SUUpdateAlert.m | 22 +++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 64cb9285..041b8946 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -91,6 +91,18 @@ /* Take care not to overflow the status window. */ "Installing update..." = "Installing update…"; +/* Title confirmation for skipping major upgrade and future updates */ +"Do you want to Skip this Upgrade?" = "Do you want to Skip this Upgrade?"; + +/* Confirmation message for skipping major upgrade and future updates */ +"Skipping this major upgrade will opt out of notifications for future updates." = "Skipping this major upgrade will opt out of notifications for future updates."; + +/* Skipping major upgrade */ +"Skip Upgrade" = "Skip Upgrade"; + +/* Not skipping a major upgrade */ +"Don't Skip" = "Don't Skip"; + /* the unit for kilobytes */ "KB" = "KB"; @@ -98,9 +110,6 @@ without a download but with a URL. */ "Learn More..." = "Learn More…"; -/* When the update to download or install is a major (usually paid) one */ -"Skip Major Update" = "Skip Major Update"; - /* the unit for megabytes */ "MB" = "MB"; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 3f72971c..27050245 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -138,7 +138,23 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (IBAction)skipThisVersion:(id)__unused sender { - [self endWithSelection:SPUUserUpdateChoiceSkip]; + if (self.state.majorUpgrade) { + NSAlert *alert = [[NSAlert alloc] init]; + alert.alertStyle = NSAlertStyleInformational; + alert.informativeText = SULocalizedString(@"Skipping this major upgrade will opt out of notifications for future updates.", nil); + alert.messageText = SULocalizedString(@"Do you want to Skip this Upgrade?", nil); + + [alert addButtonWithTitle:SULocalizedString(@"Skip Upgrade", nil)]; + [alert addButtonWithTitle:SULocalizedString(@"Don't Skip", nil)]; + + [alert beginSheetModalForWindow:(NSWindow * _Nonnull)self.window completionHandler:^(NSModalResponse response) { + if (response == NSAlertFirstButtonReturn) { + [self endWithSelection:SPUUserUpdateChoiceSkip]; + } + }]; + } else { + [self endWithSelection:SPUUserUpdateChoiceSkip]; + } } - (IBAction)remindMeLater:(id)__unused sender @@ -369,10 +385,6 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We should be explicit that the update will be installed on quit self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); } - - if (self.state.majorUpgrade) { - self.skipButton.title = SULocalizedString(@"Skip Major Update", nil); - } if ([self.updateItem isCriticalUpdate]) { self.skipButton.hidden = YES; From 17eb15e9d3f06708dae014b7e28ffc20c7f0a3e4 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 28 May 2021 23:11:13 -0700 Subject: [PATCH 13/17] Simplify skipping major updates We now only track one major version to skip and one minor version to skip, instead of an array of potentially growing minor/major versions. --- Sparkle/SPUSkippedUpdate.h | 21 +++-- Sparkle/SPUSkippedUpdate.m | 127 ++++++------------------------- Sparkle/SPUUIBasedUpdateDriver.m | 8 +- Sparkle/SUAppcastDriver.m | 44 +++++------ Sparkle/SUConstants.h | 3 +- Sparkle/SUConstants.m | 3 +- 6 files changed, 64 insertions(+), 142 deletions(-) diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h index 9dfe60d6..2f57e748 100644 --- a/Sparkle/SPUSkippedUpdate.h +++ b/Sparkle/SPUSkippedUpdate.h @@ -13,23 +13,22 @@ NS_ASSUME_NONNULL_BEGIN @class SUHost, SUAppcastItem; /* - A skipped update tracks the version and minimum autoupdate version the user skipped. - Each minimum autoupdate version is tracked as a separate release / train. - The intent is that a user choosing to skip a future major update chooses to skip that train's updates, - but a user choosing to skip a minor update only chooses to skip updates equal or preceding that update. + A skipped update tracks an optional minor version and an optional major version the user may skip. + The minor and major versions are independent versions, so the user can choose to skip at most two separate versions. + The intent is when the user is faced with a major upgrade, they can skip a major version. + Otherwise they can choose to skip a minor version. */ @interface SPUSkippedUpdate : NSObject -- (instancetype)initWithVersion:(NSString *)version minimumAutoupdateVersion:(nullable NSString *)minimumAutoupdateVersion; ++ (nullable SPUSkippedUpdate *)skippedUpdateForHost:(SUHost *)host; -+ (NSArray *)skippedUpdatesForHost:(SUHost *)host; -+ (void)clearSkippedUpdatesForHost:(SUHost *)host; -+ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host; ++ (void)clearSkippedUpdateForHost:(SUHost *)host; -+ (BOOL)minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion isEqual:(NSString * _Nullable)minimumAutoupdateVersion2; ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade; -@property (nonatomic, readonly) NSString *version; -@property (nonatomic, readonly, nullable) NSString *minimumAutoupdateVersion; +// At least one of these version properties will be non-nil +@property (nonatomic, readonly, nullable) NSString *minorVersion; +@property (nonatomic, readonly, nullable) NSString *majorVersion; @end diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m index b2f66d49..d1794f66 100644 --- a/Sparkle/SPUSkippedUpdate.m +++ b/Sparkle/SPUSkippedUpdate.m @@ -14,129 +14,50 @@ #include "AppKitPrevention.h" -#define SKIPPED_UPDATE_TAG_SEPARATOR @";skip;" - @implementation SPUSkippedUpdate -@synthesize version = _version; -@synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion; +@synthesize minorVersion = _minorVersion; +@synthesize majorVersion = _majorVersion; -- (instancetype)initWithVersion:(NSString *)version minimumAutoupdateVersion:(nullable NSString *)minimumAutoupdateVersion +- (instancetype)initWithMinorVersion:(nullable NSString *)minorVersion majorVersion:(nullable NSString *)majorVersion { self = [super init]; if (self != nil) { - _version = [version copy]; - _minimumAutoupdateVersion = [minimumAutoupdateVersion copy]; + _minorVersion = [minorVersion copy]; + _majorVersion = [majorVersion copy]; } return self; } -+ (NSString *)encodeSkippedUpdate:(SPUSkippedUpdate *)skippedUpdate ++ (nullable SPUSkippedUpdate *)skippedUpdateForHost:(SUHost *)host { - NSMutableArray *components = [NSMutableArray array]; + NSString *minorVersion = [host objectForUserDefaultsKey:SUSkippedMinorVersionKey]; + NSString *majorVersion = [host objectForUserDefaultsKey:SUSkippedMajorVersionKey]; - [components addObject:skippedUpdate.version]; - - NSString *minimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; - if (minimumAutoupdateVersion != nil) { - [components addObject:minimumAutoupdateVersion]; - } - - // We encode the version and minimum autoupdate version in a human readable form with our own separator - return [components componentsJoinedByString:SKIPPED_UPDATE_TAG_SEPARATOR]; -} - -+ (nullable instancetype)decodeSkippedUpdateFromString:(id)stringObject -{ - if (![(NSObject *)stringObject isKindOfClass:[NSString class]]) { + if (minorVersion != nil || majorVersion != nil) { + return [[SPUSkippedUpdate alloc] initWithMinorVersion:minorVersion majorVersion:majorVersion]; + } else { return nil; } - - NSString *string = stringObject; - - NSArray *components = [string componentsSeparatedByString:SKIPPED_UPDATE_TAG_SEPARATOR]; - switch (components.count) { - case 1: - return [[self alloc] initWithVersion:components[0] minimumAutoupdateVersion:nil]; - case 2: - return [[self alloc] initWithVersion:components[0] minimumAutoupdateVersion:components[1]]; - default: - return nil; - } } -+ (NSArray *)skippedUpdatesForHost:(SUHost *)host ++ (void)clearSkippedUpdateForHost:(SUHost *)host { - id skippedVersions = [host objectForUserDefaultsKey:SUSkippedVersionKey]; - if ([(NSObject *)skippedVersions isKindOfClass:[NSString class]]) { - // Handle legacy skipped version format with just a single skipped version - SPUSkippedUpdate *skippedUpdate = [SPUSkippedUpdate decodeSkippedUpdateFromString:skippedVersions]; + [host setObject:nil forUserDefaultsKey:SUSkippedMinorVersionKey]; + [host setObject:nil forUserDefaultsKey:SUSkippedMajorVersionKey]; +} + ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade +{ + if (majorUpgrade) { + NSString *majorVersion = updateItem.minimumAutoupdateVersion; + assert(majorVersion != nil); - return (skippedUpdate != nil) ? @[skippedUpdate] : @[]; - } else if ([(NSObject *)skippedVersions isKindOfClass:[NSArray class]]) { - // Handle array of skipped updates - NSMutableArray *skippedUpdates = [NSMutableArray array]; - for (id skippedUpdateObject in skippedVersions) { - SPUSkippedUpdate *skippedUpdate = [SPUSkippedUpdate decodeSkippedUpdateFromString:skippedUpdateObject]; - - if (skippedUpdate != nil) { - [skippedUpdates addObject:skippedUpdate]; - } - } - return [skippedUpdates copy]; + [host setObject:majorVersion forUserDefaultsKey:SUSkippedMajorVersionKey]; } else { - return @[]; + NSString *version = updateItem.versionString; + [host setObject:version forUserDefaultsKey:SUSkippedMinorVersionKey]; } } -+ (void)clearSkippedUpdatesForHost:(SUHost *)host -{ - [host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; -} - -+ (BOOL)minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion isEqual:(NSString * _Nullable)minimumAutoupdateVersion2 -{ - // Both are not provided - if (minimumAutoupdateVersion == nil && minimumAutoupdateVersion2 == nil) { - return YES; - } - - // One of them is not provided - if (minimumAutoupdateVersion == nil || minimumAutoupdateVersion2 == nil) { - return NO; - } - - // Both are provided - return [minimumAutoupdateVersion isEqualToString:(NSString * _Nonnull)minimumAutoupdateVersion2]; -} - -+ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host -{ - NSArray *currentSkippedUpdates = [self skippedUpdatesForHost:host]; - NSMutableArray *newEncodedSkippedUpdates = [NSMutableArray array]; - - NSString *updateItemMinimumAutoupdateVersion = updateItem.minimumAutoupdateVersion; - - for (SPUSkippedUpdate *skippedUpdate in currentSkippedUpdates) { - NSString *skippedUpdateMinimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; - - if ([self minimumAutoupdateVersion:updateItemMinimumAutoupdateVersion isEqual:skippedUpdateMinimumAutoupdateVersion]) { - // On same train, skip adding this old update - // It will be replaced by the new skipped update we will be adding - continue; - } - - // Add everything else that is on a different train - // We should only have an update per train in skipped updates we store/load - [newEncodedSkippedUpdates addObject:[SPUSkippedUpdate encodeSkippedUpdate:skippedUpdate]]; - } - - // Always add the new skipped update - SPUSkippedUpdate *newSkippedUpdate = [[SPUSkippedUpdate alloc] initWithVersion:updateItem.versionString minimumAutoupdateVersion:updateItemMinimumAutoupdateVersion]; - - [newEncodedSkippedUpdates addObject:[SPUSkippedUpdate encodeSkippedUpdate:newSkippedUpdate]]; - - [host setObject:[newEncodedSkippedUpdates copy] forUserDefaultsKey:SUSkippedVersionKey]; -} - @end diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index a0e8841a..4c62a506 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -164,7 +164,7 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { if (self.userInitiated) { - [SPUSkippedUpdate clearSkippedUpdatesForHost:self.host]; + [SPUSkippedUpdate clearSkippedUpdateForHost:self.host]; } id updaterDelegate = self.updaterDelegate; @@ -180,7 +180,9 @@ stage = SPUUserUpdateStageNotDownloaded; } - SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:preventsAutoupdate]; + BOOL majorUpgrade = preventsAutoupdate; + + SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -212,7 +214,7 @@ break; } case SPUUserUpdateChoiceSkip: { - [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; + [SPUSkippedUpdate skipUpdate:updateItem host:self.host majorUpgrade:majorUpgrade]; if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index afaaa6bd..61358cc0 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -169,13 +169,13 @@ NSNumber *phasedUpdateGroup = background ? @([SUPhasedUpdateGroupInfo updateGroupForHost:self.host]) : nil; - NSArray *skippedUpdates = background ? [SPUSkippedUpdate skippedUpdatesForHost:self.host] : @[]; + SPUSkippedUpdate *skippedUpdate = background ? [SPUSkippedUpdate skippedUpdateForHost:self.host] : nil; // First filter out min/max OS version and see if there's an update that passes // the minimum autoupdate version. We filter out updates that fail the minimum // autoupdate version test because we have a preference over minor updates that can be // downloaded and installed with less disturbance - SUAppcast *passesMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdates:skippedUpdates hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:YES]; + SUAppcast *passesMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdate:skippedUpdate hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:YES]; SUAppcastItem *secondaryItemPassesMinimumAutoupdate = nil; SUAppcastItem *primaryItemPassesMinimumAutoupdate = [self retrieveBestAppcastItemFromAppcast:passesMinimumAutoupdateAppcast versionComparator:applicationVersionComparator secondaryUpdate:&secondaryItemPassesMinimumAutoupdate]; @@ -185,7 +185,7 @@ SUAppcastItem *finalPrimaryItem; SUAppcastItem *finalSecondaryItem = nil; if (![self isItemNewer:primaryItemPassesMinimumAutoupdate]) { - SUAppcast *failsMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdates:skippedUpdates hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:NO]; + SUAppcast *failsMinimumAutoupdateAppcast = [[self class] filterSupportedAppcast:macOSAppcast phasedUpdateGroup:phasedUpdateGroup skippedUpdate:skippedUpdate hostVersion:self.host.version versionComparator:applicationVersionComparator testOSVersion:YES testMinimumAutoupdateVersion:NO]; finalPrimaryItem = [self retrieveBestAppcastItemFromAppcast:failsMinimumAutoupdateAppcast versionComparator:applicationVersionComparator secondaryUpdate:&finalSecondaryItem]; } else { @@ -228,10 +228,12 @@ } // This method is used by unit tests -+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdates:(NSArray *)skippedUpdates 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 * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion { NSDate *currentDate = [NSDate date]; + BOOL hostPassesSkippedMajorVersion = [self isItemMinimumAutoupdateVersionOK:skippedUpdate.majorVersion hostVersion:hostVersion versionComparator:versionComparator]; + return [appcast copyByFilteringItems:^(SUAppcastItem *item) { BOOL passesOSVersion = (!testOSVersion || [self isItemMinimumAndMaximumOperatingSystemVersionOK:item]); @@ -239,7 +241,7 @@ BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || hostVersion == nil || versionComparator == nil || [self isItemMinimumAutoupdateVersionOK:item.minimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]); - BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdates:skippedUpdates hostVersion:hostVersion versionComparator:versionComparator]); + BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdate:skippedUpdate hostPassesSkippedMajorVersion:hostPassesSkippedMajorVersion versionComparator:versionComparator]); return (BOOL)(passesOSVersion && passesPhasedRollout && passesMinimumAutoupdateVersion && passesSkippedUpdates); }]; @@ -328,26 +330,22 @@ return ui != nil && [[self versionComparator] compareVersion:self.host.version toVersion:ui.versionString] == NSOrderedAscending; } -+ (BOOL)item:(SUAppcastItem *)ui containsSkippedUpdates:(NSArray *)skippedUpdates hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator ++ (BOOL)item:(SUAppcastItem *)ui containsSkippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostPassesSkippedMajorVersion:(BOOL)hostPassesSkippedMajorVersion versionComparator:(id)versionComparator { - NSString *itemVersion = ui.versionString; - NSString *itemMinimumAutoupdateVersion = ui.minimumAutoupdateVersion; + NSString *skippedMajorVersion = skippedUpdate.majorVersion; - for (SPUSkippedUpdate *skippedUpdate in skippedUpdates) { - NSString *skippedMinimumAutoupdateVersion = skippedUpdate.minimumAutoupdateVersion; - - BOOL hostPassesSkippedMinimumAutoupdateVersion = [self isItemMinimumAutoupdateVersionOK:skippedMinimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]; - - if (!hostPassesSkippedMinimumAutoupdateVersion && [SPUSkippedUpdate minimumAutoupdateVersion:itemMinimumAutoupdateVersion isEqual:skippedMinimumAutoupdateVersion]) { - // Skipped update is on same train as item and we fail minimum autoupdate test - // So we skip all updates with the same minimum autoupdate version that we failed - return YES; - } - - if (hostPassesSkippedMinimumAutoupdateVersion && [versionComparator compareVersion:skippedUpdate.version toVersion:itemVersion] != NSOrderedAscending) { - // If host passes train of this skipped version and skipped version >= item version, then skip the update - return YES; - } + if (!hostPassesSkippedMajorVersion && skippedMajorVersion != nil && [versionComparator compareVersion:skippedMajorVersion toVersion:ui.versionString] != NSOrderedDescending) { + // Item is on a greater or equal version than a major version we've skipped + // So we skip this item + return YES; + } + + NSString *skippedMinorVersion = skippedUpdate.minorVersion; + + if (skippedMinorVersion != nil && [versionComparator compareVersion:skippedMinorVersion toVersion:ui.versionString] != NSOrderedAscending) { + // Item is on a less or equal version than a minor version we've skipped + // So we skip this item + return YES; } return NO; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 5cca1270..46327f0c 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -40,7 +40,8 @@ extern NSString *const SUFeedURLKey; extern NSString *const SUHasLaunchedBeforeKey; extern NSString *const SURelaunchHostBundleKey; extern NSString *const SUShowReleaseNotesKey; -extern NSString *const SUSkippedVersionKey; +extern NSString *const SUSkippedMinorVersionKey; +extern NSString *const SUSkippedMajorVersionKey; extern NSString *const SUScheduledCheckIntervalKey; extern NSString *const SULastCheckTimeKey; extern NSString *const SUExpectsDSASignatureKey; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index d46d1dd2..94a4fda4 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -36,7 +36,8 @@ NSString *const SUFeedURLKey = @"SUFeedURL"; NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore"; NSString *const SURelaunchHostBundleKey = @"SURelaunchHostBundle"; NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes"; -NSString *const SUSkippedVersionKey = @"SUSkippedVersion"; +NSString *const SUSkippedMinorVersionKey = @"SUSkippedVersion"; +NSString *const SUSkippedMajorVersionKey = @"SUSkippedMajorVersion"; NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval"; NSString *const SULastCheckTimeKey = @"SULastCheckTime"; NSString *const SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; From 8e466eecc8b47c260ba90f4c2c5814b36651c7d7 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 28 May 2021 23:28:44 -0700 Subject: [PATCH 14/17] Fix unit tests for skipped updates --- Sparkle/SPUSkippedUpdate.h | 3 + Sparkle/SPUSkippedUpdate.m | 2 + Tests/SUAppcastTest.swift | 73 +++++++--------------- Tests/Sparkle Unit Tests-Bridging-Header.h | 2 +- 4 files changed, 28 insertions(+), 52 deletions(-) diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h index 2f57e748..40259373 100644 --- a/Sparkle/SPUSkippedUpdate.h +++ b/Sparkle/SPUSkippedUpdate.h @@ -26,6 +26,9 @@ NS_ASSUME_NONNULL_BEGIN + (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade; +// At least one of minorVersion or majorVersion should be non-nil +- (instancetype)initWithMinorVersion:(nullable NSString *)minorVersion majorVersion:(nullable NSString *)majorVersion; + // At least one of these version properties will be non-nil @property (nonatomic, readonly, nullable) NSString *minorVersion; @property (nonatomic, readonly, nullable) NSString *majorVersion; diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m index d1794f66..e8791413 100644 --- a/Sparkle/SPUSkippedUpdate.m +++ b/Sparkle/SPUSkippedUpdate.m @@ -25,6 +25,8 @@ if (self != nil) { _minorVersion = [minorVersion copy]; _majorVersion = [majorVersion copy]; + + assert(_minorVersion != nil || _majorVersion != nil); } return self; } diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 0ef19e66..dfc8110a 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -45,7 +45,7 @@ class SUAppcastTest: XCTestCase { XCTAssertFalse(items[3].isCriticalUpdate) // Test best appcast item & a delta update item - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) let supportedAppcastItems = supportedAppcast.items @@ -88,7 +88,7 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "1.0" - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(1, supportedAppcast.items.count) @@ -101,7 +101,7 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.0" - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -114,7 +114,7 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.5" - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -129,18 +129,18 @@ class SUAppcastTest: XCTestCase { // There should be no items if 2.0 is skipped from 1.0 and 3.0 fails minimum autoupdate version do { - let skippedUpdate = SPUSkippedUpdate(version: "2.0", minimumAutoupdateVersion: nil) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.0", majorVersion: nil) - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(0, supportedAppcast.items.count) } // Try again but allowing minimum autoupdate version to fail do { - let skippedUpdate = SPUSkippedUpdate(version: "2.0", minimumAutoupdateVersion: nil) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.0", majorVersion: nil) - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(1, supportedAppcast.items.count) @@ -151,9 +151,9 @@ class SUAppcastTest: XCTestCase { // Allow minimum autoupdate version to fail and only skip 3.0 do { - let skippedUpdate = SPUSkippedUpdate(version: "3.0", minimumAutoupdateVersion: "2.0") + let skippedUpdate = SPUSkippedUpdate(minorVersion: nil, majorVersion: "3.0") - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(1, supportedAppcast.items.count) @@ -164,48 +164,19 @@ class SUAppcastTest: XCTestCase { // Allow minimum autoupdate version to fail skipping both 2.0 and 3.0 do { - let skippedUpdate = SPUSkippedUpdate(version: "3.0", minimumAutoupdateVersion: "2.0") - let skippedUpdate2 = SPUSkippedUpdate(version: "2.0", minimumAutoupdateVersion: nil) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.0", majorVersion: "3.0") - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate, skippedUpdate2], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(0, supportedAppcast.items.count) } - // Allow minimum autoupdate version to fail and only skip "2.99.9" which we will treat as same train on 3.0 - // This should implicitly only skip 3.0 - do { - let skippedUpdate = SPUSkippedUpdate(version: "2.99.9", minimumAutoupdateVersion: "2.0") - - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) - - XCTAssertEqual(1, supportedAppcast.items.count) - - let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) - - XCTAssertEqual(bestAppcastItem.versionString, "2.0") - } - - // Allow minimum autoupdate version to fail and only skip "3.1" which we will treat as same train on 3.0 - // This should implicitly only skip 3.0 - do { - let skippedUpdate = SPUSkippedUpdate(version: "3.1", minimumAutoupdateVersion: "2.0") - - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) - - XCTAssertEqual(1, supportedAppcast.items.count) - - let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: supportedAppcast.items, getDeltaItem: nil, withHostVersion: hostVersion, comparator: versionComparator) - - XCTAssertEqual(bestAppcastItem.versionString, "2.0") - } - // Allow minimum autoupdate version to fail and only skip "2.5" // This should implicitly only skip 2.0 do { - let skippedUpdate = SPUSkippedUpdate(version: "2.5", minimumAutoupdateVersion: nil) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.5", majorVersion: nil) - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(1, supportedAppcast.items.count) @@ -216,9 +187,9 @@ class SUAppcastTest: XCTestCase { // This should not skip anything but require passing minimum autoupdate version do { - let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: nil) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "1.5", majorVersion: nil) - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(1, supportedAppcast.items.count) @@ -229,9 +200,9 @@ class SUAppcastTest: XCTestCase { // This should not skip anything but allow failing minimum autoupdate version do { - let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: nil) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "1.5", majorVersion: nil) - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(2, supportedAppcast.items.count) @@ -242,9 +213,9 @@ class SUAppcastTest: XCTestCase { // This should not skip anything but require passing minimum autoupdate version do { - let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: "1.0") + let skippedUpdate = SPUSkippedUpdate(minorVersion: "1.5", majorVersion: "1.0") - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(1, supportedAppcast.items.count) @@ -255,9 +226,9 @@ class SUAppcastTest: XCTestCase { // This should not skip anything but allow failing minimum autoupdate version do { - let skippedUpdate = SPUSkippedUpdate(version: "1.5", minimumAutoupdateVersion: "1.0") + let skippedUpdate = SPUSkippedUpdate(minorVersion: "1.5", majorVersion: "1.0") - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdates: [skippedUpdate], hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(2, supportedAppcast.items.count) diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index 7dac6523..a4376798 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -39,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 skippedUpdates:(NSArray *)skippedUpdates 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 * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; @end From e0a414909cb158cc5cffdfb3f6d33a0d861ea041 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 28 May 2021 23:56:04 -0700 Subject: [PATCH 15/17] Re-word skip upgrade title confirmation --- Sparkle/Base.lproj/Sparkle.strings | 2 +- Sparkle/SUUpdateAlert.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 041b8946..497a4269 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -92,7 +92,7 @@ "Installing update..." = "Installing update…"; /* Title confirmation for skipping major upgrade and future updates */ -"Do you want to Skip this Upgrade?" = "Do you want to Skip this Upgrade?"; +"Are you sure you want to skip this upgrade?" = "Are you sure you want to skip this upgrade?"; /* Confirmation message for skipping major upgrade and future updates */ "Skipping this major upgrade will opt out of notifications for future updates." = "Skipping this major upgrade will opt out of notifications for future updates."; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 27050245..1855b88c 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -142,7 +142,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE NSAlert *alert = [[NSAlert alloc] init]; alert.alertStyle = NSAlertStyleInformational; alert.informativeText = SULocalizedString(@"Skipping this major upgrade will opt out of notifications for future updates.", nil); - alert.messageText = SULocalizedString(@"Do you want to Skip this Upgrade?", nil); + alert.messageText = SULocalizedString(@"Are you sure you want to skip this upgrade?", nil); [alert addButtonWithTitle:SULocalizedString(@"Skip Upgrade", nil)]; [alert addButtonWithTitle:SULocalizedString(@"Don't Skip", nil)]; From 0cdb0976ef3c0a13e8cb21fce01b79fdf265bb33 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 29 May 2021 07:50:30 -0700 Subject: [PATCH 16/17] Don't hide skipping button for major upgrades if update is critical --- Sparkle/SUUpdateAlert.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 1855b88c..a3e95b49 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -386,7 +386,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]) { + if ([self.updateItem isCriticalUpdate] && !self.state.majorUpgrade) { self.skipButton.hidden = YES; self.laterButton.hidden = YES; } From 79cd07fc7035e1854c789613be727519d7af2dd1 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 29 May 2021 07:52:50 -0700 Subject: [PATCH 17/17] Use alerts instead of notifications --- Sparkle/Base.lproj/Sparkle.strings | 2 +- Sparkle/SUUpdateAlert.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 497a4269..4b305e80 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -95,7 +95,7 @@ "Are you sure you want to skip this upgrade?" = "Are you sure you want to skip this upgrade?"; /* Confirmation message for skipping major upgrade and future updates */ -"Skipping this major upgrade will opt out of notifications for future updates." = "Skipping this major upgrade will opt out of notifications for future updates."; +"Skipping this major upgrade will opt out of alerts for future updates." = "Skipping this major upgrade will opt out of alerts for future updates."; /* Skipping major upgrade */ "Skip Upgrade" = "Skip Upgrade"; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index a3e95b49..c2f51ac2 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -141,7 +141,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE if (self.state.majorUpgrade) { NSAlert *alert = [[NSAlert alloc] init]; alert.alertStyle = NSAlertStyleInformational; - alert.informativeText = SULocalizedString(@"Skipping this major upgrade will opt out of notifications for future updates.", nil); + alert.informativeText = SULocalizedString(@"Skipping this major upgrade will opt out of alerts for future updates.", nil); alert.messageText = SULocalizedString(@"Are you sure you want to skip this upgrade?", nil); [alert addButtonWithTitle:SULocalizedString(@"Skip Upgrade", nil)];