From 625f229a65ce17390e2af87ca17b48a13863706c Mon Sep 17 00:00:00 2001 From: Zorg Date: Thu, 18 Feb 2016 00:40:14 -0500 Subject: [PATCH] Don't terminate the app if we're already terminating --- Sparkle/SUAutomaticUpdateDriver.m | 16 ++++++++++++++++ Sparkle/SUBasicUpdateDriver.m | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 562f2d05..b4f2b78a 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -26,6 +26,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 @property (assign) BOOL postponingInstallation; @property (assign) BOOL showErrors; @property (assign) BOOL willUpdateOnTermination; +@property (assign) BOOL isTerminating; @property (strong) SUAutomaticUpdateAlert *alert; @property (strong) NSTimer *showUpdateAlertTimer; @@ -36,6 +37,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 @synthesize postponingInstallation; @synthesize showErrors; @synthesize willUpdateOnTermination; +@synthesize isTerminating; @synthesize alert; @synthesize showUpdateAlertTimer; @@ -131,6 +133,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)abortUpdate { + self.isTerminating = NO; [self stopUpdatingOnTermination]; [self invalidateShowUpdateAlertTimer]; [super abortUpdate]; @@ -185,9 +188,22 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)applicationWillTerminate:(NSNotification *)__unused note { + // We don't want to terminate the app if the user or someone else initiated a termination + // Use a property instead of passing an argument to installWithToolAndRelaunch: + // because we give the delegate an invocation to our install methods and + // this code was added later :| + self.isTerminating = YES; + [self installWithToolAndRelaunch:NO]; } +- (void)terminateApp +{ + if (!self.isTerminating) { + [super terminateApp]; + } +} + - (void)abortUpdateWithError:(NSError *)error { if (self.showErrors) { diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index a219eaee..3df60455 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -511,6 +511,7 @@ if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater]; } + [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], @@ -520,6 +521,7 @@ [self terminateApp]; } +// Note: this is overridden by the automatic update driver to not terminate in some cases - (void)terminateApp { [NSApp terminate:self];