From 5ff2d7765ee228a3ea98c480bba9a69792caa4de Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Fri, 16 Apr 2021 13:15:42 +0900 Subject: [PATCH 1/8] Add missing Japanese localization strings that added in #1819. --- Sparkle/ja.lproj/Sparkle.strings | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkle/ja.lproj/Sparkle.strings b/Sparkle/ja.lproj/Sparkle.strings index d2ba179d..32eb2a00 100644 --- a/Sparkle/ja.lproj/Sparkle.strings +++ b/Sparkle/ja.lproj/Sparkle.strings @@ -14,6 +14,12 @@ "%@ %@ is currently the newest version available.\n(You are currently running version %@.)" = "%1$@ %2$@は現在入手できる最新バージョンです。\n(現在使用中のバージョンは%3$@です。)"; +"Update Installed" = "アップデートがインストールされました"; + +"%@ is now updated to version %@!" = "%@はバージョン%@にアップデートされました!"; + +"%@ is now updated!" = "%@はアップデートされました!"; + /* Description text for SUUpdateAlert when the update is downloadable. */ "%@ %@ is now available--you have %@. Would you like to download it now?" = "%1$@ %2$@が入手できます(使用中のバージョンは%3$@です)。今すぐダウンロードしますか?"; From e64253be0bfb4313286209ab70507ece3ea71bcc Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 16:34:01 -0700 Subject: [PATCH 2/8] Merge showUpdateFount: methods into single one Handling the different variations with different completion blocks is a pain when ultimately clients want to display a mostly unified user interface. --- Sparkle/SPUAutomaticUpdateDriver.m | 2 +- Sparkle/SPUCoreBasedUpdateDriver.h | 2 +- Sparkle/SPUCoreBasedUpdateDriver.m | 12 +- Sparkle/SPUStandardUserDriver.m | 64 +----- Sparkle/SPUStatusCompletionResults.h | 27 ++- Sparkle/SPUUIBasedUpdateDriver.m | 187 ++++++++++++------ Sparkle/SPUUserDriver.h | 107 +++++----- Sparkle/SUUpdateAlert.h | 6 +- Sparkle/SUUpdateAlert.m | 91 ++------- .../SUInstallUpdateViewController.h | 2 +- .../SUInstallUpdateViewController.m | 10 +- TestApplication/SUPopUpTitlebarUserDriver.m | 56 ++---- sparkle-cli/SPUCommandLineUserDriver.m | 59 +++--- 13 files changed, 285 insertions(+), 340 deletions(-) diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 0515a9d7..7b95bb8f 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -99,7 +99,7 @@ if (self.willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) { __weak SPUAutomaticUpdateDriver *weakSelf = self; installationHandledByDelegate = [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{ - [weakSelf.coreDriver finishInstallationWithResponse:SPUInstallAndRelaunchUpdateNow displayingUserInterface:NO]; + [weakSelf.coreDriver finishInstallationWithResponse:SPUUserUpdateChoiceInstall displayingUserInterface:NO]; }]; } diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 8187bf09..57806ee8 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)clearDownloadedUpdate; -- (void)finishInstallationWithResponse:(SPUInstallUpdateStatus)installUpdateStatus displayingUserInterface:(BOOL)displayingUserInterface; +- (void)finishInstallationWithResponse:(SPUUserUpdateChoice)installUpdateStatus displayingUserInterface:(BOOL)displayingUserInterface; - (void)abortUpdateAndShowNextUpdateImmediately:(BOOL)shouldShowUpdateImmediately error:(nullable NSError *)error; diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index a1695365..68fed439 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -297,16 +297,14 @@ [self.delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently]; } -- (void)finishInstallationWithResponse:(SPUInstallUpdateStatus)installUpdateStatus displayingUserInterface:(BOOL)displayingUserInterface +- (void)finishInstallationWithResponse:(SPUUserUpdateChoice)response displayingUserInterface:(BOOL)displayingUserInterface { - switch (installUpdateStatus) { - case SPUDismissUpdateInstallation: + switch (response) { + case SPUUserUpdateChoiceDismiss: + case SPUUserUpdateChoiceSkip: [self.delegate coreDriverIsRequestingAbortUpdateWithError:nil]; break; - case SPUInstallUpdateNow: - [self.installerDriver installWithToolAndRelaunch:NO displayingUserInterface:displayingUserInterface]; - break; - case SPUInstallAndRelaunchUpdateNow: + case SPUUserUpdateChoiceInstall: [self.installerDriver installWithToolAndRelaunch:YES displayingUserInterface:displayingUserInterface]; break; } diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index a1808635..e962371f 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -28,7 +28,7 @@ @property (nonatomic, weak, nullable, readonly) id delegate; -@property (nonatomic, copy) void (^installUpdateHandler)(SPUInstallUpdateStatus); +@property (nonatomic, copy) void (^installUpdateHandler)(SPUUserUpdateChoice); @property (nonatomic, copy) void (^cancellation)(void); @property (nonatomic) SUStatusController *checkingController; @@ -124,68 +124,24 @@ #pragma mark Update Found -- (void)showUpdateFoundWithAlertHandler:(SUUpdateAlert *(^)(SPUStandardUserDriver *, SUHost *, id))alertHandler userInitiated:(BOOL)userInitiated +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply { + assert(NSThread.isMainThread); + id versionDisplayer = nil; if ([self.delegate respondsToSelector:@selector(standardUserDriverRequestsVersionDisplayer)]) { versionDisplayer = [self.delegate standardUserDriverRequestsVersionDisplayer]; } __weak SPUStandardUserDriver *weakSelf = self; - SUHost *host = self.host; - self.activeUpdateAlert = alertHandler(weakSelf, host, versionDisplayer); + self.activeUpdateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem state:state host:self.host versionDisplayer:versionDisplayer completionBlock:^(SPUUserUpdateChoice choice) { + reply(choice); + weakSelf.activeUpdateAlert = nil; + }]; [self setUpFocusForActiveUpdateAlertWithUserInitiation:userInitiated]; } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply -{ - assert(NSThread.isMainThread); - - [self showUpdateFoundWithAlertHandler:^SUUpdateAlert *(SPUStandardUserDriver *weakSelf, SUHost *host, id versionDisplayer) { - return [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem alreadyDownloaded:NO host:host versionDisplayer:versionDisplayer completionBlock:^(SPUUpdateAlertChoice choice) { - reply(choice); - weakSelf.activeUpdateAlert = nil; - }]; - } userInitiated:userInitiated]; -} - -- (void)showDownloadedUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply -{ - assert(NSThread.isMainThread); - - [self showUpdateFoundWithAlertHandler:^SUUpdateAlert *(SPUStandardUserDriver *weakSelf, SUHost *host, id versionDisplayer) { - return [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem alreadyDownloaded:YES host:host versionDisplayer:versionDisplayer completionBlock:^(SPUUpdateAlertChoice choice) { - reply(choice); - weakSelf.activeUpdateAlert = nil; - }]; - } userInitiated:userInitiated]; -} - -- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply -{ - assert(NSThread.isMainThread); - - [self showUpdateFoundWithAlertHandler:^SUUpdateAlert *(SPUStandardUserDriver *weakSelf, SUHost *host, id versionDisplayer) { - return [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:host versionDisplayer:versionDisplayer resumableCompletionBlock:^(SPUInstallUpdateStatus choice) { - reply(choice); - weakSelf.activeUpdateAlert = nil; - }]; - } userInitiated:userInitiated]; -} - -- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply -{ - assert(NSThread.isMainThread); - - [self showUpdateFoundWithAlertHandler:^SUUpdateAlert *(SPUStandardUserDriver *weakSelf, SUHost *host, id versionDisplayer) { - return [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:host versionDisplayer:versionDisplayer informationalCompletionBlock:^(SPUInformationalUpdateAlertChoice choice) { - reply(choice); - weakSelf.activeUpdateAlert = nil; - }]; - } userInitiated:userInitiated]; -} - - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { assert(NSThread.isMainThread); @@ -205,7 +161,7 @@ #pragma mark Install & Relaunch Update -- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler +- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))installUpdateHandler { assert(NSThread.isMainThread); @@ -222,7 +178,7 @@ - (void)installAndRestart:(id)__unused sender { if (self.installUpdateHandler != nil) { - self.installUpdateHandler(SPUInstallAndRelaunchUpdateNow); + self.installUpdateHandler(SPUUserUpdateChoiceInstall); self.installUpdateHandler = nil; } } diff --git a/Sparkle/SPUStatusCompletionResults.h b/Sparkle/SPUStatusCompletionResults.h index 0283c119..31fd4ae0 100644 --- a/Sparkle/SPUStatusCompletionResults.h +++ b/Sparkle/SPUStatusCompletionResults.h @@ -18,23 +18,40 @@ #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 }; -typedef NS_ENUM(NSInteger, SPUInformationalUpdateAlertChoice) { - SPUDismissInformationalNoticeChoice, - SPUSkipThisInformationalVersionChoice -}; - // Deprecated typedef NS_ENUM(NSUInteger, SPUUserInitiatedCheckStatus) { SPUUserInitiatedCheckDone, diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index a52fcc76..a80c3286 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -108,77 +108,150 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate { id updaterDelegate = self.updaterDelegate; - - if (updateItem.isInformationOnlyUpdate) { - assert(!self.resumingDownloadedUpdate); - assert(!self.resumingInstallingUpdate); + 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 showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) { + [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated state:state reply:^(SPUUserUpdateChoice userChoice) { 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; + + // Rule out invalid choices + SPUUserUpdateChoice validatedChoice; + if ((state == SPUUserUpdateStateInstalling && userChoice == SPUUserUpdateChoiceSkip) || (state == SPUUserUpdateStateInformational && userChoice == SPUUserUpdateChoiceInstall)) { + validatedChoice = SPUUserUpdateChoiceDismiss; + } else { + validatedChoice = userChoice; } - }); - }]; - } 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: - [self.coreDriver extractDownloadedUpdate]; + + 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 inBackground:NO]; + break; + case SPUUserUpdateStateInformational: + assert(false); + break; + } break; - case SPUSkipThisVersionChoice: - [self.coreDriver clearDownloadedUpdate]; + case SPUUserUpdateChoiceSkip: [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]; - 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: - [self.coreDriver downloadUpdateFromAppcastItem:updateItem 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]; + + break; + case SPUUserUpdateChoiceDismiss: + switch (state) { + case SPUUserUpdateStateDownloaded: + case SPUUserUpdateStateNotDownloaded: + case SPUUserUpdateStateInformational: + [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; + [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; + break; + case SPUUserUpdateStateInstalling: + [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; + break; + } + break; } }); }]; } else { - [self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInstallUpdateStatus choice) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - [self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction]; - }); - }]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (updateItem.isInformationOnlyUpdate) { + assert(!self.resumingDownloadedUpdate); + assert(!self.resumingInstallingUpdate); + + [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: + [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]; + 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: + [self.coreDriver downloadUpdateFromAppcastItem:updateItem 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]; + 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 } if ([self.delegate respondsToSelector:@selector(uiDriverDidShowUpdate)]) { @@ -257,9 +330,9 @@ - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)__unused willInstallSilently { if (!willInstallImmediately) { - [self.userDriver showReadyToInstallAndRelaunch:^(SPUInstallUpdateStatus installUpdateStatus) { + [self.userDriver showReadyToInstallAndRelaunch:^(SPUUserUpdateChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - [self.coreDriver finishInstallationWithResponse:installUpdateStatus displayingUserInterface:!self.preventsInstallerInteraction]; + [self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction]; }); }]; } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 17151457..d85c072b 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -68,68 +68,34 @@ SU_EXPORT @protocol SPUUserDriver - (void)dismissUserInitiatedUpdateCheck; /*! - * Show the user a new update is found and can be downloaded and installed + * Show the user a new update is found. * * Let the user know a new update is found and ask them what they want to do. * - * @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 reply - * A reply of SPUInstallUpdateChoice begins downloading and installing the new update. - * - * A reply of SPUInstallLaterChoice reminds the user later of the update, which can act as a "do nothing" option. - * - * A reply of SPUSkipThisVersionChoice skips this particular version and won't bother the user again, - * unless they initiate an update check themselves. - */ -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply; - -/*! - * Show the user a new update has been downloaded and can be installed - * - * This method behaves just like -showUpdateFoundWithAppcastItem:reply: except the update has already been downloaded. - */ -- (void)showDownloadedUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply; - -/*! - * Show the user an update that has started installing can be resumed and installed immediately - * - * Let the user know an update that has already been downloaded and started installing can be resumed. - * Note at this point the update cannot be canceled. - * - * @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 reply - * A reply of SPUInstallAndRelaunchUpdateNow installs the update immediately and relaunches the new update. - * Note: the application is not relaunched if it was not running before installing the update. - * A reply of SPUInstallUpdateNow installs the update immediately but does not relaunch the new update. - * A reply of SPUDismissUpdateInstallation dismisses the update installation. Note the update will attempt to finish installation - * after the application terminates. - */ -- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply; - -/*! - * Show the user a new informational only update has been found - * - * Let the user know a new informational update is found and ask them what they want to do. - * * @param appcastItem The Appcast Item containing information that reflects the new update. - * The infoURL property for the appcastItem may be of interest. * * @param userInitiated A flag indicating whether or not a user initiated this update check * - * @param reply - * A reply of SPUDismissInformationalNoticeChoice dismisses this notice. - * An implementor may decide to invoke another action before dismissing the notice. + * @param state The current state of the update. + * 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. * - * A reply of SPUSkipThisInformationalVersionChoice skips this particular version and won't bother the user again, - * unless they initiate an update check themselves. + * 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"). + * + * 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 upon dismissing until the next time an update is shown to the user. + * If the state is SPUUserUpdateStateInstalling, the installing update is also preserved upon dismissing. In this state however, the update will 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 update cannot be skipped, only dismissed or installed. */ -- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply; +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply; /*! * Show the user the release notes for the new update @@ -220,19 +186,20 @@ SU_EXPORT @protocol SPUUserDriver - (void)showExtractionReceivedProgress:(double)progress; /*! - * Show the user that the update is ready to install + * Show the user that the update is ready to install & relaunch * - * Let the user know that the update is ready and ask them whether they want to install or not. - * Note if the target application is already terminated and an update can be performed silently, this method may not be invoked. + * Let the user know that the update is ready to install and relaunch, and ask them whether they want to proceed. + * Note if the target application has already terminated, this method may not be invoked. * - * @param installUpdateHandler - * A reply of SPUInstallAndRelaunchUpdateNow installs the update immediately and relaunches the new update. - * Note: the application is not relaunched if it was not running before installing the update. - * A reply of SPUInstallUpdateNow installes the update immediately but does not relaunch the new update. - * A reply of SPUDismissUpdateInstallation dismisses the update installation. Note the update may still be installed after - * the application terminates, however there is not a strong guarantee that this will happen. + * @param reply + * A reply of SPUUserUpdateChoiceInstall installs the update and relaunches the new update immediately. + * + * A reply of SPUUserUpdateChoiceDismiss dismisses the update installation for the time being. Note the update may still be installed automatically after + * the application terminates. + * + * A reply of SPUUserUpdateChoiceSkip acts the same as dismissing. This update which has started installing cannot be skipped. */ -- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler; +- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))reply; /*! * Show the user that the update is installing @@ -282,6 +249,10 @@ SU_EXPORT @protocol SPUUserDriver */ @optional +// Clients should move to non-deprecated methods +// Deprecated methods are only (temporarily) kept around for binary compatibility reasons +#if DEBUG + - (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion __deprecated_msg("Implement -showUserInitiatedUpdateCheckWithCancellation: instead"); - (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion __deprecated_msg("Implement -showDownloadInitiatedWithCancellation: instead"); @@ -290,6 +261,16 @@ SU_EXPORT @protocol SPUUserDriver - (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"); + +#endif + @end NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 09f9cbf7..750af172 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -20,11 +20,7 @@ @property (nonatomic, weak, readonly) id versionDisplayer; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item alreadyDownloaded:(BOOL)alreadyDownloaded host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUpdateAlertChoice))block; - -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer resumableCompletionBlock:(void (^)(SPUInstallUpdateStatus))block; - -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer informationalCompletionBlock:(void (^)(SPUInformationalUpdateAlertChoice))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 76fa5705..f4ceefc0 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -33,12 +33,10 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @interface SUUpdateAlert () @property (strong) SUAppcastItem *updateItem; -@property (nonatomic) BOOL alreadyDownloaded; @property (strong) SUHost *host; @property (nonatomic) BOOL allowsAutomaticUpdates; -@property (nonatomic, copy, nullable) void(^completionBlock)(SPUUpdateAlertChoice); -@property (nonatomic, copy, nullable) void(^resumableCompletionBlock)(SPUInstallUpdateStatus); -@property (nonatomic, copy, nullable) void(^informationalCompletionBlock)(SPUInformationalUpdateAlertChoice); +@property (nonatomic, copy, nullable) void(^completionBlock)(SPUUserUpdateChoice); +@property (nonatomic) SPUUserUpdateState state; @property (strong) NSProgressIndicator *releaseNotesSpinner; @@ -60,9 +58,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @implementation SUUpdateAlert @synthesize completionBlock = _completionBlock; -@synthesize alreadyDownloaded = _alreadyDownloaded; -@synthesize resumableCompletionBlock = _resumableCompletionBlock; -@synthesize informationalCompletionBlock = _informationalCompletionBlock; +@synthesize state = _state; @synthesize versionDisplayer; @synthesize updateItem; @@ -84,7 +80,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE @synthesize webView = _webView; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer +- (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,6 +88,9 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE updateItem = item; versionDisplayer = aVersionDisplayer; + _state = state; + _completionBlock = [block copy]; + SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && !item.isInformationOnlyUpdate; [self setShouldCascadeWindows:NO]; @@ -99,45 +98,13 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE return self; } -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item alreadyDownloaded:(BOOL)alreadyDownloaded host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer completionBlock:(void (^)(SPUUpdateAlertChoice))block -{ - self = [self initWithAppcastItem:item host:aHost versionDisplayer:aVersionDisplayer]; - if (self != nil) - { - _completionBlock = [block copy]; - _alreadyDownloaded = alreadyDownloaded; - } - return self; -} - -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer resumableCompletionBlock:(void (^)(SPUInstallUpdateStatus))block -{ - self = [self initWithAppcastItem:item host:aHost versionDisplayer:aVersionDisplayer]; - if (self != nil) - { - _resumableCompletionBlock = [block copy]; - _alreadyDownloaded = YES; - } - return self; -} - -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer informationalCompletionBlock:(void (^)(SPUInformationalUpdateAlertChoice))block -{ - self = [self initWithAppcastItem:item host:aHost versionDisplayer:aVersionDisplayer]; - if (self != nil) - { - _informationalCompletionBlock = [block copy]; - } - return self; -} - - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; } - (void)disableKeyboardShortcutForInstallButton { self.installButton.keyEquivalent = @""; } -- (void)endWithSelection:(SPUUpdateAlertChoice)choice +- (void)endWithSelection:(SPUUserUpdateChoice)choice { [self.webView stopLoading]; [self.webView.view removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused. @@ -146,52 +113,29 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE if (self.completionBlock != nil) { self.completionBlock(choice); self.completionBlock = nil; - } else if (self.resumableCompletionBlock != nil) { - switch (choice) { - case SPUInstallUpdateChoice: - self.resumableCompletionBlock(SPUInstallAndRelaunchUpdateNow); - break; - case SPUInstallLaterChoice: - self.resumableCompletionBlock(SPUDismissUpdateInstallation); - break; - case SPUSkipThisVersionChoice: - abort(); - } - self.resumableCompletionBlock = nil; - } else if (self.informationalCompletionBlock != nil) { - switch (choice) { - case SPUInstallLaterChoice: - self.informationalCompletionBlock(SPUDismissInformationalNoticeChoice); - break; - case SPUSkipThisVersionChoice: - self.informationalCompletionBlock(SPUSkipThisInformationalVersionChoice); - break; - case SPUInstallUpdateChoice: - abort(); - } } } - (IBAction)installUpdate:(id)__unused sender { - [self endWithSelection:SPUInstallUpdateChoice]; + [self endWithSelection:SPUUserUpdateChoiceInstall]; } - (IBAction)openInfoURL:(id)__unused sender { [[NSWorkspace sharedWorkspace] openURL:self.updateItem.infoURL]; - [self endWithSelection:SPUInstallLaterChoice]; + [self endWithSelection:SPUUserUpdateChoiceDismiss]; } - (IBAction)skipThisVersion:(id)__unused sender { - [self endWithSelection:SPUSkipThisVersionChoice]; + [self endWithSelection:SPUUserUpdateChoiceSkip]; } - (IBAction)remindMeLater:(id)__unused sender { - [self endWithSelection:SPUInstallLaterChoice]; + [self endWithSelection:SPUUserUpdateChoiceDismiss]; } - (void)displayReleaseNotes @@ -407,8 +351,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } } - BOOL startedInstalling = (self.resumableCompletionBlock != nil); - if (startedInstalling) { + if (self.state == SPUUserUpdateStateInstalling) { // An already downloaded & resumable update can't be skipped self.skipButton.hidden = YES; @@ -434,7 +377,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (BOOL)windowShouldClose:(NSNotification *) __unused note { - [self endWithSelection:SPUInstallLaterChoice]; + [self endWithSelection:SPUUserUpdateChoiceDismiss]; return YES; } @@ -449,7 +392,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.alreadyDownloaded) + else if (self.state == SPUUserUpdateStateDownloaded || self.state == SPUUserUpdateStateInstalling) { return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [self.host name]]; } @@ -477,13 +420,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.alreadyDownloaded) { + if (self.state == SPUUserUpdateStateNotDownloaded) { 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.alreadyDownloaded) { + if (self.state == SPUUserUpdateStateNotDownloaded) { 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 39320996..0ae16ea2 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 (^)(SPUUpdateAlertChoice))reply; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply; - (void)showReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; diff --git a/TestApplication/SUInstallUpdateViewController.m b/TestApplication/SUInstallUpdateViewController.m index c27a5b56..019860f2 100644 --- a/TestApplication/SUInstallUpdateViewController.m +++ b/TestApplication/SUInstallUpdateViewController.m @@ -14,7 +14,7 @@ @property (nonatomic) IBOutlet NSTextView *textView; @property (nonatomic, readonly) SUAppcastItem *appcastItem; @property (nonatomic, nullable) NSAttributedString *preloadedReleaseNotes; -@property (nonatomic, copy) void (^reply)(SPUUpdateAlertChoice); +@property (nonatomic, copy) void (^reply)(SPUUserUpdateChoice); @property (nonatomic, readonly) BOOL skippable; @end @@ -28,7 +28,7 @@ @synthesize reply = _reply; @synthesize skippable = _skippable; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUpdateAlertChoice))reply +- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply { self = [super initWithNibName:@"SUInstallUpdateViewController" bundle:nil]; if (self != nil) { @@ -109,7 +109,7 @@ - (IBAction)installUpdate:(id)__unused sender { if (self.reply != nil) { - self.reply(SPUInstallUpdateChoice); + self.reply(SPUUserUpdateChoiceInstall); self.reply = nil; } } @@ -117,7 +117,7 @@ - (IBAction)installUpdateLater:(id)__unused sender { if (self.reply != nil) { - self.reply(SPUInstallLaterChoice); + self.reply(SPUUserUpdateChoiceDismiss); self.reply = nil; } } @@ -125,7 +125,7 @@ - (IBAction)skipUpdate:(id)__unused sender { if (self.reply != nil) { - self.reply(SPUSkipThisVersionChoice); + self.reply(SPUUserUpdateChoiceSkip); self.reply = nil; } } diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index e1c28838..0c6ab0f4 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -113,7 +113,7 @@ #pragma mark Update Found -- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUpdateAlertChoice))reply +- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply { NSPopover *popover = [[NSPopover alloc] init]; popover.behavior = NSPopoverBehaviorTransient; @@ -121,7 +121,7 @@ __weak SUPopUpTitlebarUserDriver *weakSelf = self; __block NSButton *actionButton = nil; - SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUpdateAlertChoice choice) { + SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUserUpdateChoice choice) { reply(choice); [popover close]; @@ -139,38 +139,24 @@ }]; } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply { - [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; -} - -- (void)showDownloadedUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply -{ - [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; -} - -- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply -{ - [self showUpdateWithAppcastItem:appcastItem skippable:NO reply:^(SPUUpdateAlertChoice choice) { - switch (choice) { - case SPUInstallUpdateChoice: - reply(SPUInstallAndRelaunchUpdateNow); - break; - case SPUInstallLaterChoice: - reply(SPUDismissUpdateInstallation); - break; - case SPUSkipThisVersionChoice: - abort(); - } - }]; -} - -- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply -{ - // Todo: show user interface for this - NSLog(@"Found info URL: %@", appcastItem.infoURL); - - reply(SPUDismissInformationalNoticeChoice); + switch (state) { + case SPUUserUpdateStateInformational: + // Todo: show user interface for this + NSLog(@"Found info URL: %@", appcastItem.infoURL); + + reply(SPUUserUpdateChoiceDismiss); + + break; + case SPUUserUpdateStateNotDownloaded: + case SPUUserUpdateStateDownloaded: + [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; + break; + case SPUUserUpdateStateInstalling: + [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; + break; + } } - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData @@ -184,10 +170,10 @@ #pragma mark Install & Relaunch Update -- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler +- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))installUpdateHandler { [self addUpdateButtonWithTitle:@"Install & Relaunch" action:^(NSButton *__unused button) { - installUpdateHandler(SPUInstallAndRelaunchUpdateNow); + installUpdateHandler(SPUUserUpdateChoiceInstall); }]; } diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index edf05cbd..e1dbe215 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -105,39 +105,34 @@ } } -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply { - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; - reply(SPUInstallUpdateChoice); -} - -- (void)showDownloadedUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply -{ - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; - reply(SPUInstallUpdateChoice); -} - -- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply -{ - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"resumable"]; - - if (self.deferInstallation) { - if (self.verbose) { - fprintf(stderr, "Deferring Installation.\n"); - } - reply(SPUDismissUpdateInstallation); - } else { - reply(SPUInstallAndRelaunchUpdateNow); + switch (state) { + case SPUUserUpdateStateNotDownloaded: + [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; + reply(SPUUserUpdateChoiceInstall); + break; + case SPUUserUpdateStateDownloaded: + [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; + reply(SPUUserUpdateChoiceInstall); + break; + case SPUUserUpdateStateInstalling: + if (self.deferInstallation) { + if (self.verbose) { + fprintf(stderr, "Deferring Installation.\n"); + } + reply(SPUUserUpdateChoiceDismiss); + } else { + reply(SPUUserUpdateChoiceInstall); + } + break; + case SPUUserUpdateStateInformational: + fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); + reply(SPUUserUpdateChoiceDismiss); + break; } } -- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply -{ - fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); - - reply(SPUDismissInformationalNoticeChoice); -} - - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { if (self.verbose) { @@ -225,15 +220,15 @@ } } -- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler +- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))installUpdateHandler { if (self.deferInstallation) { if (self.verbose) { fprintf(stderr, "Deferring Installation.\n"); } - installUpdateHandler(SPUDismissUpdateInstallation); + installUpdateHandler(SPUUserUpdateChoiceDismiss); } else { - installUpdateHandler(SPUInstallAndRelaunchUpdateNow); + installUpdateHandler(SPUUserUpdateChoiceInstall); } } From ab9ffdb90180604310670342ecd720a2e350b50f Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 16:40:33 -0700 Subject: [PATCH 3/8] Rename SPUUserUpdateStateNotDownloaded to SPUUserUpdateStateNew Update documentation too. Fix test app trying to make installable update skippable. --- Sparkle/SPUStatusCompletionResults.h | 2 +- Sparkle/SPUUIBasedUpdateDriver.m | 6 +++--- Sparkle/SPUUserDriver.h | 6 +++--- Sparkle/SUUpdateAlert.m | 4 ++-- TestApplication/SUPopUpTitlebarUserDriver.m | 4 ++-- sparkle-cli/SPUCommandLineUserDriver.m | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sparkle/SPUStatusCompletionResults.h b/Sparkle/SPUStatusCompletionResults.h index 31fd4ae0..e6c6ea47 100644 --- a/Sparkle/SPUStatusCompletionResults.h +++ b/Sparkle/SPUStatusCompletionResults.h @@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { }; typedef NS_ENUM(NSInteger, SPUUserUpdateState) { - SPUUserUpdateStateNotDownloaded, + SPUUserUpdateStateNew, SPUUserUpdateStateDownloaded, SPUUserUpdateStateInstalling, SPUUserUpdateStateInformational diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index a80c3286..209d5650 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -117,7 +117,7 @@ } else if (self.resumingInstallingUpdate) { state = SPUUserUpdateStateInstalling; } else { - state = SPUUserUpdateStateNotDownloaded; + state = SPUUserUpdateStateNew; } [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated state:state reply:^(SPUUserUpdateChoice userChoice) { @@ -142,7 +142,7 @@ case SPUUserUpdateStateInstalling: [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; - case SPUUserUpdateStateNotDownloaded: + case SPUUserUpdateStateNew: [self.coreDriver downloadUpdateFromAppcastItem:updateItem inBackground:NO]; break; case SPUUserUpdateStateInformational: @@ -163,7 +163,7 @@ case SPUUserUpdateChoiceDismiss: switch (state) { case SPUUserUpdateStateDownloaded: - case SPUUserUpdateStateNotDownloaded: + case SPUUserUpdateStateNew: case SPUUserUpdateStateInformational: [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index d85c072b..0c23e4f1 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -77,7 +77,7 @@ SU_EXPORT @protocol SPUUserDriver * @param userInitiated A flag indicating whether or not a user initiated this update check * * @param state The current state of the update. - * SPUUserUpdateStateNotDownloaded - Update has not been downloaded yet. + * SPUUserUpdateStateNew - 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. @@ -89,8 +89,8 @@ SU_EXPORT @protocol SPUUserDriver * 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"). * * 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 upon dismissing until the next time an update is shown to the user. - * If the state is SPUUserUpdateStateInstalling, the installing update is also preserved upon dismissing. In this state however, the update will still be installed after the application is terminated. + * 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. * * 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 update cannot be skipped, only dismissed or installed. diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index f4ceefc0..927609b4 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -420,13 +420,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 == SPUUserUpdateStateNew) { 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 == SPUUserUpdateStateNew) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", @"Description text for SUUpdateAlert when the update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { finalString = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", @"Description text for SUUpdateAlert when the update has already been downloaded and ready to install."), self.host.name, updateItemVersion]; diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 0c6ab0f4..e3eb2177 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -149,12 +149,12 @@ reply(SPUUserUpdateChoiceDismiss); break; - case SPUUserUpdateStateNotDownloaded: + case SPUUserUpdateStateNew: case SPUUserUpdateStateDownloaded: [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; break; case SPUUserUpdateStateInstalling: - [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; + [self showUpdateWithAppcastItem:appcastItem skippable:NO reply:reply]; break; } } diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index e1dbe215..780cf5c2 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -108,7 +108,7 @@ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply { switch (state) { - case SPUUserUpdateStateNotDownloaded: + case SPUUserUpdateStateNew: [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; reply(SPUUserUpdateChoiceInstall); break; From 1abe5f70db42571c67bea0e703a3f193aa4609ba Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 16:47:22 -0700 Subject: [PATCH 4/8] Add comment for legacy path --- Sparkle/SPUUIBasedUpdateDriver.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 209d5650..7dc44da3 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -178,6 +178,7 @@ }); }]; } else { + // Legacy path that will be removed eventually #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" if (updateItem.isInformationOnlyUpdate) { From 3309abf9362a5e180071122552b26e3a9c3d7074 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 16:55:48 -0700 Subject: [PATCH 5/8] Remove DEBUG conditional check around deprecated methods --- Sparkle/SPUUserDriver.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 0c23e4f1..e7e1fb32 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -251,7 +251,6 @@ SU_EXPORT @protocol SPUUserDriver // Clients should move to non-deprecated methods // Deprecated methods are only (temporarily) kept around for binary compatibility reasons -#if DEBUG - (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion __deprecated_msg("Implement -showUserInitiatedUpdateCheckWithCancellation: instead"); @@ -269,8 +268,6 @@ SU_EXPORT @protocol SPUUserDriver - (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply __deprecated_msg("Implement -showUpdateFoundWithAppcastItem:userInitiated:state:reply: instead"); -#endif - @end NS_ASSUME_NONNULL_END From 188a8931740091fbd1857c89389fd7d7ce1e0516 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 19:07:48 -0700 Subject: [PATCH 6/8] Rename new state back to not downloaded --- Sparkle/SPUStatusCompletionResults.h | 2 +- Sparkle/SPUUIBasedUpdateDriver.m | 6 +++--- Sparkle/SPUUserDriver.h | 2 +- Sparkle/SUUpdateAlert.m | 4 ++-- TestApplication/SUPopUpTitlebarUserDriver.m | 2 +- sparkle-cli/SPUCommandLineUserDriver.m | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sparkle/SPUStatusCompletionResults.h b/Sparkle/SPUStatusCompletionResults.h index e6c6ea47..31fd4ae0 100644 --- a/Sparkle/SPUStatusCompletionResults.h +++ b/Sparkle/SPUStatusCompletionResults.h @@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { }; typedef NS_ENUM(NSInteger, SPUUserUpdateState) { - SPUUserUpdateStateNew, + SPUUserUpdateStateNotDownloaded, SPUUserUpdateStateDownloaded, SPUUserUpdateStateInstalling, SPUUserUpdateStateInformational diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 7dc44da3..7e36dc2f 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -117,7 +117,7 @@ } else if (self.resumingInstallingUpdate) { state = SPUUserUpdateStateInstalling; } else { - state = SPUUserUpdateStateNew; + state = SPUUserUpdateStateNotDownloaded; } [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated state:state reply:^(SPUUserUpdateChoice userChoice) { @@ -142,7 +142,7 @@ case SPUUserUpdateStateInstalling: [self.coreDriver finishInstallationWithResponse:validatedChoice displayingUserInterface:!self.preventsInstallerInteraction]; break; - case SPUUserUpdateStateNew: + case SPUUserUpdateStateNotDownloaded: [self.coreDriver downloadUpdateFromAppcastItem:updateItem inBackground:NO]; break; case SPUUserUpdateStateInformational: @@ -163,7 +163,7 @@ case SPUUserUpdateChoiceDismiss: switch (state) { case SPUUserUpdateStateDownloaded: - case SPUUserUpdateStateNew: + case SPUUserUpdateStateNotDownloaded: case SPUUserUpdateStateInformational: [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index e7e1fb32..bcfcef93 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -77,7 +77,7 @@ SU_EXPORT @protocol SPUUserDriver * @param userInitiated A flag indicating whether or not a user initiated this update check * * @param state The current state of the update. - * SPUUserUpdateStateNew - Update has not been downloaded yet. + * 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. diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 927609b4..f4ceefc0 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -420,13 +420,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 == SPUUserUpdateStateNew) { + if (self.state == SPUUserUpdateStateNotDownloaded) { 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 == SPUUserUpdateStateNew) { + if (self.state == SPUUserUpdateStateNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", @"Description text for SUUpdateAlert when the update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { finalString = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", @"Description text for SUUpdateAlert when the update has already been downloaded and ready to install."), self.host.name, updateItemVersion]; diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index e3eb2177..6304359f 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -149,7 +149,7 @@ reply(SPUUserUpdateChoiceDismiss); break; - case SPUUserUpdateStateNew: + case SPUUserUpdateStateNotDownloaded: case SPUUserUpdateStateDownloaded: [self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply]; break; diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 780cf5c2..e1dbe215 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -108,7 +108,7 @@ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply { switch (state) { - case SPUUserUpdateStateNew: + case SPUUserUpdateStateNotDownloaded: [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; reply(SPUUserUpdateChoiceInstall); break; From af9935540a146787718a64588f9a18e27dfd2e44 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 17 Apr 2021 11:04:59 -0700 Subject: [PATCH 7/8] Don't bring up authorization just because group ID doesn't match --- Sparkle/SUFileManager.h | 1 + Sparkle/SUFileManager.m | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Sparkle/SUFileManager.h b/Sparkle/SUFileManager.h index a643fba1..21b3f57a 100644 --- a/Sparkle/SUFileManager.h +++ b/Sparkle/SUFileManager.h @@ -103,6 +103,7 @@ NS_ASSUME_NONNULL_BEGIN * If the owner and group IDs match on the root items of targetURL and matchURL, this method stops and assumes that nothing needs to be done. * Otherwise this method recursively changes the IDs if the target is a directory. If an item in the directory is encountered that is unable to be changed, * then this method stops and returns NO. + * While this method will try to change the group ID, being unable to change the group ID does not result in a failure if the owner ID can be changed or matched. * * This is not an atomic operation. */ diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 5b8e09d7..b81af0f4 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -434,15 +434,30 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { // Speeds up the common case return YES; } - - if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:groupID error:error]) { - return NO; + + // If we can't change both the new owner & group, try to only change the owner + // If this works, this is sufficient enough for performing the update + NSNumber *groupIDToUse; + if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:groupID error:NULL]) { + if ((targetOwnerID != nil && [ownerID isEqualToNumber:targetOwnerID])) { + // Assume they're the same even if we don't check every file recursively + // Speeds up the common case like above + return YES; + } + + if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:targetGroupID error:error]) { + return NO; + } + + groupIDToUse = targetGroupID; + } else { + groupIDToUse = groupID; } if (isTargetADirectory) { NSDirectoryEnumerator *directoryEnumerator = [_fileManager enumeratorAtURL:targetURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; for (NSURL *url in directoryEnumerator) { - if (![self _changeOwnerAndGroupOfItemAtURL:url ownerID:ownerID groupID:groupID error:error]) { + if (![self _changeOwnerAndGroupOfItemAtURL:url ownerID:ownerID groupID:groupIDToUse error:error]) { return NO; } } From 302f3f41a36a616a23494338448672c7585d0ab4 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 17 Apr 2021 16:07:18 -0700 Subject: [PATCH 8/8] Clear downloaded update upon skipping I had this line of code before in the legacy path but forgot to use it. --- Sparkle/SPUUIBasedUpdateDriver.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 7e36dc2f..fb01cee1 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -157,6 +157,8 @@ [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; } + [self.coreDriver clearDownloadedUpdate]; + [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break;