From cdfcd1469edb6e9d9711829d711bd562558b227f Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Thu, 16 Feb 2012 01:44:21 -0700 Subject: [PATCH] Allow the delegate to trigger a silent install and relaunch --- SUAutomaticUpdateDriver.m | 25 ++++++++++++++++++++++--- SUUpdater.h | 5 +++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 82ef5e8f..61018962 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -48,6 +48,19 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 willUpdateOnTermination = YES; + if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)]) + { + BOOL relaunch = YES; + BOOL showUI = NO; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)]]; + [invocation setSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)]; + [invocation setArgument:&relaunch atIndex:2]; + [invocation setArgument:&showUI atIndex:3]; + [invocation setTarget:self]; + + [[updater delegate] updater:updater willInstallUpdateOnQuit:updateItem immediateInstallationInvocation:invocation]; + } + // If this is marked as a critical update, we'll prompt the user to install it right away. if ([updateItem isCriticalUpdate]) { @@ -69,6 +82,9 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [processInfo enableSuddenTermination]; } willUpdateOnTermination = NO; + + if ([[updater delegate] respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)]) + [[updater delegate] updater:updater didCancelInstallUpdateOnQuit:updateItem]; } } @@ -120,10 +136,13 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } } -- (void)installWithToolAndRelaunch:(BOOL)relaunch +- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI { - showErrors = YES; - [super installWithToolAndRelaunch:relaunch]; + if (relaunch) + [self stopUpdatingOnTermination]; + + showErrors = YES; + [super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI]; } - (void)applicationWillTerminate:(NSNotification *)note diff --git a/SUUpdater.h b/SUUpdater.h index ff04620c..7dc26bc3 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -138,6 +138,11 @@ -(void) updaterWillShowModalAlert:(SUUpdater *)updater; -(void) updaterDidShowModalAlert:(SUUpdater *)updater; +// Called when an update is scheduled to be silently installed on quit. +// The invocation can be used to trigger an immediate silent install and relaunch. +- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)update immediateInstallationInvocation:(NSInvocation *)invocation; +- (void)updater:(SUUpdater *)updater didCancelInstallUpdateOnQuit:(SUAppcastItem *)update; + @end