From ebb1f017359656f53bc7d930af69c0912f4c78e9 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Fri, 30 May 2008 22:38:33 -0700 Subject: [PATCH] Removed the checkInterval IV and factored out its assignment to a checkInterval method in SUUpdater. Now when future updates are scheduled after an initial one exits, they'll use the current interval. --- SUUpdater.h | 1 - SUUpdater.m | 32 +++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/SUUpdater.h b/SUUpdater.h index cd35cca8..5eea61a3 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -12,7 +12,6 @@ @class SUUpdateDriver; @interface SUUpdater : NSObject { NSTimer *checkTimer; - NSTimeInterval checkInterval; SUUpdateDriver *driver; NSBundle *hostBundle; diff --git a/SUUpdater.m b/SUUpdater.m index f3fd34d7..f1e53462 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -14,6 +14,7 @@ - (NSArray *)feedParameters; - (BOOL)automaticallyUpdates; - (BOOL)shouldScheduleUpdateCheck; +- (NSTimeInterval)checkInterval; @end @implementation SUUpdater @@ -82,16 +83,7 @@ static SUUpdater *sharedUpdater = nil; } - (void)beginUpdateCycle -{ - // Find the stored check interval. User defaults override Info.plist. - if ([[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey]) - checkInterval = [[[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey] doubleValue]; - else if ([hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey]) - checkInterval = [[hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey] doubleValue]; - - if (checkInterval < SU_MIN_CHECK_INTERVAL) // This can also mean one that isn't set. - checkInterval = SU_DEFAULT_CHECK_INTERVAL; - +{ // How long has it been since last we checked for an update? NSDate *lastCheckDate = [[SUUserDefaults standardUserDefaults] objectForKey:SULastCheckTimeKey]; if (!lastCheckDate) { lastCheckDate = [NSDate distantPast]; } @@ -99,8 +91,8 @@ static SUUpdater *sharedUpdater = nil; // Now we want to figure out how long until we check again. NSTimeInterval delayUntilCheck; - if (intervalSinceCheck < checkInterval) - delayUntilCheck = (checkInterval - intervalSinceCheck); // It hasn't been long enough. + if (intervalSinceCheck < [self checkInterval]) + delayUntilCheck = ([self checkInterval] - intervalSinceCheck); // It hasn't been long enough. else delayUntilCheck = 0; // We're overdue! Run one now. @@ -143,7 +135,7 @@ static SUUpdater *sharedUpdater = nil; [driver removeObserver:self forKeyPath:@"finished"]; [driver release]; driver = nil; if ([self shouldScheduleUpdateCheck]) - checkTimer = [NSTimer scheduledTimerWithTimeInterval:checkInterval target:self selector:@selector(checkForUpdatesInBackground) userInfo:nil repeats:NO]; + checkTimer = [NSTimer scheduledTimerWithTimeInterval:[self checkInterval] target:self selector:@selector(checkForUpdatesInBackground) userInfo:nil repeats:NO]; } - (BOOL)shouldScheduleUpdateCheck @@ -188,6 +180,20 @@ static SUUpdater *sharedUpdater = nil; return parameters; } +- (NSTimeInterval)checkInterval +{ + NSTimeInterval checkInterval = 0; + // Find the stored check interval. User defaults override Info.plist. + if ([[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey]) + checkInterval = [[[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey] doubleValue]; + else if ([hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey]) + checkInterval = [[hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey] doubleValue]; + + if (checkInterval < SU_MIN_CHECK_INTERVAL) // This can also mean one that isn't set. + checkInterval = SU_DEFAULT_CHECK_INTERVAL; + return checkInterval; +} + - (void)dealloc { [hostBundle release];