diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index c88aaeaf..5f5fffcb 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -96,6 +96,12 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; } + else if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) + { + [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{ + [self installWithToolAndRelaunch:YES displayingUserInterface:NO]; + }]; + } // If this is marked as a critical update, we'll prompt the user to install it right away. if ([self.updateItem isCriticalUpdate]) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 483d9d77..4265a3eb 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -494,19 +494,24 @@ id updater = self.updater; static BOOL postponedOnce = NO; id updaterDelegate = [updater delegate]; - if (!postponedOnce && [updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)]) - { - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]]; - [invocation setSelector:@selector(installWithToolAndRelaunch:)]; - [invocation setArgument:&relaunch atIndex:2]; - [invocation setTarget:self]; - postponedOnce = YES; - if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { - return; + if (!postponedOnce) { + if ([updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)]) { + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]]; + [invocation setSelector:@selector(installWithToolAndRelaunch:)]; + [invocation setArgument:&relaunch atIndex:2]; + [invocation setTarget:self]; + postponedOnce = YES; + if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { + return; + } + } else if ([updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:)]) { + postponedOnce = YES; + if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem]) { + return; + } } } - if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) { [updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; } diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index bc1d4916..d05270f2 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -189,6 +189,8 @@ SU_EXPORT @interface SUUpdater : NSObject For UI-less/daemon apps that aren't usually quit, instead of this function, you can use the delegate method SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation: + or + SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationBlock: to immediately start installation when an update was found. A progress dialog is shown but the user will never be prompted to read the diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 86d1eb9e..ed5952b2 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -195,6 +195,21 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvoking:(NSInvocation *)invocation; +/*! + Returns whether the relaunch should be delayed in order to perform other tasks. + + This is not called if the user didn't relaunch on the previous update, + in that case it will immediately restart. + + This method acts as a simpler alternative to SUUpdaterDelegate::updater:shouldPostponeRelaunchForUpdate:untilInvoking: avoiding usage of NSInvocation, which is not available in Swift environments. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + + \return \c YES to delay the relaunch. + */ +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item; + /*! Returns whether the application should be relaunched at all. @@ -280,6 +295,18 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation; +/*! + Called when an update is scheduled to be silently installed on quit. + This is after an update has been automatically downloaded in the background. + (i.e. SUUpdater::automaticallyDownloadsUpdates is YES) + This method acts as a more modern alternative to SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation: using a block instead of NSInvocation, which is not available in Swift environments. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + \param installationBlock Can be used to trigger an immediate silent install and relaunch. + */ +- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)(void))installationBlock; + /*! Calls after an update that was scheduled to be silently installed on quit has been canceled.