Allow to configure update groups for updating in phases (#1381)

This commit is contained in:
Fabian Jäger authored and Kornel committed 2019-03-20 12:45:48 +00:00
1 parent f550b92f72
commit 26db6982b3
10 files changed
+84 -3

No files matched your search

+2
View File
@@ -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;
+16
View File
@@ -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) {
+2 -2
View File
@@ -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;
+2
View File
@@ -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";
+3
View File
@@ -31,4 +31,7 @@
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName;
- (id)objectForKey:(NSString *)key;
- (BOOL)boolForKey:(NSString *)key;
- (NSNumber*)updateGroupIdentifier;
- (NSNumber*)setNewUpdateGroupIdentifier;
@end
+18
View File
@@ -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
+33
View File
@@ -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
+1
View File
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUSystemUpdateInfo : NSObject
+ (BOOL)systemAllowsAutomaticUpdatesForHost:(SUHost *)host;
+ (NSUInteger)updateGroupForHost:(SUHost *)host;
@end
+6
View File
@@ -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
+1 -1
View File
@@ -17,7 +17,7 @@
]]>
</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="2.0" length="$INSERT_ARCHIVE_LENGTH" type="application/octet-stream" sparkle:edSignature="$INSERT_EDDSA_SIGNATURE" />
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="2.0" length="$INSERT_ARCHIVE_LENGTH" type="application/octet-stream" sparkle:edSignature="$INSERT_EDDSA_SIGNATURE" sparkle:phasedRolloutInterval="25200" />
</item>
</channel>
</rss>