Add channels support to Sparkle

This allows developers to post updates to specific channels like for beta updates. Updaters only get notifications from channels they're allowed to be on.
This commit is contained in:
Zorg committed 2021-06-26 23:18:22 -07:00
1 parent fefce16697
commit 5fba1fe046
9 files changed
+70 -8

No files matched your search

+2 -2
View File
@@ -81,7 +81,7 @@
5D1AF5900FD767AD0065DB48 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */; };
5D1AF59A0FD767E50065DB48 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5990FD767E50065DB48 /* libz.dylib */; };
5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5F1510A11C96E591006E1629 /* testnamespaces.xml */; };
61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (); }; };
61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
61299A6009CA6EB100B7442F /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
61299B3609CB04E000B7442F /* Sparkle.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299B3509CB04E000B7442F /* Sparkle.h */; settings = {ATTRIBUTES = (Public, ); }; };
612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */; };
@@ -2313,6 +2313,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */,
61299B3609CB04E000B7442F /* Sparkle.h in Headers */,
72B767E61C9CFD7200A07552 /* SPUAutomaticUpdateDriver.h in Headers */,
72B767D61C9C8B5C00A07552 /* SPUBasicUpdateDriver.h in Headers */,
@@ -2357,7 +2358,6 @@
725602D51C83551C00DAA70E /* SUApplicationInfo.h in Headers */,
7214B8811D456A8500CB5CED /* SUBundleIcon.h in Headers */,
720767D31E2EE9C200F9A850 /* SUTouchBarForwardDeclarations.h in Headers */,
61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */,
55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */,
14652F8419A978C200959E44 /* SUExport.h in Headers */,
7267E5E51D3D90AA00D1BF90 /* SUFileManager.h in Headers */,
+29
View File
@@ -160,6 +160,35 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck)
*/
- (void)updater:(SPUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast;
/*!
Returns the set of Sparkle channels the updater is allowed to find new updates from.
An appcast item can specify a set of channels its update is posted to. Without specifying any channels, appcast items are posted to the default channel.
For instance:
<item>
<sparkle:version>2.0 Beta 1</sparkle:version>
<sparkle:channels>
<sparkle:beta/>
</sparkle:channels>
</item>
This example posts an update to the sparkle:beta channel, so only updaters that are allowed to use the sparkle:beta channel can find this update.
If the <sparkle:channels> is empty or not present, the update item is posted to the default channel and can be found by any complying updater.
Sparkle allows you to use the 'sparkle:beta' channel name (SUAppcastElementBetaChannel) for distributing beta updates to your own applications.
Otherwise you can use any other name you'd like; however, for other names you will need to use and define your own XML namespace tailored for your app.
To define your own namespace, add an attribute to rss element like xmlns:myapp="https://myappwebsite.net"
Note to use this feature, all app versions that your users may update from in your feed must use a version of Sparkle that supports this feature.
This feature was added in Sparkle 2.
\return The set of channel names the updater is allowed to find new updates in. An empty set is the default behavior,
which means the updater will only look for updates in the default channel.
*/
- (NSSet<NSString *> *)allowedChannelsForUpdater:(SPUUpdater *)updater;
/*!
Returns the item in the appcast corresponding to the update that should be installed.
+4 -4
View File
@@ -144,16 +144,16 @@
}
[dict setObject:deltas forKey:name];
}
else if ([name isEqualToString:SUAppcastElementTags]) {
NSMutableArray *tags = [NSMutableArray array];
else if ([name isEqualToString:SUAppcastElementTags] || [name isEqualToString:SUAppcastElementChannels]) {
NSMutableArray *names = [NSMutableArray array];
NSEnumerator *childEnum = [[node children] objectEnumerator];
for (NSXMLNode *child in childEnum) {
NSString *childName = child.name;
if (childName) {
[tags addObject:childName];
[names addObject:childName];
}
}
[dict setObject:tags forKey:name];
[dict setObject:names forKey:name];
}
else if ([name isEqualToString:SUAppcastElementInformationalUpdate]) {
NSMutableSet *informationalUpdateVersions = [NSMutableSet set];
+21 -2
View File
@@ -166,9 +166,28 @@
NSDictionary *userInfo = @{ SUUpdaterAppcastNotificationKey: loadedAppcast };
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:self.updater userInfo:userInfo];
// We will never care about other OS's
NSSet<NSString *> *allowedChannels;
if ([self.updaterDelegate respondsToSelector:@selector(allowedChannelsForUpdater:)]) {
allowedChannels = [self.updaterDelegate allowedChannelsForUpdater:self.updater];
} else {
allowedChannels = [NSSet set];
}
SUAppcast *macOSAppcast = [loadedAppcast copyByFilteringItems:^(SUAppcastItem *item) {
return (BOOL)[item isMacOsUpdate];
// We will never care about other OS's
BOOL macOSUpdate = [item isMacOsUpdate];
if (!macOSUpdate) {
return NO;
}
NSSet<NSString *> *channels = item.channels;
if (channels.count == 0) {
// Item is on the default channel
return YES;
}
// Item channels and allowed channels must have one channel in common
return [channels intersectsSet:allowedChannels];
}];
id<SUVersionComparison> applicationVersionComparator = [self versionComparator];
+1
View File
@@ -52,6 +52,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
@property (copy, readonly, nullable) NSNumber* phasedRolloutInterval;
@property (nonatomic, copy, readonly) NSString *installationType;
@property (copy, readonly, nullable) NSString *minimumAutoupdateVersion;
@property (nonatomic, readonly) NSSet<NSString *> *channels;
@property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate;
@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate;
+8
View File
@@ -73,6 +73,7 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState";
@synthesize state = _state;
@synthesize hasCriticalInformation = _hasCriticalInformation;
@synthesize informationalUpdateVersions = _informationalUpdateVersions;
@synthesize channels = _channels;
+ (BOOL)supportsSecureCoding
{
@@ -344,6 +345,13 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState";
}
return nil;
}
NSArray<NSString *> *channels = [dict objectForKey:SUAppcastElementChannels];
if (channels == nil) {
_channels = [NSSet set];
} else {
_channels = [NSSet setWithArray:channels];
}
_propertiesDictionary = [[NSDictionary alloc] initWithDictionary:dict];
_title = [(NSString *)[dict objectForKey:SURSSElementTitle] copy];
+2
View File
@@ -86,6 +86,8 @@ extern NSString *const SUAppcastElementReleaseNotesLink;
extern NSString *const SUAppcastElementTags;
extern NSString *const SUAppcastElementPhasedRolloutInterval;
extern NSString *const SUAppcastElementInformationalUpdate;
extern NSString *const SUAppcastElementChannels;
extern NSString *const SUAppcastElementBetaChannel;
extern NSString *const SURSSAttributeURL;
extern NSString *const SURSSAttributeLength;
+2
View File
@@ -80,6 +80,8 @@ NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink";
NSString *const SUAppcastElementTags = @"sparkle:tags";
NSString *const SUAppcastElementPhasedRolloutInterval = @"sparkle:phasedRolloutInterval";
NSString *const SUAppcastElementInformationalUpdate = @"sparkle:informationalUpdate";
NSString *const SUAppcastElementChannels = @"sparkle:channels";
NSString *const SUAppcastElementBetaChannel = @"sparkle:beta";
NSString *const SURSSAttributeURL = @"url";
NSString *const SURSSAttributeLength = @"length";
+1
View File
@@ -22,6 +22,7 @@
#import <Sparkle/SUVersionComparisonProtocol.h>
#import <Sparkle/SUVersionDisplayProtocol.h>
#import <Sparkle/SUErrors.h>
#import <Sparkle/SUConstants.h>
#import <Sparkle/SPUUpdatePermissionRequest.h>
#import <Sparkle/SUUpdatePermissionResponse.h>
#import <Sparkle/SPUUserDriver.h>