Have progress agent terminate after relaunching, not after stopping progress

This commit is contained in:
Zorg committed 2016-07-30 14:18:39 -04:00
1 parent 8c564fef1f
commit 23e027d02f
2 files changed
+57 -56

No files matched your search

+12 -11
View File
@@ -563,22 +563,22 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
return;
}
// Ask the updater if it is still alive
// If they are, we will receive a pong response back
// Reset if we received a pong just to be on the safe side
self.receivedUpdaterPong = NO;
[self.communicator handleMessageWithIdentifier:SUUpdaterAlivePing data:[NSData data]];
// Launch our installer progress UI tool if only after a certain amount of time passes,
// Show our installer progress UI tool if only after a certain amount of time passes,
// and if our installer is silent (i.e, doesn't show progress on its own)
__block BOOL shouldLaunchInstallerProgress = YES;
__block BOOL shouldShowUIProgress = YES;
if (self.shouldShowUI && [self.installer canInstallSilently]) {
// Ask the updater if it is still alive
// If they are, we will receive a pong response back
// Reset if we received a pong just to be on the safe side
self.receivedUpdaterPong = NO;
[self.communicator handleMessageWithIdentifier:SUUpdaterAlivePing data:[NSData data]];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUDisplayProgressTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Make sure we're still eligible for showing the installer progress
// Also if the updater process is still alive, showing the progress should not be our duty
// if the communicator object is nil, the updater definitely isn't alive. However, if it is not nil,
// this does not necessarily mean the updater is alive, so we should also check if we got a recent response back from the updater
if (shouldLaunchInstallerProgress && (!self.receivedUpdaterPong || self.communicator == nil)) {
if (shouldShowUIProgress && (!self.receivedUpdaterPong || self.communicator == nil)) {
[self.agentConnection.agent showProgress];
}
});
@@ -608,11 +608,11 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
self.performedStage3Installation = YES;
dispatch_async(dispatch_get_main_queue(), ^{
// Make sure to terminate our displayed progress before we move onto cleanup & relaunch
// Make sure to stop our displayed progress before we move onto cleanup & relaunch
// This will also stop the agent from broadcasting the status info service, which we want to do before
// we relaunch the app because the relaunched app could check the service upon launch..
[self.agentConnection.agent stopProgress];
shouldLaunchInstallerProgress = NO;
shouldShowUIProgress = NO;
[self.communicator handleMessageWithIdentifier:SUInstallationFinishedStage3 data:[NSData data]];
@@ -628,6 +628,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
pathToRelaunch = self.relaunchPath;
}
// This will also signal to the agent that it will terminate soon
[self.agentConnection.agent relaunchPath:pathToRelaunch];
}
+45 -45
View File
@@ -162,18 +162,19 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
- (void)registerRelaunchBundlePath:(NSString *)relaunchBundlePath reply:(void (^)(NSNumber *))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
assert(relaunchBundlePath != nil);
NSBundle *relaunchBundle = [NSBundle bundleWithPath:relaunchBundlePath];
if (relaunchBundle == nil) {
[self cleanupAndExitWithStatus:EXIT_FAILURE];
if (relaunchBundlePath != nil && !self.willTerminate) {
NSBundle *relaunchBundle = [NSBundle bundleWithPath:relaunchBundlePath];
if (relaunchBundle == nil) {
[self cleanupAndExitWithStatus:EXIT_FAILURE];
}
NSRunningApplication *runningApplication = [SUApplicationInfo runningApplicationWithBundle:relaunchBundle];
NSNumber *processIdentifier = (runningApplication == nil || runningApplication.terminated) ? nil : @(runningApplication.processIdentifier);
reply(processIdentifier);
self.repliedToRegistration = YES;
}
NSRunningApplication *runningApplication = [SUApplicationInfo runningApplicationWithBundle:relaunchBundle];
NSNumber *processIdentifier = (runningApplication == nil || runningApplication.terminated) ? nil : @(runningApplication.processIdentifier);
reply(processIdentifier);
self.repliedToRegistration = YES;
});
}
@@ -189,8 +190,18 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
- (void)relaunchPath:(NSString *)pathToRelaunch
{
dispatch_async(dispatch_get_main_queue(), ^{
if (![[NSWorkspace sharedWorkspace] openFile:pathToRelaunch]) {
SULog(@"Error: Failed to relaunch bundle at %@", pathToRelaunch);
if (!self.willTerminate) {
if (![[NSWorkspace sharedWorkspace] openFile:pathToRelaunch]) {
SULog(@"Error: Failed to relaunch bundle at %@", pathToRelaunch);
}
// Delay termination for a little bit to better increase the chance the updated application when relaunched will be the frontmost application
// This is related to macOS activation issues when terminating a frontmost application happens right before launching another app
self.willTerminate = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUTerminationTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_SUCCESS];
});
}
});
}
@@ -198,44 +209,33 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
- (void)showProgress
{
dispatch_async(dispatch_get_main_queue(), ^{
// Show app icon in the dock
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Note: the application icon needs to be set after showing the icon in the dock
self.application.applicationIconImage = [SUApplicationInfo bestIconForBundle:self.hostBundle];
// Activate ourselves otherwise we will probably be in the background
[self.application activateIgnoringOtherApps:YES];
[self.delegate installerProgressShouldDisplayWithBundle:self.hostBundle];
if (!self.willTerminate) {
// Show app icon in the dock
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Note: the application icon needs to be set after showing the icon in the dock
self.application.applicationIconImage = [SUApplicationInfo bestIconForBundle:self.hostBundle];
// Activate ourselves otherwise we will probably be in the background
[self.application activateIgnoringOtherApps:YES];
[self.delegate installerProgressShouldDisplayWithBundle:self.hostBundle];
}
});
}
- (void)stopProgress
{
dispatch_async(dispatch_get_main_queue(), ^{
[self _stopProgress];
});
}
- (void)_stopProgress
{
[self.statusInfo invalidate];
self.statusInfo = nil;
// Dismiss any UI immediately, but delay termination for a little bit to better increase the chance
// the updated application when relaunched will be the frontmost application
// This is related to macOS activation issues when terminating a frontmost application happens right before
// launching another app
[self.delegate installerProgressShouldStop];
self.delegate = nil;
self.willTerminate = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUTerminationTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Exit right away, don't go through the apple event process again
[self cleanupAndExitWithStatus:EXIT_SUCCESS];
// Dismiss any UI immediately
[self.delegate installerProgressShouldStop];
self.delegate = nil;
// No need to broadcast status service anymore
// In fact we shouldn't when we decide to relaunch the update
[self.statusInfo invalidate];
self.statusInfo = nil;
});
}