From b515c15f9b444f090cd0b542bb2480e486023a5e Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Tue, 4 Oct 2011 20:39:09 -0700 Subject: [PATCH 01/10] We have this check box that says "Automatically download and install updates in the future." But we only download them automatically. We still ask permission again before installing them. With this patch, we make good on the description of that box: updates are automatically installed when the app is quit. No user intervention involved whatsoever if they checked that box. If the user doesn't quit the app for a day after the update is downloaded, we'll show the dialog we've always used for automatically downloaded updates (Install Now / Install on Quit / Skip This Update). --- SUAutomaticUpdateDriver.h | 3 ++- SUAutomaticUpdateDriver.m | 44 ++++++++++++++++++++++++++++++++++----- SUBasicUpdateDriver.m | 2 -- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/SUAutomaticUpdateDriver.h b/SUAutomaticUpdateDriver.h index 266f6b69..c3d811ff 100644 --- a/SUAutomaticUpdateDriver.h +++ b/SUAutomaticUpdateDriver.h @@ -16,8 +16,9 @@ @interface SUAutomaticUpdateDriver : SUBasicUpdateDriver { @private - BOOL postponingInstallation, showErrors; + BOOL showErrors; SUAutomaticUpdateAlert *alert; + NSTimer *showUpdateAlertTimer; } @end diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 19a3c418..7bd9d05b 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -12,9 +12,12 @@ #import "SUHost.h" #import "SUConstants.h" +// If the user hasn't quit in a day, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise. +static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24; + @implementation SUAutomaticUpdateDriver -- (void)unarchiverDidFinish:(SUUnarchiver *)ua +- (void)showUpdateAlert { alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem host:host delegate:self]; @@ -33,6 +36,39 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } +- (void)unarchiverDidFinish:(SUUnarchiver *)ua +{ + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + + showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; +} + +- (void)stopUpdatingOnTermination +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; +} + +- (void)invalidateShowUpdateAlertTimer +{ + [showUpdateAlertTimer invalidate]; + [showUpdateAlertTimer release]; + showUpdateAlertTimer = nil; +} + +- (void)dealloc +{ + [self invalidateShowUpdateAlertTimer]; + [alert release]; + [super dealloc]; +} + +- (void)abortUpdate +{ + [self stopUpdatingOnTermination]; + [self invalidateShowUpdateAlertTimer]; + [super abortUpdate]; +} + - (void)applicationDidBecomeActive:(NSNotification *)aNotification { [[alert window] makeKeyAndOrderFront:self]; @@ -44,12 +80,12 @@ switch (choice) { case SUInstallNowChoice: + [self stopUpdatingOnTermination]; [self installWithToolAndRelaunch:YES]; break; case SUInstallLaterChoice: - postponingInstallation = YES; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + // No-op: we're already waiting on quit. break; case SUDoNotInstallChoice: @@ -59,8 +95,6 @@ } } -- (BOOL)shouldInstallSynchronously { return postponingInstallation; } - - (void)installWithToolAndRelaunch:(BOOL)relaunch { showErrors = YES; diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 158d271b..637aba78 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -252,8 +252,6 @@ [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:[NSDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey]]]; } -- (BOOL)shouldInstallSynchronously { return NO; } - - (void)installWithToolAndRelaunch:(BOOL)relaunch { if (![updater mayUpdateAndRestart]) From e64516c08939299acf4b3227ac6f37862646b63c Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 09:28:41 -0700 Subject: [PATCH 02/10] Fixed a no-autorelease-pool leak. --- SUPipedUnarchiver.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index 3a2e4cf3..5c82dbc8 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -48,11 +48,12 @@ { // *** GETS CALLED ON NON-MAIN THREAD!!! - SULog(@"Extracting %@ using '%@'",archivePath,command); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; FILE *fp = NULL, *cmdFP = NULL; + SULog(@"Extracting %@ using '%@'",archivePath,command); + // Get the file size. #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize]; @@ -98,7 +99,7 @@ reportError: finally: if (fp) fclose(fp); - [pool drain]; + [pool release]; } - (void)extractTAR From bf38b0c9fdf06969ad37aef397c25b0538436134 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 10:56:37 -0700 Subject: [PATCH 03/10] Adding appcast item element, tag You would use this like: My great update ... The behavior of this tag presently is: rather than waiting for the user to quit the app (or for some large amount of time to pass), the user will be prompted to install the update (with a stronger message) immediately upon its receipt. This behavior could be improved for the manual update case as well. We can also use this new mechanism to create special behavior for e.g. paid updates. --- SUAppcastItem.h | 3 ++- SUAppcastItem.m | 5 +++++ SUAutomaticUpdateAlert.m | 18 ++++++++++++++++-- SUAutomaticUpdateDriver.m | 13 ++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/SUAppcastItem.h b/SUAppcastItem.h index d1067321..5c91b88c 100644 --- a/SUAppcastItem.h +++ b/SUAppcastItem.h @@ -28,7 +28,7 @@ NSDictionary *deltaUpdates; NSDictionary *propertiesDictionary; - + NSURL *infoURL; // UK 2007-08-31 } @@ -47,6 +47,7 @@ - (NSString *)minimumSystemVersion; - (NSDictionary *)deltaUpdates; - (BOOL)isDeltaUpdate; +- (BOOL)isCriticalUpdate; // Returns the dictionary provided in initWithDictionary; this might be useful later for extensions. - (NSDictionary *)propertiesDictionary; diff --git a/SUAppcastItem.m b/SUAppcastItem.m index 57680557..5a46f2ff 100644 --- a/SUAppcastItem.m +++ b/SUAppcastItem.m @@ -130,6 +130,11 @@ return [[propertiesDictionary objectForKey:@"enclosure"] objectForKey:@"sparkle:deltaFrom"] != nil; } +- (BOOL)isCriticalUpdate +{ + return [[propertiesDictionary objectForKey:@"sparkle:tags"] containsObject:@"sparkle:criticalUpdate"]; +} + - initWithDictionary:(NSDictionary *)dict { return [self initWithDictionary:dict failureReason:nil]; diff --git a/SUAutomaticUpdateAlert.m b/SUAutomaticUpdateAlert.m index f055f48d..65f84bed 100644 --- a/SUAutomaticUpdateAlert.m +++ b/SUAutomaticUpdateAlert.m @@ -60,12 +60,26 @@ - (NSString *)titleText { - return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [host name]]; + if ([updateItem isCriticalUpdate]) + { + return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil)]; + } + else + { + return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [host name]]; + } } - (NSString *)descriptionText { - return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]]; + if ([updateItem isCriticalUpdate]) + { + return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! This is an important update; would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]]; + } + else + { + return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]]; + } } @end diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 7bd9d05b..04ccf170 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -38,9 +38,16 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)unarchiverDidFinish:(SUUnarchiver *)ua { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; - - showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; + // If this is marked as a critical update, we'll prompt the user to install it right away. + if ([updateItem isCriticalUpdate]) + { + [self showUpdateAlert]; + } + else + { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; + } } - (void)stopUpdatingOnTermination From bb682da743fbeb65fcc6d7def976199f736ef288 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 22:44:17 -0700 Subject: [PATCH 04/10] Prompts the user to update after a week (rather than a day) if he doesn't quit the app. --- SUAutomaticUpdateDriver.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 04ccf170..32b3a463 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -12,8 +12,8 @@ #import "SUHost.h" #import "SUConstants.h" -// If the user hasn't quit in a day, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise. -static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24; +// If the user hasn't quit in a week, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise. +static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24 * 7; @implementation SUAutomaticUpdateDriver From 8f5b9f03ac11b1e55afab2dfbe3e1922ae2cca0a Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 22:49:49 -0700 Subject: [PATCH 05/10] Updating Sparkle.strings for the new, more strongly worded strings that are displayed for a 'critical update' --- en.lproj/Sparkle.strings | Bin 9058 -> 9382 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/en.lproj/Sparkle.strings b/en.lproj/Sparkle.strings index ebfa934be8974db2d7cef8197f880a60cfbbfca6..1332d2660369868d78d674b4c88f988baeaa650a 100644 GIT binary patch delta 487 zcmaFlw#;+F4(kwx42DdGVg>~$naGd_X6G^#Fyu27F_bWXL`r~Sr9hDsAg_cWmBAXw zFQ44cm_Av7F^@tsj&F>SV4r-2O=5Ewdk4?tcU%FgnGE=?R{%O9fAV@ReN!c%Lu`Rq ziNTR5hr@MF_L1hB{7O=4vyR9<)_O;V9I(HNfQCSP2vV2{#5q9UDlnvh!$N^Uoxu~R zq8KQi2$abI%7h|?iaL;=1PrGVAj}6lryLl%sbE$Km{kPise?m152!)`7@qkICbSjcN;z$4^6AyTjYLHCsWDZ zpW2rlQF0<}X<^mH(;w;8;vx1Her;*OdLa(}o4BcBr|5;RFAeOf_y$%b z9dThPOQeeNaIvo;s;r%Pr@J?T-ZI`Tc+-#Bd{p9^td^W(UE!7p z%)?4pDQ{SF!&L3#Og6MJBB+RL9C#2lu!3O@7X%@xHGC^r3dDU7AutKsrd(Ujq}iKL z@1gCi6c9%K4ave`v_l;eKv=RN#31(%FkMoK?x6bvzO0x%wNL<=+K6Q?2L+NRbAIDi zaF0&nhJB|J9x9@rjWZ)G({pyhGkC+)nv%=Ibs46*3Gx788yL#nKX>*w zfdI*Z#mC7tvJJ~I5SLnTY#?;z$0$Z6VqO`|by%pgrLQCLxgc@y25F_<6zM>Abu3+o KE&*vnqF7&JfzQVP From bc458a6ab5e099589f25b3261ea5a965cbcbabdf Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Sun, 12 Feb 2012 16:22:37 -0700 Subject: [PATCH 06/10] Set up install on quit for critical automatic updates too Fixes the SUInstallLaterChoice for critical update prompts. --- SUAutomaticUpdateDriver.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 32b3a463..17e04b89 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -38,6 +38,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)unarchiverDidFinish:(SUUnarchiver *)ua { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + // If this is marked as a critical update, we'll prompt the user to install it right away. if ([updateItem isCriticalUpdate]) { @@ -45,7 +47,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } else { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; } } @@ -64,6 +65,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)dealloc { + [self stopUpdatingOnTermination]; [self invalidateShowUpdateAlertTimer]; [alert release]; [super dealloc]; From 1d8adc8fac21ce10cc2432f8c78f1620b90ea916 Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Sun, 12 Feb 2012 17:12:50 -0700 Subject: [PATCH 07/10] Increment the sudden termination counter if installing on quit --- SUAutomaticUpdateDriver.h | 1 + SUAutomaticUpdateDriver.m | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/SUAutomaticUpdateDriver.h b/SUAutomaticUpdateDriver.h index c3d811ff..54b467e3 100644 --- a/SUAutomaticUpdateDriver.h +++ b/SUAutomaticUpdateDriver.h @@ -17,6 +17,7 @@ { @private BOOL showErrors; + BOOL willUpdateOnTermination; SUAutomaticUpdateAlert *alert; NSTimer *showUpdateAlertTimer; } diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 17e04b89..82ef5e8f 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -40,6 +40,14 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + // Sudden termination is available on 10.6+ + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + if ([processInfo respondsToSelector:@selector(disableSuddenTermination)]) { + [processInfo disableSuddenTermination]; + } + + willUpdateOnTermination = YES; + // If this is marked as a critical update, we'll prompt the user to install it right away. if ([updateItem isCriticalUpdate]) { @@ -53,7 +61,15 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)stopUpdatingOnTermination { - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; + if (willUpdateOnTermination) + { + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + if ([processInfo respondsToSelector:@selector(enableSuddenTermination)]) { + [processInfo enableSuddenTermination]; + } + willUpdateOnTermination = NO; + } } - (void)invalidateShowUpdateAlertTimer From 833081ffa9c85d5a25f1152c4a250cfcb67e4181 Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Sun, 12 Feb 2012 11:17:27 -0700 Subject: [PATCH 08/10] Support silent relaunches --- SUBasicUpdateDriver.h | 1 + SUBasicUpdateDriver.m | 15 ++++++++++++++- finish_installation.m | 23 ++++++++++++++--------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/SUBasicUpdateDriver.h b/SUBasicUpdateDriver.h index 21fe7171..4dc3afaf 100644 --- a/SUBasicUpdateDriver.h +++ b/SUBasicUpdateDriver.h @@ -47,6 +47,7 @@ - (void)failedToApplyDeltaUpdate; - (void)installWithToolAndRelaunch:(BOOL)relaunch; +- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI; - (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error; - (void)installWithToolAndRelaunch:(BOOL)relaunch; diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 1e71e1b6..c8562c1e 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -264,6 +264,12 @@ } - (void)installWithToolAndRelaunch:(BOOL)relaunch +{ + // Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them. + [self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch]; +} + +- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI { if (![updater mayUpdateAndRestart]) { @@ -321,7 +327,14 @@ if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"]; - [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects:[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", nil]]; + [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects: + [host bundlePath], + pathToRelaunch, + [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], + tempDir, + relaunch ? @"1" : @"0", + showUI ? @"1" : @"0", + nil]]; [NSApp terminate:self]; } diff --git a/finish_installation.m b/finish_installation.m index c0d2cc69..88b117b2 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -23,6 +23,7 @@ NSTimer *longInstallationTimer; SUHost *host; BOOL shouldRelaunch; + BOOL shouldShowUI; } - (void) parentHasQuit; @@ -37,8 +38,7 @@ @implementation TerminationListener -- (id) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath: (const char*)infolderpath shouldRelaunch:(BOOL)relaunch - selfPath: (NSString*)inSelfPath +- (id) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath:(const char*)infolderpath shouldRelaunch:(BOOL)relaunch shouldShowUI:(BOOL)showUI selfPath:(NSString*)inSelfPath { if( !(self = [super init]) ) return nil; @@ -49,6 +49,7 @@ folderpath = infolderpath; selfPath = [inSelfPath retain]; shouldRelaunch = relaunch; + shouldShowUI = showUI; BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already @@ -139,9 +140,8 @@ { NSBundle *theBundle = [NSBundle bundleWithPath: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: hostpath length:strlen(hostpath)]]; host = [[SUHost alloc] initWithBundle: theBundle]; - - // Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them. - if (shouldRelaunch) { + + if (shouldShowUI) { SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: host]; // We quit anyway after we've installed, so leak this for now. [statusCtl setButtonTitle: SULocalizedString(@"Cancel Update",@"") target: nil action: Nil isDefault: NO]; [statusCtl beginActionWithTitle: SULocalizedString(@"Installing update...",@"") @@ -162,8 +162,7 @@ - (void) installerForHost:(SUHost *)host failedWithError:(NSError *)error { - // Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them. - if (shouldRelaunch) + if (shouldShowUI) NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", [error localizedDescription] ); exit(EXIT_FAILURE); } @@ -172,14 +171,13 @@ int main (int argc, const char * argv[]) { - if( argc < 5 || argc > 6 ) + if( argc < 5 || argc > 7 ) return EXIT_FAILURE; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //ProcessSerialNumber psn = { 0, kCurrentProcess }; //TransformProcessType( &psn, kProcessTransformToForegroundApplication ); - [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; #if 0 // Cmdline tool NSString* selfPath = nil; @@ -193,6 +191,12 @@ int main (int argc, const char * argv[]) #else NSString* selfPath = [[NSBundle mainBundle] bundlePath]; #endif + + BOOL shouldShowUI = (argc > 6) ? atoi(argv[6]) : 1; + if (shouldShowUI) + { + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; + } [NSApplication sharedApplication]; [[[TerminationListener alloc] initWithHostPath: (argc > 1) ? argv[1] : NULL @@ -200,6 +204,7 @@ int main (int argc, const char * argv[]) parentProcessId: (argc > 3) ? atoi(argv[3]) : 0 folderPath: (argc > 4) ? argv[4] : NULL shouldRelaunch: (argc > 5) ? atoi(argv[5]) : 1 + shouldShowUI: shouldShowUI selfPath: selfPath] autorelease]; [[NSApplication sharedApplication] run]; From cdfcd1469edb6e9d9711829d711bd562558b227f Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Thu, 16 Feb 2012 01:44:21 -0700 Subject: [PATCH 09/10] 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 From 7fc9e32ce7c57cf3b40fa26d30950d59adb02368 Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Thu, 1 Mar 2012 22:41:49 -0700 Subject: [PATCH 10/10] Allow manual checks when an install on quit update is pending --- SUAutomaticUpdateDriver.m | 7 ++++++- SUUpdateDriver.h | 2 ++ SUUpdateDriver.m | 2 ++ SUUpdater.m | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 61018962..41e5503c 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -19,6 +19,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)showUpdateAlert { + isInterruptible = NO; alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem host:host delegate:self]; // If the app is a menubar app or the like, we need to focus it first and alter the @@ -69,6 +70,9 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 else { showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; + + // At this point the driver is idle, allow it to be interrupted for user-initiated update checks. + isInterruptible = YES; } } @@ -126,7 +130,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 break; case SUInstallLaterChoice: - // No-op: we're already waiting on quit. + // We're already waiting on quit, just indicate that we're idle. + isInterruptible = YES; break; case SUDoNotInstallChoice: diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 1a305d11..19100a60 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -21,11 +21,13 @@ extern NSString * const SUUpdateDriverFinishedNotification; NSURL *appcastURL; BOOL finished; + BOOL isInterruptible; } - initWithUpdater:(SUUpdater *)updater; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (void)abortUpdate; +- (BOOL)isInterruptible; - (BOOL)finished; @end diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index d98282a9..c844031b 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -33,6 +33,8 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self]; } +- (BOOL)isInterruptible { return isInterruptible; } + - (BOOL)finished { return finished; } - (void)dealloc diff --git a/SUUpdater.m b/SUUpdater.m index 7d426118..6858de18 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -288,6 +288,9 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault - (IBAction)checkForUpdates: (id)sender { + if (driver && [driver isInterruptible]) + [driver abortUpdate]; + [self checkForUpdatesWithDriver:[[[SUUserInitiatedUpdateDriver alloc] initWithUpdater:self] autorelease]]; }