mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
Allow delegate to pick no valid items (#1880)
* Allow delegate to pick no valid items We now allow returning SUAppcastItem.emptyAppcastItem in -bestValidUpdateInAppcast:forUpdater: to indicate no update should be picked. We preserve returning nil to indicate Sparkle handles the best appcast selection instead. People have expressed needs for both of these decisions (and deprecated SUUpdater relies on the nil behavior).
This commit is contained in:
1 parent
ac1bb7036c
commit
b21647bcef
4 files changed
+34
-9
No files matched your search
Vendored
+2
-1
@@ -209,7 +209,8 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck)
|
||||
|
||||
\param appcast The appcast that was downloaded from the remote server.
|
||||
\param updater The updater instance.
|
||||
\return The best valid appcast item, or nil if you don't want to be delegated this task.
|
||||
\return The best valid appcast item. Return SUAppcastItem.emptyAppcastItem if no appcast item is valid. Return nil if you don't want to be delegated this task and
|
||||
want to let Sparkle handle picking the best valid update.
|
||||
*/
|
||||
- (nullable SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SPUUpdater *)updater;
|
||||
|
||||
|
||||
Vendored
+20
-8
@@ -129,25 +129,37 @@
|
||||
// Find the best valid update in the appcast by asking the delegate
|
||||
// Don't ask the delegate if the appcast has no items though
|
||||
SUAppcastItem *regularItemFromDelegate;
|
||||
BOOL delegateOptedOutOfSelection;
|
||||
if (appcast.items.count > 0 && [self.updaterDelegate respondsToSelector:@selector((bestValidUpdateInAppcast:forUpdater:))]) {
|
||||
SUAppcastItem *candidateItem = [self.updaterDelegate bestValidUpdateInAppcast:appcast forUpdater:(id _Nonnull)self.updater];
|
||||
|
||||
assert(!candidateItem.deltaUpdate);
|
||||
if (candidateItem.deltaUpdate) {
|
||||
// Client would have to go out of their way to examine the .deltaUpdates to return one
|
||||
// This is very unlikely, and we need them to give us a regular update item back
|
||||
SULog(SULogLevelError, @"Error: -bestValidUpdateInAppcast:forUpdater: cannot return a delta update item");
|
||||
if (candidateItem == SUAppcastItem.emptyAppcastItem) {
|
||||
regularItemFromDelegate = nil;
|
||||
} else {
|
||||
regularItemFromDelegate = candidateItem;
|
||||
delegateOptedOutOfSelection = YES;
|
||||
} else if (candidateItem == nil) {
|
||||
regularItemFromDelegate = nil;
|
||||
delegateOptedOutOfSelection = NO;
|
||||
} else if (candidateItem != nil) {
|
||||
assert(!candidateItem.deltaUpdate);
|
||||
if (candidateItem.deltaUpdate) {
|
||||
// Client would have to go out of their way to examine the .deltaUpdates to return one
|
||||
// We need them to give us a regular update item back instead..
|
||||
SULog(SULogLevelError, @"Error: -bestValidUpdateInAppcast:forUpdater: cannot return a delta update item");
|
||||
regularItemFromDelegate = nil;
|
||||
} else {
|
||||
regularItemFromDelegate = candidateItem;
|
||||
}
|
||||
|
||||
delegateOptedOutOfSelection = NO;
|
||||
}
|
||||
} else {
|
||||
regularItemFromDelegate = nil;
|
||||
delegateOptedOutOfSelection = NO;
|
||||
}
|
||||
|
||||
// Take care of finding best appcast item ourselves if delegate does not
|
||||
SUAppcastItem *regularItem;
|
||||
if (regularItemFromDelegate == nil) {
|
||||
if (regularItemFromDelegate == nil && !delegateOptedOutOfSelection) {
|
||||
regularItem = [[self class] bestItemFromAppcastItems:appcast.items comparator:versionComparator];
|
||||
} else {
|
||||
regularItem = regularItemFromDelegate;
|
||||
|
||||
Vendored
+2
@@ -68,6 +68,8 @@ SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (instancetype)emptyAppcastItem;
|
||||
|
||||
// Deprecated initializers
|
||||
- (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case.");
|
||||
- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case.");
|
||||
|
||||
Vendored
+10
@@ -285,6 +285,16 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState";
|
||||
}
|
||||
}
|
||||
|
||||
+ (instancetype)emptyAppcastItem
|
||||
{
|
||||
static SUAppcastItem *emptyAppcastItem;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
emptyAppcastItem = [[SUAppcastItem alloc] init];
|
||||
});
|
||||
return emptyAppcastItem;
|
||||
}
|
||||
|
||||
// Initializer used for making delta items
|
||||
- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL state:(SPUAppcastItemState * _Nullable)state
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user