diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index b90fc21b..3aa1ab30 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -79,6 +79,12 @@ [self.coreDriver downloadUpdateFromAppcastItem:updateItem]; } +// Method used for backwards compatibility for the updater delegate +- (void)finishInstallationAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showingUI +{ + [self.coreDriver finishInstallationWithResponse:(relaunch ? SUInstallAndRelaunchUpdateNow : SUInstallUpdateNow) displayingUserInterface:showingUI]; +} + - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently { self.willInstallSilently = willInstallSilently; @@ -86,11 +92,33 @@ if (!willInstallImmediately) { BOOL installationHandledByDelegate = NO; id updaterDelegate = self.updaterDelegate; - if (self.willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) { - __weak SUAutomaticUpdateDriver *weakSelf = self; - installationHandledByDelegate = [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{ - [weakSelf.coreDriver finishInstallationWithResponse:SUInstallAndRelaunchUpdateNow displayingUserInterface:NO]; - }]; + if (self.willInstallSilently) { + if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) { + __weak SUAutomaticUpdateDriver *weakSelf = self; + installationHandledByDelegate = [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{ + [weakSelf.coreDriver finishInstallationWithResponse:SUInstallAndRelaunchUpdateNow displayingUserInterface:NO]; + }]; + } else if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)]) { + // Just for backwards compatibility + + BOOL relaunch = YES; + BOOL showUI = NO; + + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(finishInstallationAndRelaunch:displayingUserInterface:)]]; + [invocation setSelector:@selector(finishInstallationAndRelaunch:displayingUserInterface:)]; + [invocation setArgument:&relaunch atIndex:2]; + [invocation setArgument:&showUI atIndex:3]; + [invocation setTarget:self]; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; +#pragma clang diagnostic pop + + // We have to assume they will handle the installation since they implement this method + // Not ideal, but this is why this delegate callback is deprecated + installationHandledByDelegate = YES; + } } if (!installationHandledByDelegate) { diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index bad493f9..65c7228a 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -291,7 +291,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param item The appcast item corresponding to the update that is proposed to be installed. \param invocation Can be used to trigger an immediate silent install and relaunch. - \deprecated See -updater:willInstallUpdateOnQuit:immediateInstallationBlock: instead. This method is no longer invoked. + \deprecated See -updater:willInstallUpdateOnQuit:immediateInstallationBlock: instead. If this method is implemented, Sparkle will assume the delegate is given responsibility to handling the update without a choice. For this reason, please don't implement this method. */ - (void)updater:(id)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation __deprecated;