diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index c7645ec5..8f6509ac 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -379,19 +379,26 @@ }); } +- (void)_showInstallingUpdate +{ + [self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; + [self.statusController setButtonEnabled:NO]; +} + - (void)showInstallingUpdate { dispatch_async(dispatch_get_main_queue(), ^{ - [self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; - [self.statusController setButtonEnabled:NO]; + [self _showInstallingUpdate]; }); } - (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement { - // Deciding not to show anything here - [self.coreComponent registerAcknowledgement:acknowledgement]; - [self.coreComponent acceptAcknowledgement]; + dispatch_async(dispatch_get_main_queue(), ^{ + // Deciding not to show anything here + [self.coreComponent registerAcknowledgement:acknowledgement]; + [self.coreComponent acceptAcknowledgement]; + }); } #pragma mark Aborting Everything @@ -399,13 +406,6 @@ - (void)terminateApplication { dispatch_async(dispatch_get_main_queue(), ^{ - // if a user chooses to NOT relaunch the app (as is the case with WebKit - // when it asks you if you are sure you want to close the app with multiple - // tabs open), the status window still stays on the screen and obscures - // other windows; with this fix, it doesn't - [self.statusController close]; - self.statusController = nil; - // Give the delegate a deferred chance for providing an application path // This is a private API and used by SUUpdater NSString *applicationPath = nil; @@ -421,7 +421,16 @@ applicationBundle = self.applicationBundle; } - [self.uiComponent terminateApplicationForBundle:applicationBundle]; + if ([self.uiComponent terminateApplicationForBundleAndWillTerminateCurrentApplication:applicationBundle]) { + // if a user chooses to NOT relaunch the app (as is the case with WebKit + // when it asks you if you are sure you want to close the app with multiple + // tabs open), the status window still stays on the screen and obscures + // other windows; with this fix, it doesn't + [self.statusController close]; + self.statusController = nil; + } else { + [self _showInstallingUpdate]; + } }); } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 4948ec5c..5fe7b028 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -252,11 +252,12 @@ SU_EXPORT @protocol SPUUserDriver - (void)showInstallingUpdate; /*! - * Terminate the application + * Terminate the application and show or dismiss installer progress. * - * Sparkle is signaling that it wants the application to request for application termination. - * Care should be taken if the request for application termination fails or is delayed. - * Eg: may want to hide installation status windows in case termination doesn't happen right away + * Sparkle is asking us to send a request to terminate the application. + * + * If this will terminate the current application, one may decide to dismiss progress UI in case the termination request is delayed or canceled. + * Or if this will terminate a remote application, one may decide to show the user that the update is currently installing. * * This can be called from any thread */ diff --git a/Sparkle/SPUUserDriverUIComponent.h b/Sparkle/SPUUserDriverUIComponent.h index 2bac8251..ee8e2d5d 100644 --- a/Sparkle/SPUUserDriverUIComponent.h +++ b/Sparkle/SPUUserDriverUIComponent.h @@ -15,6 +15,8 @@ SU_EXPORT @interface SPUUserDriverUIComponent : NSObject - (instancetype)init; +- (BOOL)terminateApplicationForBundleAndWillTerminateCurrentApplication:(NSBundle *)bundle; + - (void)terminateApplicationForBundle:(NSBundle *)bundle; - (BOOL)applicationIsAliveForBundle:(NSBundle *)bundle; diff --git a/Sparkle/SPUUserDriverUIComponent.m b/Sparkle/SPUUserDriverUIComponent.m index 07a6140c..79ace719 100644 --- a/Sparkle/SPUUserDriverUIComponent.m +++ b/Sparkle/SPUUserDriverUIComponent.m @@ -21,10 +21,23 @@ - (void)terminateApplicationForBundle:(NSBundle *)bundle { + [self terminateApplicationForBundleAndWillTerminateCurrentApplication:bundle]; +} + +- (BOOL)terminateApplicationForBundleAndWillTerminateCurrentApplication:(NSBundle *)bundle +{ + NSRunningApplication *currentRunningApplication = [NSRunningApplication currentApplication]; + BOOL willTerminateSelf = NO; + NSArray *runningApplications = [SPUApplicationInfo runningApplicationsWithBundle:bundle]; for (NSRunningApplication *runningApplication in runningApplications) { + if (!willTerminateSelf && [currentRunningApplication isEqual:runningApplication]) { + willTerminateSelf = YES; + } [runningApplication terminate]; } + + return willTerminateSelf; } - (BOOL)applicationIsAliveForBundle:(NSBundle *)bundle diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index fd20630d..7232df06 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -330,10 +330,12 @@ - (void)terminateApplication { dispatch_async(dispatch_get_main_queue(), ^{ - // In case our termination request fails or is delayed - [self removeUpdateButton]; - - [self.uiComponent terminateApplicationForBundle:self.applicationBundle]; + if ([self.uiComponent terminateApplicationForBundleAndWillTerminateCurrentApplication:self.applicationBundle]) { + // In case our termination request fails or is delayed + [self removeUpdateButton]; + } else { + [self addUpdateButtonWithTitle:@"Installing…"]; + } }); }