diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h
index c0380dd8..1d8b1d01 100644
--- a/Sparkle/SUAppcastItem.h
+++ b/Sparkle/SUAppcastItem.h
@@ -20,6 +20,7 @@
SU_EXPORT @interface SUAppcastItem : NSObject
@property (copy, readonly) NSString *title;
@property (copy, readonly) NSString *dateString;
+@property (copy, readonly) NSDate *date;
@property (copy, readonly) NSString *itemDescription;
@property (strong, readonly) NSURL *releaseNotesURL;
@property (strong, readonly) SUSignatures *signatures;
@@ -32,6 +33,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject
@property (copy, readonly) NSString *displayVersionString;
@property (copy, readonly) NSDictionary *deltaUpdates;
@property (strong, readonly) NSURL *infoURL;
+@property (copy, readonly) NSNumber* phasedRolloutInterval;
// Initializes with data from a dictionary provided by the RSS class.
- (instancetype)initWithDictionary:(NSDictionary *)dict;
diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m
index f265b54e..20fc1a1a 100644
--- a/Sparkle/SUAppcastItem.m
+++ b/Sparkle/SUAppcastItem.m
@@ -28,6 +28,7 @@
@property (copy, readwrite) NSDictionary *deltaUpdates;
@property (strong, readwrite) NSURL *infoURL;
@property (readwrite, copy) NSDictionary *propertiesDictionary;
+@property (copy, readwrite) NSNumber* phasedRolloutInterval;
@end
@implementation SUAppcastItem
@@ -46,6 +47,7 @@
@synthesize versionString;
@synthesize osString;
@synthesize propertiesDictionary;
+@synthesize phasedRolloutInterval;
- (BOOL)isDeltaUpdate
{
@@ -63,6 +65,18 @@
return self.osString == nil || [self.osString isEqualToString:SUAppcastAttributeValueMacOS];
}
+- (NSDate*)date {
+ if(self.dateString == nil) {
+ return nil;
+ }
+
+ NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
+ dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
+ dateFormatter.dateFormat = @"E, dd MMM yyyy HH:mm:ss Z";
+
+ return [dateFormatter dateFromString:self.dateString];
+}
+
- (BOOL)isInformationOnlyUpdate
{
return self.infoURL && !self.fileURL;
@@ -175,6 +189,8 @@
self.displayVersionString = self.versionString;
}
+ self.phasedRolloutInterval = [enclosure objectForKey:SUAppcastElementPhasedRolloutInterval];
+
// Find the appropriate release notes URL.
NSString *releaseNotesString = [dict objectForKey:SUAppcastElementReleaseNotesLink];
if (releaseNotesString) {
diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h
index f84995c0..2c48e949 100644
--- a/Sparkle/SUConstants.h
+++ b/Sparkle/SUConstants.h
@@ -50,6 +50,7 @@ extern NSString *const SUAllowsAutomaticUpdatesKey;
extern NSString *const SUEnableAutomaticChecksKey;
extern NSString *const SUEnableSystemProfilingKey;
extern NSString *const SUSendProfileInfoKey;
+extern NSString *const SUUpdateGroupIdentifierKey;
extern NSString *const SULastProfileSubmitDateKey;
extern NSString *const SUPromptUserOnFirstLaunchKey;
extern NSString *const SUDefaultsDomainKey;
@@ -71,14 +72,13 @@ extern NSString *const SUAppcastAttributeShortVersionString;
extern NSString *const SUAppcastAttributeVersion;
extern NSString *const SUAppcastAttributeOsType;
-
-
extern NSString *const SUAppcastElementCriticalUpdate;
extern NSString *const SUAppcastElementDeltas;
extern NSString *const SUAppcastElementMinimumSystemVersion;
extern NSString *const SUAppcastElementMaximumSystemVersion;
extern NSString *const SUAppcastElementReleaseNotesLink;
extern NSString *const SUAppcastElementTags;
+extern NSString *const SUAppcastElementPhasedRolloutInterval;
extern NSString *const SURSSAttributeURL;
extern NSString *const SURSSAttributeLength;
diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m
index 309d9d89..f50483c1 100644
--- a/Sparkle/SUConstants.m
+++ b/Sparkle/SUConstants.m
@@ -42,6 +42,7 @@ NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates";
NSString *const SUEnableSystemProfilingKey = @"SUEnableSystemProfiling";
NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks";
NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo";
+NSString *const SUUpdateGroupIdentifierKey = @"SUUpdateGroupIdentifier";
NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate";
NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch";
NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript";
@@ -67,6 +68,7 @@ NSString *const SUAppcastElementMinimumSystemVersion = @"sparkle:minimumSystemVe
NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVersion";
NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink";
NSString *const SUAppcastElementTags = @"sparkle:tags";
+NSString *const SUAppcastElementPhasedRolloutInterval = @"sparkle:phasedRolloutInterval";
NSString *const SURSSAttributeURL = @"url";
NSString *const SURSSAttributeLength = @"length";
diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h
index 4880d1e7..d0d4b70a 100644
--- a/Sparkle/SUHost.h
+++ b/Sparkle/SUHost.h
@@ -31,4 +31,7 @@
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName;
- (id)objectForKey:(NSString *)key;
- (BOOL)boolForKey:(NSString *)key;
+
+- (NSNumber*)updateGroupIdentifier;
+- (NSNumber*)setNewUpdateGroupIdentifier;
@end
diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m
index 015dfe69..2529a565 100644
--- a/Sparkle/SUHost.m
+++ b/Sparkle/SUHost.m
@@ -246,4 +246,22 @@
return [self objectForUserDefaultsKey:key] ? [self boolForUserDefaultsKey:key] : [self boolForInfoDictionaryKey:key];
}
+- (NSNumber*)updateGroupIdentifier {
+ NSNumber* updateGroupIdentifier = [self objectForUserDefaultsKey:SUUpdateGroupIdentifierKey];
+ if(updateGroupIdentifier == nil) {
+ updateGroupIdentifier = [self setNewUpdateGroupIdentifier];
+ }
+
+ return updateGroupIdentifier;
+}
+
+- (NSNumber*)setNewUpdateGroupIdentifier {
+ unsigned int r = arc4random_uniform(UINT_MAX);
+ NSNumber* updateGroupIdentifier = @(r);
+
+ [self setObject:updateGroupIdentifier forUserDefaultsKey:SUUpdateGroupIdentifierKey];
+
+ return updateGroupIdentifier;
+}
+
@end
diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m
index 01e094bf..e19ca604 100644
--- a/Sparkle/SUScheduledUpdateDriver.m
+++ b/Sparkle/SUScheduledUpdateDriver.m
@@ -10,6 +10,10 @@
#import "SUUpdaterPrivate.h"
#import "SUUpdaterDelegate.h"
+#import "SUSystemUpdateInfo.h"
+#import "SUAppcastItem.h"
+#import "SUHost.h"
+
@interface SUScheduledUpdateDriver ()
@end
@@ -24,6 +28,30 @@
return self;
}
+- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui {
+ return [self isItemReadyForUpdateGroup:ui] && [super itemContainsValidUpdate:ui];
+}
+
+- (BOOL)isItemReadyForUpdateGroup:(SUAppcastItem *)ui {
+ if([ui isCriticalUpdate] || ![ui phasedRolloutInterval]) {
+ return YES;
+ }
+
+ NSDate* itemReleaseDate = ui.date;
+ if(itemReleaseDate) {
+ NSTimeInterval timeSinceRelease = [[NSDate date] timeIntervalSinceDate:itemReleaseDate];
+
+ NSTimeInterval phasedRolloutInterval = [[ui phasedRolloutInterval] doubleValue];
+ NSTimeInterval timeToWaitForGroup = phasedRolloutInterval * [SUSystemUpdateInfo updateGroupForHost:self.host];
+
+ if(timeSinceRelease < timeToWaitForGroup) {
+ return NO; // not this host's turn yet
+ }
+ }
+
+ return YES;
+}
+
- (void)didFindValidUpdate
{
self.showErrors = YES; // We only start showing errors after we present the UI for the first time.
@@ -58,4 +86,9 @@
return [super shouldShowUpdateAlertForItem:item];
}
+- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable) downloadData {
+ [self.host setNewUpdateGroupIdentifier]; // use new update group next time
+ [super downloaderDidFinishWithTemporaryDownloadData:downloadData];
+}
+
@end
diff --git a/Sparkle/SUSystemUpdateInfo.h b/Sparkle/SUSystemUpdateInfo.h
index 28f89978..69ee0317 100644
--- a/Sparkle/SUSystemUpdateInfo.h
+++ b/Sparkle/SUSystemUpdateInfo.h
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUSystemUpdateInfo : NSObject
+ (BOOL)systemAllowsAutomaticUpdatesForHost:(SUHost *)host;
++ (NSUInteger)updateGroupForHost:(SUHost *)host;
@end
diff --git a/Sparkle/SUSystemUpdateInfo.m b/Sparkle/SUSystemUpdateInfo.m
index 78325eae..6f05d0e5 100644
--- a/Sparkle/SUSystemUpdateInfo.m
+++ b/Sparkle/SUSystemUpdateInfo.m
@@ -58,4 +58,10 @@
return changeOwnerAndGroupSuccess;
}
+#define NUM_UPDATE_GROUPS 7
++ (NSUInteger)updateGroupForHost:(SUHost *)host {
+ NSNumber* updateGroupIdentifier = [host updateGroupIdentifier];
+ return ([updateGroupIdentifier unsignedIntValue] % NUM_UPDATE_GROUPS);
+}
+
@end
diff --git a/TestApplication/sparkletestcast.xml b/TestApplication/sparkletestcast.xml
index b74b0220..05010a0d 100644
--- a/TestApplication/sparkletestcast.xml
+++ b/TestApplication/sparkletestcast.xml
@@ -17,7 +17,7 @@
]]>
Sat, 26 Jul 2014 15:20:11 +0000
-
+