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