diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index afda196c..95e682b2 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -284,7 +284,14 @@ 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 */; }; - 726DF88E1C84277600188804 /* SPUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 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 */; }; + 7269E4982648D3460088C213 /* SPUSkippedUpdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E493264798200088C213 /* SPUSkippedUpdate.m */; }; + 7269E49A2648F7C00088C213 /* SPUUserUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */; }; + 7269E49B2648F7C00088C213 /* SPUUserUpdateState.m in Sources */ = {isa = PBXBuildFile; fileRef = 7269E4992648F7C00088C213 /* SPUUserUpdateState.m */; }; + 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUUserUpdateState.h */; settings = {ATTRIBUTES = (Public, ); }; }; 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, ); }; }; @@ -380,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 */; }; @@ -1244,8 +1251,12 @@ 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 = ""; }; + 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; }; @@ -1934,6 +1945,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 */, @@ -2135,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"; @@ -2384,11 +2399,12 @@ 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 */, 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 */, @@ -2429,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 */, @@ -2438,6 +2454,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 */, @@ -3336,6 +3353,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 */, @@ -3519,6 +3537,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 */, @@ -3550,6 +3569,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 */, @@ -3651,6 +3671,8 @@ 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 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/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 71b1c504..4b305e80 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 */ +"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 alerts for future updates." = "Skipping this major upgrade will opt out of alerts 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"; 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/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h new file mode 100644 index 00000000..40259373 --- /dev/null +++ b/Sparkle/SPUSkippedUpdate.h @@ -0,0 +1,38 @@ +// +// 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; + +/* + 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 + ++ (nullable SPUSkippedUpdate *)skippedUpdateForHost:(SUHost *)host; + ++ (void)clearSkippedUpdateForHost:(SUHost *)host; + ++ (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; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m new file mode 100644 index 00000000..e8791413 --- /dev/null +++ b/Sparkle/SPUSkippedUpdate.m @@ -0,0 +1,65 @@ +// +// 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" + +@implementation SPUSkippedUpdate + +@synthesize minorVersion = _minorVersion; +@synthesize majorVersion = _majorVersion; + +- (instancetype)initWithMinorVersion:(nullable NSString *)minorVersion majorVersion:(nullable NSString *)majorVersion +{ + self = [super init]; + if (self != nil) { + _minorVersion = [minorVersion copy]; + _majorVersion = [majorVersion copy]; + + assert(_minorVersion != nil || _majorVersion != nil); + } + return self; +} + ++ (nullable SPUSkippedUpdate *)skippedUpdateForHost:(SUHost *)host +{ + NSString *minorVersion = [host objectForUserDefaultsKey:SUSkippedMinorVersionKey]; + NSString *majorVersion = [host objectForUserDefaultsKey:SUSkippedMajorVersionKey]; + + if (minorVersion != nil || majorVersion != nil) { + return [[SPUSkippedUpdate alloc] initWithMinorVersion:minorVersion majorVersion:majorVersion]; + } else { + return nil; + } +} + ++ (void)clearSkippedUpdateForHost:(SUHost *)host +{ + [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); + + [host setObject:majorVersion forUserDefaultsKey:SUSkippedMajorVersionKey]; + } else { + NSString *version = updateItem.versionString; + [host setObject:version forUserDefaultsKey:SUSkippedMinorVersionKey]; + } +} + +@end 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 77b5a13d..4c62a506 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -17,6 +17,8 @@ #import "SPUDownloadData.h" #import "SPUResumableUpdate.h" #import "SPUDownloadDriver.h" +#import "SPUSkippedUpdate.h" +#import "SPUUserUpdateState+Private.h" #include "AppKitPrevention.h" @@ -161,175 +163,102 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate { + if (self.userInitiated) { + [SPUSkippedUpdate clearSkippedUpdateForHost: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; - } - - [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: { - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - - 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: { - [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; - - 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: { - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - - 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; + } + + 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(), ^{ - [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 majorUpgrade:majorUpgrade]; + + 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]; @@ -364,22 +293,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..684cf12d 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.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. * * @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.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 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..90e732c4 --- /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 majorUpgrade:(BOOL)majorUpgrade; + +@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..b1be0c91 --- /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 majorUpgrade; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUUserUpdateState_h */ diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUserUpdateState.m new file mode 100644 index 00000000..935f6766 --- /dev/null +++ b/Sparkle/SPUUserUpdateState.m @@ -0,0 +1,57 @@ +// +// 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" + +#define SPUUserUpdateStateStageKey @"SPUUserUpdateStateStage" +#define SPUUserUpdateStateUserInitiatedKey @"SPUUserUpdateStateUserInitiated" +#define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" + +@implementation SPUUserUpdateState + +@synthesize stage = _stage; +@synthesize userInitiated = _userInitiated; +@synthesize majorUpgrade = _majorUpgrade; + +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade +{ + self = [super init]; + if (self != nil) { + _stage = stage; + _userInitiated = userInitiated; + _majorUpgrade = majorUpgrade; + } + 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/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 2613bfab..61358cc0 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; + 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 skippedVersion:skippedVersion 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]; @@ -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 skippedUpdate:skippedUpdate 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,18 +228,20 @@ } // 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 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]); 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 containsSkippedUpdate:skippedUpdate hostPassesSkippedMajorVersion:hostPassesSkippedMajorVersion versionComparator:versionComparator]); return (BOOL)(passesOSVersion && passesPhasedRollout && passesMinimumAutoupdateVersion && passesSkippedUpdates); }]; @@ -300,10 +303,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 +330,25 @@ 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 containsSkippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostPassesSkippedMajorVersion:(BOOL)hostPassesSkippedMajorVersion versionComparator:(id)versionComparator { - if (skippedVersion == nil) { return NO; } + NSString *skippedMajorVersion = skippedUpdate.majorVersion; - return [versionComparator compareVersion:ui.versionString toVersion:(NSString * _Nonnull)skippedVersion] != NSOrderedDescending; + 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; } + (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate 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; 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"; 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..c2f51ac2 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) { @@ -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; @@ -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 alerts for future updates.", 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)]; + + [alert beginSheetModalForWindow:(NSWindow * _Nonnull)self.window completionHandler:^(NSModalResponse response) { + if (response == NSAlertFirstButtonReturn) { + [self endWithSelection:SPUUserUpdateChoiceSkip]; + } + }]; + } else { + [self endWithSelection:SPUUserUpdateChoiceSkip]; + } } - (IBAction)remindMeLater:(id)__unused sender @@ -328,7 +344,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:)]; } @@ -362,7 +378,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); @@ -370,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; } @@ -400,7 +416,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]]; } @@ -425,16 +441,16 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We display a different summary depending on if it's an "info-only" item, or a "critical update" item, or if we've already downloaded the update and just need to relaunch NSString *finalString = nil; - if (self.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 == 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/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index dfe63735..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, skippedVersion: nil, 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, skippedVersion: nil, 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, skippedVersion: nil, 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, skippedVersion: nil, 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,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(minorVersion: "2.0", majorVersion: nil) + + 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 supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedVersion: "2.0", hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) + let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.0", majorVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: skippedUpdate, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) XCTAssertEqual(1, supportedAppcast.items.count) @@ -144,8 +148,95 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual(bestAppcastItem.versionString, "3.0") } + + // Allow minimum autoupdate version to fail and only skip 3.0 + do { + let skippedUpdate = SPUSkippedUpdate(minorVersion: nil, majorVersion: "3.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: 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(minorVersion: "2.0", majorVersion: "3.0") + + 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.5" + // This should implicitly only skip 2.0 + do { + let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.5", majorVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: 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(minorVersion: "1.5", majorVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: 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(minorVersion: "1.5", majorVersion: nil) + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: 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(minorVersion: "1.5", majorVersion: "1.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: 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(minorVersion: "1.5", majorVersion: "1.0") + + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: 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..a4376798 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 skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; @end 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;