From f3cd2b9ff9794fa43cb214b8e0151f4e08320191 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 12 Apr 2025 13:25:23 -0700 Subject: [PATCH] Make -[SPUUserDriver showUpdateInFocus] optional (#2717) When this method is not implemented, the updater assumes already presented updates cannot be brought in utmost focus. --- Sparkle/SPUUpdater.h | 8 ++++++-- Sparkle/SPUUpdater.m | 21 +++++++++++++++++---- Sparkle/SPUUserDriver.h | 20 +++++++++++--------- sparkle-cli/SPUCommandLineUserDriver.m | 4 ---- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Sparkle/SPUUpdater.h b/Sparkle/SPUUpdater.h index 9f035d33..0bf49a41 100644 --- a/Sparkle/SPUUpdater.h +++ b/Sparkle/SPUUpdater.h @@ -96,7 +96,8 @@ SU_EXPORT @interface SPUUpdater : NSObject If an update hasn't started, the user may be shown that a new check for updates is occurring. If an update has already been downloaded or begun installing from a previous session, the user may be presented to install that update. - If the user is already being presented with an update, that update will be shown to the user in active focus. + If the user is already being presented with an update or update permission prompt, that notice may be shown to the user in active focus + (as long as the user driver is the standard `SPUStandardUserDriver` or if it implements `-[SPUUserDriver showUpdateInFocus]`). This will find updates that the user has previously opted into skipping. @@ -150,7 +151,10 @@ SU_EXPORT @interface SPUUpdater : NSObject /** A property indicating whether or not updates can be checked by the user. - An update check can be made by the user when an update session isn't in progress, or when an update or its progress is being shown to the user. + An update check can be made by the user when an update session isn't in progress. + An update check can also be made when an update or its progress is being shown to the user + (as long as the user driver is the standard `SPUStandardUserDriver` or if it implements `-[SPUUserDriver showUpdateInFocus]`). + A user cannot check for updates when data (such as the feed or an update) is still being downloaded automatically in the background. This property is suitable to use for menu item validation for seeing if `-checkForUpdates` can be invoked. diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 305aa8f7..c549734e 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -421,7 +421,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification _showingPermissionRequest = YES; [self setSessionInProgress:YES]; - [self setCanCheckForUpdates:YES]; + + BOOL canShowUserDriverInFocusDuringPermissionPrompt = [_userDriver respondsToSelector:@selector(showUpdateInFocus)]; + [self setCanCheckForUpdates:canShowUserDriverInFocusDuringPermissionPrompt]; __weak __typeof__(self) weakSelf = self; [_userDriver showUpdatePermissionRequest:updatePermissionRequest reply:^(SUUpdatePermissionResponse *response) { @@ -432,6 +434,11 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification strongSelf->_showingPermissionRequest = NO; [strongSelf updatePermissionRequestFinishedWithResponse:response]; + + if (!canShowUserDriverInFocusDuringPermissionPrompt) { + [strongSelf setCanCheckForUpdates:YES]; + } + // Schedule checks, but make sure we ignore the delayed call from KVO [strongSelf resetUpdateCycle]; } @@ -647,6 +654,10 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if (_showingPermissionRequest || _driver.showingUpdate) { if ([_userDriver respondsToSelector:@selector(showUpdateInFocus)]) { [_userDriver showUpdateInFocus]; + } else { + NSString *noticeType = _showingPermissionRequest ? @"permission request" : @"update"; + + SULog(SULogLevelError, @"Error: checkForUpdates called but %@ is being shown and %@ does not implement -[SPUUserDriver showUpdateInFocus]", noticeType, _userDriver); } return; } @@ -821,9 +832,11 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } }]; - [_driver setUpdateShownHandler:^{ - weakSelf.canCheckForUpdates = YES; - }]; + if ([_userDriver respondsToSelector:@selector(showUpdateInFocus)]) { + [_driver setUpdateShownHandler:^{ + weakSelf.canCheckForUpdates = YES; + }]; + } [_driver setUpdateWillInstallHandler:^{ [weakSelf updateLastUpdateCheckDate]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 3d90e44a..d0cc98e6 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -256,14 +256,6 @@ SU_EXPORT @protocol SPUUserDriver */ - (void)showUpdateInstalledAndRelaunched:(BOOL)relaunched acknowledgement:(void (^)(void))acknowledgement; -/** - * Show the user the current presented update or its progress in utmost focus - * - * The user wishes to check for updates while the user is being shown update progress. - * Bring whatever is on screen to frontmost focus (permission request, update information, downloading or extraction status, choice to install update, etc). - */ -- (void)showUpdateInFocus; - /** * Dismiss the current update installation * @@ -273,12 +265,22 @@ SU_EXPORT @protocol SPUUserDriver */ - (void)dismissUpdateInstallation; +@optional + +/** + * Show the user the current presented update or its progress in utmost focus + * + * The user wishes to check for updates while the user is being shown update progress. + * Bring whatever is on screen to frontmost focus (permission request, update information, downloading or extraction status, choice to install update, etc). + * Implementing this method is optional. + */ +- (void)showUpdateInFocus; + /* * Below are deprecated methods that have been replaced by better alternatives. * The deprecated methods will be used if the alternatives have not been implemented yet. * In the future support for using these deprecated methods may be removed however. */ -@optional // Clients should move to non-deprecated methods // Deprecated methods are only (temporarily) kept around for compatibility reasons diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 17ac255e..e1f22054 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -121,10 +121,6 @@ } } -- (void)showUpdateInFocus -{ -} - - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { if (_verbose) {