From e909c0d9889c8410e8301f61ab0d851dcfcaa4e8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 11 Apr 2021 13:45:40 -0700 Subject: [PATCH 1/3] Show alert that non-relaunched application was installed This only applies when the updater outlives the application it is updating and the application is not relaunched (i.e, an external/remote updater). --- Sparkle/SPUCoreBasedUpdateDriver.h | 2 +- Sparkle/SPUCoreBasedUpdateDriver.m | 6 +-- Sparkle/SPUInstallerDriver.h | 2 +- Sparkle/SPUInstallerDriver.m | 10 ++--- Sparkle/SPUStandardUserDriver.m | 44 ++++++++++++++++++++- Sparkle/SPUUIBasedUpdateDriver.m | 11 +++++- Sparkle/SPUUserDriver.h | 13 ++++-- TestApplication/SUPopUpTitlebarUserDriver.m | 2 +- sparkle-cli/SPUCommandLineUserDriver.m | 2 +- 9 files changed, 72 insertions(+), 20 deletions(-) diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 9014289d..8187bf09 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)installerIsSendingAppTerminationSignal; -- (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement; +- (void)installerDidFinishInstallationAndRelaunched:(BOOL)relaunched acknowledgement:(void(^)(void))acknowledgement; @end diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 8537aa2e..a1695365 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -326,10 +326,10 @@ } } -- (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement +- (void)installerDidFinishInstallationAndRelaunched:(BOOL)relaunched acknowledgement:(void(^)(void))acknowledgement { - if ([self.delegate respondsToSelector:@selector(installerDidFinishInstallationWithAcknowledgement:)]) { - [self.delegate installerDidFinishInstallationWithAcknowledgement:acknowledgement]; + if ([self.delegate respondsToSelector:@selector(installerDidFinishInstallationAndRelaunched:acknowledgement:)]) { + [self.delegate installerDidFinishInstallationAndRelaunched:relaunched acknowledgement:acknowledgement]; } else { acknowledgement(); } diff --git a/Sparkle/SPUInstallerDriver.h b/Sparkle/SPUInstallerDriver.h index 9ab98a2a..2426f9a2 100644 --- a/Sparkle/SPUInstallerDriver.h +++ b/Sparkle/SPUInstallerDriver.h @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently; - (void)installerIsSendingAppTerminationSignal; - (void)installerWillFinishInstallationAndRelaunch:(BOOL)relaunch; -- (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement; +- (void)installerDidFinishInstallationAndRelaunched:(BOOL)relaunch acknowledgement:(void(^)(void))acknowledgement; - (void)installerIsRequestingAbortInstallWithError:(nullable NSError *)error; - (void)installerDidFailToApplyDeltaUpdate; diff --git a/Sparkle/SPUInstallerDriver.m b/Sparkle/SPUInstallerDriver.m index c69f49f1..92797933 100644 --- a/Sparkle/SPUInstallerDriver.m +++ b/Sparkle/SPUInstallerDriver.m @@ -52,7 +52,7 @@ @property (nonatomic) BOOL postponedOnce; @property (nonatomic, weak, readonly) id updater; @property (nonatomic, weak, readonly) id updaterDelegate; -@property (nonatomic) BOOL willRelaunch; +@property (nonatomic) BOOL relaunch; @property (nonatomic) BOOL systemDomain; @@ -78,7 +78,7 @@ @synthesize postponedOnce = _postponedOnce; @synthesize updater = _updater; @synthesize updaterDelegate = _updaterDelegate; -@synthesize willRelaunch = _willRelaunch; +@synthesize relaunch = _relaunch; @synthesize systemDomain = _systemDomain; @synthesize updateItem = _updateItem; @synthesize downloadName = _downloadName; @@ -296,7 +296,7 @@ hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes); } - [self.delegate installerWillFinishInstallationAndRelaunch:self.willRelaunch]; + [self.delegate installerWillFinishInstallationAndRelaunch:self.relaunch]; if (!hasTargetTerminated) { [self.delegate installerIsSendingAppTerminationSignal]; @@ -307,7 +307,7 @@ [self.installerConnection invalidate]; self.installerConnection = nil; - [self.delegate installerDidFinishInstallationWithAcknowledgement:^{ + [self.delegate installerDidFinishInstallationAndRelaunched:self.relaunch acknowledgement:^{ dispatch_async(dispatch_get_main_queue(), ^{ [self.delegate installerIsRequestingAbortInstallWithError:nil]; }); @@ -498,7 +498,7 @@ // For resumability, we'll assume we are far enough for the installation to continue self.currentStage = SPUInstallationFinishedStage1; - self.willRelaunch = relaunch; + self.relaunch = relaunch; uint8_t response[2] = {(uint8_t)relaunch, (uint8_t)showUI}; NSData *responseData = [NSData dataWithBytes:response length:sizeof(response)]; diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index b9c3ed0f..ebc5d600 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -22,6 +22,10 @@ @interface SPUStandardUserDriver () @property (nonatomic, readonly) SUHost *host; +// We must store the oldHostName before the host is potentially replaced +// because we may use this property after update has been installed +@property (nonatomic, readonly) NSString *oldHostName; +@property (nonatomic, readonly) NSURL *oldHostBundleURL; @property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent; @property (nonatomic, weak, nullable, readonly) id delegate; @@ -36,6 +40,8 @@ @implementation SPUStandardUserDriver @synthesize host = _host; +@synthesize oldHostName = _oldHostName; +@synthesize oldHostBundleURL = _oldHostBundleURL; @synthesize coreComponent = _coreComponent; @synthesize delegate = _delegate; @synthesize checkingController = _checkingController; @@ -50,6 +56,8 @@ self = [super init]; if (self != nil) { _host = [[SUHost alloc] initWithBundle:hostBundle]; + _oldHostName = _host.name; + _oldHostBundleURL = hostBundle.bundleURL; _delegate = delegate; _coreComponent = [[SPUUserDriverCoreComponent alloc] init]; } @@ -421,12 +429,44 @@ [self.statusController setButtonEnabled:NO]; } -- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement +- (void)showUpdateInstalledAndRelaunched:(BOOL)relaunched acknowledgement:(void (^)(void))acknowledgement { assert(NSThread.isMainThread); - // Deciding not to show anything here + // Close window showing update is installing + [self.statusController close]; + self.statusController = nil; + [self.coreComponent registerAcknowledgement:acknowledgement]; + + // Only show installed prompt when the app is not relaunched + // When the app is relaunched, there is enough of a UI from relaunching the app. + if (!relaunched) { + NSAlert *alert = [[NSAlert alloc] init]; + alert.messageText = SULocalizedString(@"Update Installed", nil); + + // Extract information from newly updated bundle if available + NSString *hostName; + NSString *hostVersion; + NSBundle *newBundle = [NSBundle bundleWithURL:self.oldHostBundleURL]; + if (newBundle != nil) { + SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle]; + hostName = newHost.name; + hostVersion = newHost.displayVersion; + } else { + // This may happen if Sparkle's normalization is enabled + hostName = self.oldHostName; + hostVersion = nil; + } + + if (hostVersion != nil) { + alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ is now updated to version %@!", nil), hostName, hostVersion]; + } else { + alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ is now updated!", nil), hostName]; + } + [self showAlert:alert]; + } + [self.coreComponent acceptAcknowledgement]; } diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 989d3611..192f2277 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -259,9 +259,16 @@ [self.userDriver showSendingTerminationSignal]; } -- (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement +- (void)installerDidFinishInstallationAndRelaunched:(BOOL)relaunched acknowledgement:(void(^)(void))acknowledgement { - [self.userDriver showUpdateInstallationDidFinishWithAcknowledgement:acknowledgement]; + if ([self.userDriver respondsToSelector:@selector(showUpdateInstalledAndRelaunched:acknowledgement:)]) { + [self.userDriver showUpdateInstalledAndRelaunched:relaunched acknowledgement:acknowledgement]; + } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [self.userDriver showUpdateInstallationDidFinishWithAcknowledgement:acknowledgement]; +#pragma clang diagnostic pop + } } - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 31c6e7e3..60e4d50f 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -273,12 +273,15 @@ SU_EXPORT @protocol SPUUserDriver * Show the user that the update installation finished * * Let the user know that the update finished installing. - * This will only be invoked if the updater process is still alive, which is typically not the case if - * the updater's lifetime is tied to the application it is updating. * - * @param acknowledgement Acknowledge to the updater that the installation finish was shown. + * This will only be invoked if the updater process is still alive, which is typically not the case if + * the updater's lifetime is tied to the application it is updating. This implementation must not try to reference + * the old bundle prior to the installation, which will no longer be around. + * + * @param relaunched Indicates if the update was relaunched, which only happens if the application was running before installing the update. + * @param acknowledgement Acknowledge to the updater that the finished installation was shown. */ -- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement; +- (void)showUpdateInstalledAndRelaunched:(BOOL)relaunched acknowledgement:(void (^)(void))acknowledgement; /*! * Dismiss the current update installation @@ -293,6 +296,8 @@ SU_EXPORT @protocol SPUUserDriver - (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))acknowledgement __deprecated_msg("Implement -showUpdateNotFoundWithError:acknowledgement: instead"); +- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement __deprecated_msg("Implement -showUpdateInstalledAndRelaunched:acknowledgement: instead"); + @end NS_ASSUME_NONNULL_END diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index d49fcb43..58d14125 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -292,7 +292,7 @@ [self removeUpdateButton]; } -- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement +- (void)showUpdateInstalledAndRelaunched:(BOOL)__unused relaunched acknowledgement:(void (^)(void))acknowledgement { [self.coreComponent registerAcknowledgement:acknowledgement]; diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 4f9c2c90..fcb2b46b 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -256,7 +256,7 @@ } } -- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement +- (void)showUpdateInstalledAndRelaunched:(BOOL)__unused relaunched acknowledgement:(void (^)(void))acknowledgement { [self.coreComponent registerAcknowledgement:acknowledgement]; From 3ea863d82b5d6a32c472f9b0073361b2bd0c809e Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 11 Apr 2021 19:01:27 -0700 Subject: [PATCH 2/3] Remove incorrect note about when relaunch happens User driver can also request to not relaunch the app and this is worded oddly. --- Sparkle/SPUUserDriver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 60e4d50f..6625cde9 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -278,7 +278,7 @@ SU_EXPORT @protocol SPUUserDriver * the updater's lifetime is tied to the application it is updating. This implementation must not try to reference * the old bundle prior to the installation, which will no longer be around. * - * @param relaunched Indicates if the update was relaunched, which only happens if the application was running before installing the update. + * @param relaunched Indicates if the update was relaunched. * @param acknowledgement Acknowledge to the updater that the finished installation was shown. */ - (void)showUpdateInstalledAndRelaunched:(BOOL)relaunched acknowledgement:(void (^)(void))acknowledgement; From b0d9a75f988e7c580fdaaf00e97a4c4ac2aa52de Mon Sep 17 00:00:00 2001 From: Zorg Date: Thu, 15 Apr 2021 19:36:14 -0700 Subject: [PATCH 3/3] Add new installed update localizations to Sparkle.strings --- Sparkle/Base.lproj/Sparkle.strings | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index faf6b910..48acd4d4 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -14,6 +14,12 @@ "%@ %@ is currently the newest version available.\n(You are currently running version %@.)" = "%1$@ %2$@ is currently the newest version available.\n(You are currently running version %3$@.)"; +"Update Installed" = "Update Installed"; + +"%@ is now updated to version %@!" = "%@ is now updated to version %@!"; + +"%@ is now updated!" = "%@ 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$@ is now available—you have %3$@. Would you like to download it now?";