From 796967cf247a2e76cf645973984ca336679a895a Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 25 Dec 2016 18:41:38 -0500 Subject: [PATCH] Allow delegate methods that return an object to return nil Returning nil from these delegate methods is equivalent to not implementing the delegate method. The caller should be able to make this kind of decision when implementing an optional delegate method. --- Sparkle/SUBasicUpdateDriver.m | 13 ++++++++++--- Sparkle/SUUpdater.m | 8 ++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 4d0487b4..b4f65b22 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -162,11 +162,15 @@ if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? { item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:(id)self.updater]; + } + + if (item != nil) // Does the delegate want to handle it? + { if ([item isDeltaUpdate]) { self.nonDeltaUpdateItem = [[self.updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:(id)self.updater]; } - } - else // If not, we'll take care of it ourselves. + } + else // If not, we'll take care of it ourselves. { // Find the best supported update SUAppcastItem *deltaUpdateItem = nil; @@ -525,7 +529,10 @@ NSString *pathToRelaunch = [self.host bundlePath]; if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { - pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; + NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; + if (delegateRelaunchPath != nil) { + pathToRelaunch = delegateRelaunchPath; + } } [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath], diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index c13974a5..522dd24c 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -435,8 +435,12 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). NSString *appcastString = [self.host objectForKey:SUFeedURLKey]; - if ([self.delegate respondsToSelector:@selector(feedURLStringForUpdater:)]) - appcastString = [self.delegate feedURLStringForUpdater:self]; + if ([self.delegate respondsToSelector:@selector(feedURLStringForUpdater:)]) { + NSString *delegateAppcastString = [self.delegate feedURLStringForUpdater:self]; + if (delegateAppcastString != nil) { + appcastString = delegateAppcastString; + } + } if (!appcastString) // Can't find an appcast string! [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the %@ key in either the Info.plist or the user defaults!", SUFeedURLKey]; NSCharacterSet *quoteSet = [NSCharacterSet characterSetWithCharactersInString:@"\"\'"]; // Some feed publishers add quotes; strip 'em.