diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index eac7f126..d57d3bc1 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -234,4 +234,9 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } } +- (BOOL)usesPhasedRollout +{ + return YES; +} + @end diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index b26a7910..9d1db5f9 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -27,6 +27,7 @@ - (BOOL)isItemNewer:(SUAppcastItem *)ui; - (BOOL)itemPreventsAutoupdate:(SUAppcastItem *)ui; - (BOOL)hostSupportsItem:(SUAppcastItem *)ui; +- (BOOL)usesPhasedRollout; - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui; - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui; - (void)appcastDidFinishLoading:(SUAppcast *)ac; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index d3237dff..292253e0 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -26,6 +26,7 @@ #import "SUAppcast.h" #import "SUAppcastItem.h" #import "SUGlobalUpdateLock.h" +#import "SUSystemUpdateInfo.h" #import "SPUURLRequest.h" #import "SPUDownloaderSession.h" @@ -145,7 +146,35 @@ return item; } +- (BOOL)usesPhasedRollout +{ + return NO; +} + +- (BOOL)isItemReadyForPhasedRollout:(SUAppcastItem *)ui { + if(![self usesPhasedRollout] || [ui isCriticalUpdate] || ![ui phasedRolloutInterval]) { + return YES; + } + + NSDate* itemReleaseDate = ui.date; + if(!itemReleaseDate) { + return YES; + } + + NSTimeInterval timeSinceRelease = [[NSDate date] timeIntervalSinceDate:itemReleaseDate]; + + NSTimeInterval phasedRolloutInterval = [[ui phasedRolloutInterval] doubleValue]; + NSTimeInterval timeToWaitForGroup = phasedRolloutInterval * [SUSystemUpdateInfo updateGroupForHost:self.host]; + + return timeSinceRelease >= timeToWaitForGroup; +} + - (BOOL)hostSupportsItem:(SUAppcastItem *)ui +{ + return [self hostSupportsOperatingSystemInItem:ui] && [self isItemReadyForPhasedRollout:ui]; +} + +- (BOOL)hostSupportsOperatingSystemInItem:(SUAppcastItem *)ui { BOOL osOK = [ui isMacOsUpdate]; if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) && @@ -358,6 +387,12 @@ { // finished. downloadData should be nil as this was a permanent download assert(self.updateItem); + + if (self.updateItem.phasedRolloutInterval != nil) { + // use new update group next time, even if the driver doesn't usesPhasedRollout + [SUSystemUpdateInfo setNewUpdateGroupIdentifierForHost:self.host]; + } + id updater = self.updater; if ([[updater delegate] respondsToSelector:@selector(updater:didDownloadUpdate:)]) { [[updater delegate] updater:self.updater didDownloadUpdate:self.updateItem]; diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 1c023f4b..7060b5b9 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -10,13 +10,8 @@ #import "SUUpdaterPrivate.h" #import "SUUpdaterDelegate.h" -#import "SUSystemUpdateInfo.h" #import "SUAppcastItem.h" -@interface SUScheduledUpdateDriver () -- (BOOL)isItemReadyForPhasedRollout:(SUAppcastItem *)ui; -@end - @implementation SUScheduledUpdateDriver - (instancetype)initWithUpdater:(id)anUpdater @@ -27,26 +22,9 @@ return self; } -- (BOOL)hostSupportsItem:(SUAppcastItem *)ui { - return [super hostSupportsItem:ui] && [self isItemReadyForPhasedRollout:ui]; -} - -- (BOOL)isItemReadyForPhasedRollout:(SUAppcastItem *)ui { - if([ui isCriticalUpdate] || ![ui phasedRolloutInterval]) { - return YES; - } - - NSDate* itemReleaseDate = ui.date; - if(!itemReleaseDate) { - return YES; - } - - NSTimeInterval timeSinceRelease = [[NSDate date] timeIntervalSinceDate:itemReleaseDate]; - - NSTimeInterval phasedRolloutInterval = [[ui phasedRolloutInterval] doubleValue]; - NSTimeInterval timeToWaitForGroup = phasedRolloutInterval * [SUSystemUpdateInfo updateGroupForHost:self.host]; - - return timeSinceRelease >= timeToWaitForGroup; +- (BOOL)usesPhasedRollout +{ + return YES; } - (void)didFindValidUpdate @@ -83,9 +61,4 @@ return [super shouldShowUpdateAlertForItem:item]; } -- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable) downloadData { - [SUSystemUpdateInfo setNewUpdateGroupIdentifierForHost:self.host]; // use new update group next time - [super downloaderDidFinishWithTemporaryDownloadData:downloadData]; -} - @end