From af245bfe623c3c485cb5ed0f1245886f52d4af33 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 1 May 2021 11:08:18 -0700 Subject: [PATCH 1/2] Enforce the updater session is in progress We should enforce update session is in progress before checking for new updates. I've tested checking for updates regularly, in background, and informational updates. An update check could have been made while the permission request was in flight, which we don't want to happen. --- Sparkle/SPUUpdater.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 933da125..206776e4 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -423,6 +423,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if (self.sessionInProgress) { SULog(SULogLevelError, @"Error: -checkForUpdatesInBackground called but .sessionInProgress == YES"); + return; } self.sessionInProgress = YES; @@ -488,6 +489,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if (self.sessionInProgress) { SULog(SULogLevelError, @"Error: -checkForUpdates called but .sessionInProgress == YES"); + return; } if (self.driver != nil) { @@ -529,6 +531,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if (self.sessionInProgress) { SULog(SULogLevelError, @"Error: -checkForUpdateInformation called but .sessionInProgress == YES"); + return; } self.sessionInProgress = YES; From fbe48e5738f5ddf28e722aceeac38012878cad5b Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 1 May 2021 19:53:01 -0700 Subject: [PATCH 2/2] Allow skipping/canceling of an update that is currently installing --- Autoupdate/AppInstaller.m | 4 +++ Autoupdate/SPUMessageTypes.h | 3 +- Sparkle/SPUCoreBasedUpdateDriver.m | 4 ++- Sparkle/SPUInstallerDriver.h | 2 ++ Sparkle/SPUInstallerDriver.m | 15 ++++++++-- Sparkle/SPUUIBasedUpdateDriver.m | 44 ++++++++++++++++++++---------- Sparkle/SPUUserDriver.h | 7 ++--- Sparkle/SUUpdateAlert.m | 3 -- 8 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index 54fb5a65..7d8dbbf0 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -437,6 +437,10 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; }); } }); + } else if (identifier == SPUCancelInstallation) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self cleanupAndExitWithStatus:0 error:nil]; + }); } else if (identifier == SPUUpdaterAlivePong) { self.receivedUpdaterPong = YES; } diff --git a/Autoupdate/SPUMessageTypes.h b/Autoupdate/SPUMessageTypes.h index 0a48bd07..d938ed9b 100644 --- a/Autoupdate/SPUMessageTypes.h +++ b/Autoupdate/SPUMessageTypes.h @@ -31,7 +31,8 @@ typedef NS_ENUM(int32_t, SPUUpdaterMessageType) SPUInstallationData = 0, SPUSentUpdateAppcastItemData = 1, SPUResumeInstallationToStage2 = 2, - SPUUpdaterAlivePong = 3 + SPUUpdaterAlivePong = 3, + SPUCancelInstallation = 4 }; BOOL SPUInstallerMessageTypeIsLegal(SPUInstallerMessageType oldMessageType, SPUInstallerMessageType newMessageType); diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index b095524f..34013026 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -331,9 +331,11 @@ { switch (response) { case SPUUserUpdateChoiceDismiss: - case SPUUserUpdateChoiceSkip: [self.delegate coreDriverIsRequestingAbortUpdateWithError:nil]; break; + case SPUUserUpdateChoiceSkip: + [self.installerDriver cancelUpdate]; + break; case SPUUserUpdateChoiceInstall: [self.installerDriver installWithToolAndRelaunch:YES displayingUserInterface:displayingUserInterface]; break; diff --git a/Sparkle/SPUInstallerDriver.h b/Sparkle/SPUInstallerDriver.h index 2bb25107..8e831b91 100644 --- a/Sparkle/SPUInstallerDriver.h +++ b/Sparkle/SPUInstallerDriver.h @@ -40,6 +40,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI; +- (void)cancelUpdate; + - (void)abortInstall; @end diff --git a/Sparkle/SPUInstallerDriver.m b/Sparkle/SPUInstallerDriver.m index 09212511..dc2c47d0 100644 --- a/Sparkle/SPUInstallerDriver.m +++ b/Sparkle/SPUInstallerDriver.m @@ -141,8 +141,6 @@ assert(installationType != nil); [self.installerConnection setServiceName:serviceName systemDomain:self.systemDomain]; - - [self sendInstallationData]; } // This can be called multiple times (eg: if a delta update fails, this may be called again with a regular update item) @@ -482,6 +480,7 @@ case SUInstallerLauncherSuccess: self.systemDomain = systemDomain; [self setUpConnection]; + [self sendInstallationData]; completionHandler(nil); break; } @@ -534,6 +533,18 @@ // the installer will send us SPUInstallationFinishedStage2 when stage 2 is done } +- (void)cancelUpdate +{ + // Set up connection to the installer if one is not set up already + [self setUpConnection]; + + self.aborted = YES; + + [self.installerConnection handleMessageWithIdentifier:SPUCancelInstallation data:[NSData data]]; + + [self.delegate installerIsRequestingAbortInstallWithError:nil]; +} + - (void)abortInstall { self.aborted = YES; diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 54ae8de4..aca2e8ac 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -125,14 +125,14 @@ // Rule out invalid choices SPUUserUpdateChoice validatedChoice; - if ((state == SPUUserUpdateStateInstalling && userChoice == SPUUserUpdateChoiceSkip) || (state == SPUUserUpdateStateInformational && userChoice == SPUUserUpdateChoiceInstall)) { + if (state == SPUUserUpdateStateInformational && userChoice == SPUUserUpdateChoiceInstall) { validatedChoice = SPUUserUpdateChoiceDismiss; } else { validatedChoice = userChoice; } switch (validatedChoice) { - case SPUUserUpdateChoiceInstall: + case SPUUserUpdateChoiceInstall: { [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (state) { @@ -150,29 +150,26 @@ break; } break; - case SPUUserUpdateChoiceSkip: + } + case SPUUserUpdateChoiceSkip: { [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; } - // 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 SPUUserUpdateChoiceDismiss: switch (state) { case SPUUserUpdateStateDownloaded: case SPUUserUpdateStateNotDownloaded: case SPUUserUpdateStateInformational: - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; + // 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]; @@ -180,6 +177,25 @@ } 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; + } } }); }]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index a976c4e9..89e2715c 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -79,7 +79,7 @@ SU_EXPORT @protocol SPUUserDriver * 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. + * If the state 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; @@ -194,10 +194,9 @@ SU_EXPORT @protocol SPUUserDriver * @param reply * A reply of SPUUserUpdateChoiceInstall installs the update the new update immediately. The application is relaunched only if it is still running by the time this reply is invoked. If the application terminates on its own, Sparkle will attempt to automatically install the update. * - * 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 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. + * A reply of SPUUserUpdateChoiceSkip cancels the current update that has begun installing and dismisses the update. In this circumstance, the update is canceled but this update version is not skipped in the future. * * Before this point, -showInstallingUpdate will be called. */ diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index a392fe2f..785ee001 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -357,9 +357,6 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE } if (self.state == SPUUserUpdateStateInstalling) { - // An already downloaded & resumable update can't be skipped - self.skipButton.hidden = YES; - // We're going to be relaunching pretty instantaneously self.installButton.title = SULocalizedString(@"Install and Relaunch", nil);