From 3c0e02f3337b53a037bfebd2678ac1da2211dd82 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 16 Jan 2021 18:13:58 -0800 Subject: [PATCH] Integrate "Fix #1061 & #835: Sparkle clients polling too frequently" https://github.com/sparkle-project/Sparkle/pull/1135 --- Sparkle/SPUUpdater.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 2f128e3d..391de321 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -57,6 +57,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @property (nonatomic, copy) void (^preStartedScheduledUpdateBlock)(void); @property (nonatomic, nullable) id resumableUpdate; +@property (nonatomic, copy) NSDate *updateLastCheckedDate; + @property (nonatomic) BOOL loggedATSWarning; @property (nonatomic) BOOL loggedDSAWarning; @@ -78,6 +80,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize startedUpdater = _startedUpdater; @synthesize preStartedScheduledUpdateBlock = _preStartedScheduledUpdateBlock; @synthesize resumableUpdate = _resumableUpdate; +@synthesize updateLastCheckedDate = _updateLastCheckedDate; @synthesize loggedATSWarning = _loggedATSWarning; @synthesize loggedDSAWarning = _loggedDSAWarning; @@ -324,13 +327,20 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (NSDate *)lastUpdateCheckDate { - return [self.host objectForUserDefaultsKey:SULastCheckTimeKey]; + if ([self updateLastCheckedDate] == nil) + { + [self setUpdateLastCheckedDate:[self.host objectForUserDefaultsKey:SULastCheckTimeKey]]; + } + + return [self updateLastCheckedDate]; } - (void)updateLastUpdateCheckDate { [self willChangeValueForKey:NSStringFromSelector(@selector((lastUpdateCheckDate)))]; - [self.host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey]; + // We use an intermediate property for last update check date due to https://github.com/sparkle-project/Sparkle/pull/1135 + [self setUpdateLastCheckedDate:[NSDate date]]; + [self.host setObject:[self updateLastCheckedDate] forUserDefaultsKey:SULastCheckTimeKey]; [self didChangeValueForKey:NSStringFromSelector(@selector((lastUpdateCheckDate)))]; }