From c0a148f5ffb5a90d8184a20ac0177c026287eefc Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 1 May 2016 11:54:23 -0400 Subject: [PATCH] Post relaunch notification only if we are relaunching --- Sparkle/SUCoreBasedUpdateDriver.m | 11 ++++++----- Sparkle/SUInstallerDriver.h | 2 +- Sparkle/SUInstallerDriver.m | 6 +++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Sparkle/SUCoreBasedUpdateDriver.m b/Sparkle/SUCoreBasedUpdateDriver.m index 1d2866de..19b34ba9 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.m +++ b/Sparkle/SUCoreBasedUpdateDriver.m @@ -213,16 +213,17 @@ } } -- (void)installerWillFinishInstallation +- (void)installerWillFinishInstallationAndRelaunch:(BOOL)relaunch { if ([self.updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) { [self.updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; } -#warning should only notify if we are really about to restart the target... - [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; - if ([self.updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)]) { - [self.updaterDelegate updaterWillRelaunchApplication:self.updater]; + if (relaunch) { + [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; + if ([self.updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)]) { + [self.updaterDelegate updaterWillRelaunchApplication:self.updater]; + } } } diff --git a/Sparkle/SUInstallerDriver.h b/Sparkle/SUInstallerDriver.h index 1bd4dbf3..581283d2 100644 --- a/Sparkle/SUInstallerDriver.h +++ b/Sparkle/SUInstallerDriver.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)installerDidExtractUpdateWithProgress:(double)progress; - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently; - (void)installerIsRequestingAppTermination; -- (void)installerWillFinishInstallation; +- (void)installerWillFinishInstallationAndRelaunch:(BOOL)relaunch; - (void)installerDidFinishInstallation; - (void)installerIsRequestingAbortInstallWithError:(nullable NSError *)error; diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index d604c40a..0975b42f 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -43,6 +43,7 @@ @property (nonatomic) BOOL postponedOnce; @property (nonatomic, weak, readonly) id updater; @property (nonatomic, weak, readonly) id updaterDelegate; +@property (nonatomic) BOOL willRelaunch; @property (nonatomic) SUAppcastItem *updateItem; @property (nonatomic, copy) NSString *downloadName; @@ -63,6 +64,7 @@ @synthesize postponedOnce = _postponedOnce; @synthesize updater = _updater; @synthesize updaterDelegate = _updaterDelegate; +@synthesize willRelaunch = _willRelaunch; @synthesize updateItem = _updateItem; @synthesize downloadName = _downloadName; @synthesize temporaryDirectory = _temporaryDirectory; @@ -351,7 +353,7 @@ [self.remotePort invalidate]; self.remotePort = nil; - [self.delegate installerWillFinishInstallation]; + [self.delegate installerWillFinishInstallationAndRelaunch:self.willRelaunch]; if (!hasTargetTerminated) { [self.delegate installerIsRequestingAppTermination]; @@ -567,6 +569,8 @@ // For resumability, we'll assume we are far enough for the installation to continue strongSelf.currentStage = SUInstallationFinishedStage1; + strongSelf.willRelaunch = relaunch; + uint8_t response[2] = {(uint8_t)relaunch, (uint8_t)showUI}; NSData *responseData = [NSData dataWithBytes:response length:sizeof(response)];