From ca36d9963e3cc3eef0cb3c92c810b1c1da112265 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 5 Aug 2016 19:39:12 -0400 Subject: [PATCH] Remove -updaterIsRequestingQuit: delegate callback and use user driver instead This way we remove delegate responsibility duplication and this should make backwards compatibility easier --- Sparkle/SPUUpdater.m | 1 + Sparkle/SUAutomaticUpdateDriver.h | 4 ++-- Sparkle/SUAutomaticUpdateDriver.m | 15 ++++++++------- Sparkle/SUUpdaterDelegate.h | 16 ++-------------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 0e08b9b6..edf8ee3b 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -387,6 +387,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification initWithHost:strongSelf.host sparkleBundle:strongSelf.sparkleBundle updater:strongSelf.delegator + userDriver:strongSelf.userDriver updaterDelegate:strongSelf.delegate]; } else { updateDriver = diff --git a/Sparkle/SUAutomaticUpdateDriver.h b/Sparkle/SUAutomaticUpdateDriver.h index 5ae8ddd6..68978e1f 100644 --- a/Sparkle/SUAutomaticUpdateDriver.h +++ b/Sparkle/SUAutomaticUpdateDriver.h @@ -12,11 +12,11 @@ NS_ASSUME_NONNULL_BEGIN @class SUHost; -@protocol SUUpdaterDelegate; +@protocol SUUpdaterDelegate, SPUUserDriver; @interface SUAutomaticUpdateDriver : NSObject -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id )updaterDelegate; +- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate; @end diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 75645bdc..b90fc21b 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -13,6 +13,7 @@ #import "SUCoreBasedUpdateDriver.h" #import "SULog.h" #import "SUAppcastItem.h" +#import "SPUUserDriver.h" #import "SUErrors.h" #ifdef _APPKITDEFINES_H @@ -22,6 +23,7 @@ @interface SUAutomaticUpdateDriver () @property (nonatomic, readonly, weak) id updater; +@property (nonatomic, readonly, weak) id userDriver; @property (nonatomic, readonly, weak, nullable) id updaterDelegate; @property (nonatomic, readonly) SUCoreBasedUpdateDriver *coreDriver; @property (nonatomic) SUAppcastItem* updateItem; @@ -32,16 +34,19 @@ @implementation SUAutomaticUpdateDriver @synthesize updater = _updater; +@synthesize userDriver = _userDriver; @synthesize updaterDelegate = _updaterDelegate; @synthesize coreDriver = _coreDriver; @synthesize updateItem = _updateItem; @synthesize willInstallSilently = _willInstallSilently; -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id )updaterDelegate +- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate { self = [super init]; if (self != nil) { _updater = updater; + // The user driver is only used for a termination callback + _userDriver = userDriver; _updaterDelegate = updaterDelegate; _coreDriver = [[SUCoreBasedUpdateDriver alloc] initWithHost:host sparkleBundle:sparkleBundle updater:updater updaterDelegate:updaterDelegate delegate:self]; } @@ -83,8 +88,7 @@ id updaterDelegate = self.updaterDelegate; if (self.willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) { __weak SUAutomaticUpdateDriver *weakSelf = self; - installationHandledByDelegate = - [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{ + installationHandledByDelegate = [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{ [weakSelf.coreDriver finishInstallationWithResponse:SUInstallAndRelaunchUpdateNow displayingUserInterface:NO]; }]; } @@ -101,10 +105,7 @@ // otherwise the update driver will abort the update before then - (void)installerIsRequestingAppTermination { - id updaterDelegate = self.updaterDelegate; - if ([updaterDelegate respondsToSelector:@selector(updaterIsRequestingQuit:)]) { - [updaterDelegate updaterIsRequestingQuit:self.updater]; - } + [self.userDriver terminateApplication]; } - (void)basicDriverIsRequestingAbortUpdateWithError:(NSError *)error diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index f2415988..bad493f9 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -291,7 +291,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param item The appcast item corresponding to the update that is proposed to be installed. \param invocation Can be used to trigger an immediate silent install and relaunch. - \deprecated See -updater:willInstallUpdateOnQuit:immediateInstallationBlock: and -updaterIsRequestingQuit: instead. This method is no longer invoked. + \deprecated See -updater:willInstallUpdateOnQuit:immediateInstallationBlock: instead. This method is no longer invoked. */ - (void)updater:(id)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation __deprecated; @@ -300,8 +300,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param updater The updater instance. \param item The appcast item corresponding to the update that is proposed to be installed. - \param immediateInstallHandler The install handler to immediately install the update. - If you plan to invoke this, you must return YES from this method and also implement -updaterIsRequestingQuit: + \param immediateInstallHandler The install handler to immediately install the update. No UI interaction will be shown and the application will be relaunched after installation. \return Return YES if the delegate will handle installing the update or NO if the updater should be given responsibility. If the updater is given responsibility, it can later remind the user an update is available if they have not terminated the application for a long time. @@ -310,17 +309,6 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (BOOL)updater:(id)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)(void))immediateInstallHandler; -/*! - Called when the updater requests to quit the application after the delegate invoked its installation block from -updater:willInstallUpdateOnQuit:immediateInstallationBlock: - - \param updater the updater instance. - - The delegate should terminate the application so the installer can immediately install the update. - After the application is terminated, the installer will install the update and the application will be relaunched. - The installer will not show any UI interaction. - */ -- (void)updaterIsRequestingQuit:(id)updater; - /*! Calls after an update that was scheduled to be silently installed on quit has been canceled.