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])