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 32b3a463..82ef5e8f 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -38,6 +38,16 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)unarchiverDidFinish:(SUUnarchiver *)ua { + [[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]) { @@ -45,14 +55,21 @@ 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]; } } - (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 @@ -64,6 +81,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)dealloc { + [self stopUpdatingOnTermination]; [self invalidateShowUpdateAlertTimer]; [alert release]; [super dealloc];