diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 103bc5ec..83ed7000 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -529,6 +529,12 @@ return (!self.updaterDelegate || ![self.updaterDelegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [self.updaterDelegate updaterShouldRelaunchApplication:self.updater]); } +// Only implemented due to backwards compability reasons; see -installWithToolAndRelaunch:displayingUserInterface: below +- (void)installWithToolAndRelaunch:(BOOL)relaunch +{ + [self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch]; +} + - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI { assert(self.updateItem); @@ -540,16 +546,29 @@ } // Give the host app an opportunity to postpone the install and relaunch. - if (!self.postponedOnce && [self.updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)]) + if (!self.postponedOnce) { - // NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]]; - // [invocation setSelector:@selector(installWithToolAndRelaunch:)]; - // [invocation setArgument:&relaunch atIndex:2]; - // [invocation setTarget:self]; - // self.postponedOnce = YES; - // if ([self.updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { - // return; - // } + if ([self.updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvokingBlock:)]) { + self.postponedOnce = YES; + __weak SUInstallerDriver *weakSelf = self; + if ([self.updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvokingBlock:^{ + [weakSelf installWithToolAndRelaunch:relaunch displayingUserInterface:showUI]; + }]) { + return; + } + } else if ([self.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]; + self.postponedOnce = YES; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if ([self.updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { +#pragma clang diagnostic pop + return; + } + } } // Set up local and remote ports to the installer if they are not set up already diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index c240c0c1..ff93e6bf 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -148,18 +148,37 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item; /*! + \deprecated Use -updater:shouldPostponeRelaunchForUpdate:untilInvokingBlock: instead 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 may also not be called if the application is not going to relaunch after it terminates. + \param updater The SUUpdater instance. \param item The appcast item corresponding to the update that is proposed to be installed. \param invocation The invocation that must be completed before continuing with the relaunch. \return \c YES to delay the relaunch until \p invocation is invoked. */ -- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvoking:(NSInvocation *)invocation; +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvoking:(NSInvocation *)invocation __deprecated; + +/*! + 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 may also not be called if the application is not going to relaunch after it terminates. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + \param installHandler The install handler that must be completed before continuing with the relaunch. + + \return \c YES to delay the relaunch until \p installHandler is invoked. + */ +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvokingBlock:(void (^)(void))installHandler; /*! Returns whether the application should be relaunched at all.