diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index 2091792c..e4d5ee8c 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -50,6 +50,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; @property (nonatomic) NSXPCConnection *activeConnection; @property (nonatomic) id communicator; @property (nonatomic) StatusInfo *statusInfo; +@property (nonatomic) BOOL receivedUpdaterPong; @property (nonatomic, strong) TerminationListener *terminationListener; @@ -77,6 +78,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; @synthesize activeConnection = _activeConnection; @synthesize communicator = _communicator; @synthesize statusInfo = _statusInfo; +@synthesize receivedUpdaterPong = _receivedUpdaterPong; @synthesize hostBundleIdentifier = _hostBundleIdentifier; @synthesize allowsInteraction = _allowsInteraction; @synthesize terminationListener = _terminationListener; @@ -373,6 +375,8 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; } }); }); + } else if (identifier == SUUpdaterAlivePong) { + self.receivedUpdaterPong = YES; } } @@ -522,6 +526,12 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; - (void)finishInstallationAfterHostTermination { [self.terminationListener startListeningWithCompletion:^{ + // 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 __block NSRunningApplication *installerProgressRunningApplication = nil; __block BOOL shouldLaunchInstallerProgress = YES; @@ -538,7 +548,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; 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 (shouldLaunchInstallerProgress && self.communicator == nil) { + // 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)) { NSError *launchError = nil; NSArray *arguments = @[self.host.bundlePath]; diff --git a/Sparkle/Autoupdate/SUMessageTypes.h b/Sparkle/Autoupdate/SUMessageTypes.h index 60a21aa9..4979b560 100644 --- a/Sparkle/Autoupdate/SUMessageTypes.h +++ b/Sparkle/Autoupdate/SUMessageTypes.h @@ -25,14 +25,16 @@ typedef NS_ENUM(int32_t, SUInstallerMessageType) SUInstallationStartedStage1 = 5, SUInstallationFinishedStage1 = 6, SUInstallationFinishedStage2 = 7, - SUInstallationFinishedStage3 = 8 + SUInstallationFinishedStage3 = 8, + SUUpdaterAlivePing = 9 }; typedef NS_ENUM(int32_t, SUUpdaterMessageType) { SUInstallationData = 0, SUSentUpdateAppcastItemData = 1, - SUResumeInstallationToStage2 = 2 + SUResumeInstallationToStage2 = 2, + SUUpdaterAlivePong = 3 }; BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInstallerMessageType newMessageType); diff --git a/Sparkle/Autoupdate/SUMessageTypes.m b/Sparkle/Autoupdate/SUMessageTypes.m index 74d1db45..1e5628c7 100644 --- a/Sparkle/Autoupdate/SUMessageTypes.m +++ b/Sparkle/Autoupdate/SUMessageTypes.m @@ -40,6 +40,11 @@ BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInst case SUInstallationFinishedStage3: legal = (oldMessageType == SUInstallationFinishedStage2); break; + case SUUpdaterAlivePing: + // Having this state being dependent on other installation states would make the complicate our logic + // So just always allow this type of message + legal = YES; + break; } return legal; } diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index b5a7d20c..43e3a3d5 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -301,6 +301,9 @@ [self.delegate installerDidFinishInstallation]; [self.delegate installerIsRequestingAbortInstallWithError:nil]; + } else if (identifier == SUUpdaterAlivePing) { + // Don't update the current stage; a ping request has no effect on that. + [self.installerConnection handleMessageWithIdentifier:SUUpdaterAlivePong data:[NSData data]]; } }