From c21e1aba35451c8e1571104ab54d4eff0baa6401 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Sun, 17 Aug 2008 13:25:49 -0700 Subject: [PATCH] Fixes 258529 and 257967 Added backwards compatibility support for Sparkle 1.1's behavior of disabling automatic updates when the check interval was 0. Sparkle will now properly reset the update cycle when setAutomaticallyChecksForUpdates or setUpdateCheckInterval is called for non-.app bundles. --- SUUpdater.m | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/SUUpdater.m b/SUUpdater.m index 53fb9454..aa231532 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -151,9 +151,11 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv NSTimeInterval intervalSinceCheck = [[NSDate date] timeIntervalSinceDate:lastCheckDate]; // Now we want to figure out how long until we check again. - NSTimeInterval delayUntilCheck; - if (intervalSinceCheck < [self updateCheckInterval]) - delayUntilCheck = ([self updateCheckInterval] - intervalSinceCheck); // It hasn't been long enough. + NSTimeInterval delayUntilCheck, updateCheckInterval = [self updateCheckInterval]; + if (updateCheckInterval < SU_MIN_CHECK_INTERVAL) + updateCheckInterval = SU_MIN_CHECK_INTERVAL; + if (intervalSinceCheck < updateCheckInterval) + delayUntilCheck = (updateCheckInterval - intervalSinceCheck); // It hasn't been long enough. else delayUntilCheck = 0; // We're overdue! Run one now. checkTimer = [NSTimer scheduledTimerWithTimeInterval:delayUntilCheck target:self selector:@selector(checkForUpdatesInBackground) userInfo:nil repeats:NO]; @@ -229,10 +231,20 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv - (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyCheckForUpdates { [host setBool:automaticallyCheckForUpdates forUserDefaultsKey:SUEnableAutomaticChecksKey]; + // Hack to support backwards compatibility with older Sparkle versions, which supported + // disabling updates by setting the check interval to 0. + if (automaticallyCheckForUpdates && [self updateCheckInterval] == 0) + [self setUpdateCheckInterval:SU_DEFAULT_CHECK_INTERVAL]; + [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil]; + // Provide a small delay in case multiple preferences are being updated simultaneously. + [self performSelector:@selector(resetUpdateCycle) withObject:nil afterDelay:1]; } - (BOOL)automaticallyChecksForUpdates { + // Don't automatically update when the check interval is 0, to be compatible with 1.1 settings. + if ([self updateCheckInterval] == 0) + return NO; return [host boolForKey:SUEnableAutomaticChecksKey]; } @@ -320,16 +332,22 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv - (void)setUpdateCheckInterval:(NSTimeInterval)updateCheckInterval { [host setObject:[NSNumber numberWithDouble:updateCheckInterval] forUserDefaultsKey:SUScheduledCheckIntervalKey]; + if (updateCheckInterval == 0) // For compatibility with 1.1's settings. + [self setAutomaticallyChecksForUpdates:NO]; + [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil]; + + // Provide a small delay in case multiple preferences are being updated simultaneously. + [self performSelector:@selector(resetUpdateCycle) withObject:nil afterDelay:1]; } - (NSTimeInterval)updateCheckInterval { // Find the stored check interval. User defaults override Info.plist. - NSTimeInterval checkInterval = [[host objectForKey:SUScheduledCheckIntervalKey] doubleValue]; - - if (checkInterval < SU_MIN_CHECK_INTERVAL) // This can also mean one that isn't set. - checkInterval = SU_DEFAULT_CHECK_INTERVAL; - return checkInterval; + NSNumber *intervalValue = [host objectForKey:SUScheduledCheckIntervalKey]; + if (intervalValue) + return [intervalValue doubleValue]; + else + return SU_DEFAULT_CHECK_INTERVAL; } - (void)dealloc