From b1fa9efa24ca53cae2e495251b38ac799335227b Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 21 Aug 2016 15:58:33 -0400 Subject: [PATCH] Distinguish initiated vs scheduled updates for allowing interaction --- Sparkle/SPUUpdater.m | 27 +++++++++++++++++++-------- Sparkle/SPUUpdaterDelegate.h | 29 ++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index ecac1c73..ae5e8a50 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -434,7 +434,14 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification updaterDelegate:strongSelf.delegate]; } - [strongSelf checkForUpdatesWithDriver:updateDriver installerInProgress:installerIsRunning]; + BOOL preventsInstallerInteraction; + if ([strongSelf.delegate respondsToSelector:@selector(updaterShouldAllowInstallerInteractionForScheduledChecks:)]) { + preventsInstallerInteraction = ![strongSelf.delegate updaterShouldAllowInstallerInteractionForScheduledChecks:strongSelf]; + } else { + preventsInstallerInteraction = NO; + } + + [strongSelf checkForUpdatesWithDriver:updateDriver installerInProgress:installerIsRunning preventsInstallerInteraction:preventsInstallerInteraction]; }); }]; } @@ -461,7 +468,14 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification dispatch_async(dispatch_get_main_queue(), ^{ SPUUpdater *strongSelf = weakSelf; if (strongSelf != nil) { - [strongSelf checkForUpdatesWithDriver:theUpdateDriver installerInProgress:installerInProgress]; + BOOL preventsInstallerInteraction; + if ([strongSelf.delegate respondsToSelector:@selector(updaterShouldAllowInstallerInteractionForInitiatedChecks:)]) { + preventsInstallerInteraction = ![strongSelf.delegate updaterShouldAllowInstallerInteractionForInitiatedChecks:strongSelf]; + } else { + preventsInstallerInteraction = NO; + } + + [strongSelf checkForUpdatesWithDriver:theUpdateDriver installerInProgress:installerInProgress preventsInstallerInteraction:preventsInstallerInteraction]; } }); }]; @@ -483,13 +497,13 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification dispatch_async(dispatch_get_main_queue(), ^{ SPUUpdater *strongSelf = weakSelf; if (strongSelf != nil) { - [strongSelf checkForUpdatesWithDriver:[[SUProbingUpdateDriver alloc] initWithHost:strongSelf.host updater:strongSelf updaterDelegate:strongSelf.delegate] installerInProgress:installerInProgress]; + [strongSelf checkForUpdatesWithDriver:[[SUProbingUpdateDriver alloc] initWithHost:strongSelf.host updater:strongSelf updaterDelegate:strongSelf.delegate] installerInProgress:installerInProgress preventsInstallerInteraction:NO]; } }); }]; } -- (void)checkForUpdatesWithDriver:(id )d installerInProgress:(BOOL)installerInProgress +- (void)checkForUpdatesWithDriver:(id )d installerInProgress:(BOOL)installerInProgress preventsInstallerInteraction:(BOOL)preventsInstallerInteraction { if (self.driver != nil) { return; @@ -551,10 +565,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } else if (self.resumableUpdate != nil) { [self.driver resumeDownloadedUpdate:(SUDownloadedUpdate * _Nonnull)self.resumableUpdate completion:completionBlock]; } else { - BOOL allowsInstallerInteraction = - (![self.delegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)] || [self.delegate updaterShouldAllowInstallerInteraction:self]); - - [self.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[self userAgentString] httpHeaders:[self httpHeaders] preventingInstallerInteraction:!allowsInstallerInteraction completion:completionBlock]; + [self.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[self userAgentString] httpHeaders:[self httpHeaders] preventingInstallerInteraction:preventsInstallerInteraction completion:completionBlock]; } } else { // I think this is really unlikely to occur but better be safe diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index 0ff8775d..9915bbc1 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -232,19 +232,42 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; - (nullable id)versionComparatorForUpdater:(SPUUpdater *)updater; /*! - Returns whether or not the updater should allow interaction with its installer + Returns whether or not the updater should allow interaction from the installer for scheduled checks Use this to override the default behavior which is to allow interaction with the installer. + This method applies to updates started in the background + If interaction is allowed, then an authorization prompt may show up to the user if they do not curently have sufficient privileges to perform the installation of the new update. On the other hand, if interaction is not allowed, then an installation may fail if the user does not - have sufficient privileges to perform the installation. + have sufficient privileges to perform the installation. In this case, the feed and update may not even be downloaded. + + Note this has no effect if the update has already been downloaded in the background silently and ready to be resumed. \param updater The updater instance. */ -- (BOOL)updaterShouldAllowInstallerInteraction:(SPUUpdater *)updater; +- (BOOL)updaterShouldAllowInstallerInteractionForScheduledChecks:(SPUUpdater *)updater; + +/*! + Returns whether or not the updater should allow interaction from the installer for user initiated checks + + Use this to override the default behavior which is to allow interaction with the installer. + + This method applies to updates started from -[SPUUpdater checkForUpdates] + + If interaction is allowed, then an authorization prompt may show up to the user if they do + not curently have sufficient privileges to perform the installation of the new update. + + On the other hand, if interaction is not allowed, then an installation may fail if the user does not + have sufficient privileges to perform the installation. In this case, the feed and update may not even be downloaded. + + Note this has no effect if the update has already been downloaded in the background silently and ready to be resumed. + + \param updater The updater instance. + */ +- (BOOL)updaterShouldAllowInstallerInteractionForInitiatedChecks:(SPUUpdater *)updater; /*! Returns the decryption password (if any) which is used to extract the update archive DMG.