Skip to content

Commit

Permalink
Merge pull request sparkle-project#761 from zorgiepoo/automatic-updat…
Browse files Browse the repository at this point in the history
…e-termination

Fix Installation process being initiated twice
  • Loading branch information
kornelski committed Feb 19, 2016
2 parents 91e929c + c3ffd7f commit 0171ab2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Sparkle/SUAutomaticUpdateDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ @interface SUAutomaticUpdateDriver ()
@property (assign) BOOL postponingInstallation;
@property (assign) BOOL showErrors;
@property (assign) BOOL willUpdateOnTermination;
@property (assign) BOOL isTerminating;
@property (strong) SUAutomaticUpdateAlert *alert;
@property (strong) NSTimer *showUpdateAlertTimer;

Expand All @@ -36,6 +37,7 @@ @implementation SUAutomaticUpdateDriver
@synthesize postponingInstallation;
@synthesize showErrors;
@synthesize willUpdateOnTermination;
@synthesize isTerminating;
@synthesize alert;
@synthesize showUpdateAlertTimer;

Expand Down Expand Up @@ -131,6 +133,7 @@ - (void)dealloc

- (void)abortUpdate
{
self.isTerminating = NO;
[self stopUpdatingOnTermination];
[self invalidateShowUpdateAlertTimer];
[super abortUpdate];
Expand All @@ -153,8 +156,6 @@ - (void)automaticUpdateAlertFinishedWithChoice:(SUAutomaticInstallationChoice)ch

case SUInstallLaterChoice:
self.postponingInstallation = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(systemWillPowerOff:) name:NSWorkspaceWillPowerOffNotification object:nil];
// We're already waiting on quit, just indicate that we're idle.
self.interruptible = YES;
break;
Expand All @@ -166,6 +167,7 @@ - (void)automaticUpdateAlertFinishedWithChoice:(SUAutomaticInstallationChoice)ch
}
}


- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
{
if (relaunch) {
Expand All @@ -185,9 +187,22 @@ - (void)systemWillPowerOff:(NSNotification *)__unused note

- (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) {
Expand Down
2 changes: 2 additions & 0 deletions Sparkle/SUBasicUpdateDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)
if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) {
pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater];
}

[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath],
pathToRelaunch,
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
Expand All @@ -520,6 +521,7 @@ - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)
[self terminateApp];
}

// Note: this is overridden by the automatic update driver to not terminate in some cases
- (void)terminateApp
{
[NSApp terminate:self];
Expand Down

0 comments on commit 0171ab2

Please sign in to comment.