diff --git a/Sparkle/SPUUpdater.h b/Sparkle/SPUUpdater.h index 1cb82ffa..71af6533 100644 --- a/Sparkle/SPUUpdater.h +++ b/Sparkle/SPUUpdater.h @@ -112,6 +112,7 @@ SU_EXPORT @interface SPUUpdater : NSObject and the `lastUpdateCheckDate`. Therefore, you should typically only consider calling this method directly if you opt out of automatic update checks. Calling this method when updating your own bundle is invalid if Sparkle is configured to ask the user's permission to check for updates automatically and `automaticallyChecksForUpdates` is `NO`. + If you want to reset the updater's cycle after an updater setting change, see `resetUpdateCycle` or `resetUpdateCycleAfterShortDelay` instead. This is meant for programmatically initating a check for updates in the background without the user initiating it. This check will not show UI if no new updates are found. @@ -334,15 +335,28 @@ SU_EXPORT @interface SPUUpdater : NSObject @property (nonatomic, readonly, copy, nullable) NSDate *lastUpdateCheckDate; /** - Appropriately schedules or cancels the update checking timer according to the settings for the time interval and automatic checks. - - If you change the `updateCheckInterval` or `automaticallyChecksForUpdates` properties, the update cycle will be reset automatically after a short delay. - The update cycle is also started automatically after the updater is started. In all these cases, this method should not be called directly. + Appropriately re-schedules the update checking timer according to the current updater settings. - This call does not change the date of the next check, but only the internal timer. + This method should only be called in response to a user changing updater settings. This method may trigger a new update check to occur in the background if an updater setting such as the updater's feed or allowed channels has changed. + + If the `updateCheckInterval` or `automaticallyChecksForUpdates` properties are changed, this method is automatically invoked after a short delay using `resetUpdateCycleAfterShortDelay`. In these cases, manually resetting the update cycle is not necessary. + + See also `resetUpdateCycleAfterShortDelay` which gives the user a short delay before triggering a cycle reset. */ - (void)resetUpdateCycle; +/** + Appropriately re-schedules the update checking timer according to the current updater settings after a short cancellable delay. + + This method calls `resetUpdateCycle` after a short delay to give the user a short amount of time to cancel changing an updater setting. + If this method is called again, any previous reset request that is still inflight will be cancelled. + + For example, if the user changes the `automaticallyChecksForUpdates` setting to `YES`, but quickly undoes their change then + no cycle reset will be done. + + If the `updateCheckInterval` or `automaticallyChecksForUpdates` properties are changed, this method is automatically invoked. In these cases, manually resetting the update cycle is not necessary. + */ +- (void)resetUpdateCycleAfterShortDelay; /** The system profile information that is sent when checking for updates. diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 7121aaa6..ea5acc93 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -65,7 +65,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification SPUUpdaterTimer *_updaterTimer; id _resumableUpdate; NSDate *_updateLastCheckedDate; - NSURL *_parameterizedFeedURL; + NSURL *_lastCheckedFeedURL; + NSSet * _lastAllowedChannels; __weak id _delegate; @@ -277,6 +278,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } if (feedURL != nil) { + _lastCheckedFeedURL = feedURL; + _lastAllowedChannels = [self allowedChannels]; + servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"]; if (!servingOverHttps && !_loggedATSWarning) { BOOL foundXPCDownloaderService = NO; @@ -833,6 +837,16 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification [_updaterCycle cancelNextUpdateCycle]; } +- (NSSet *)allowedChannels SPU_OBJC_DIRECT +{ + id delegate = _delegate; + if ([delegate respondsToSelector:@selector(allowedChannelsForUpdater:)]) { + return [delegate allowedChannelsForUpdater:self]; + } else { + return [NSSet set]; + } +} + - (void)resetUpdateCycle { if (!_startedUpdater) { @@ -841,14 +855,33 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } // Note this resets the opportune time when user grants Sparkle permission to check for updates - // and when the user changes preferences on automatically checking for updates or the update time check interval + // and when the user changes preferences on a Sparkle setting such as automatically checking for updates if ([_userDriver respondsToSelector:@selector(resetTimeSinceOpportuneUpdateNotice)]) { [(id)_userDriver resetTimeSinceOpportuneUpdateNotice]; } if (!_sessionInProgress) { [self cancelNextUpdateCycle]; - [self scheduleNextUpdateCheckFiringImmediately:NO usingCurrentDate:YES]; + + // If the non-parameterized feed URL or allowed set of channels have been changed by the user since the last update check, + // we can fire an update check in the background immediately + BOOL fireUpdateCheckImmediately = NO; + NSURL *lastCheckedFeedURL = _lastCheckedFeedURL; + if (lastCheckedFeedURL != nil) { + NSURL *currentFeedURL = [self retrieveFeedURL:NULL]; + if (currentFeedURL != nil) { + if (![currentFeedURL isEqual:lastCheckedFeedURL]) { + fireUpdateCheckImmediately = YES; + } else if (_lastAllowedChannels != nil) { + NSSet *currentAllowedChannels = [self allowedChannels]; + if (currentAllowedChannels != nil && ![currentAllowedChannels isEqualToSet:_lastAllowedChannels]) { + fireUpdateCheckImmediately = YES; + } + } + } + } + + [self scheduleNextUpdateCheckFiringImmediately:fireUpdateCheckImmediately usingCurrentDate:YES]; } }