From d9e0265d7676fbcf04bbd2d4a3e927556ba65beb Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 11:32:00 -0700 Subject: [PATCH] Show the present update during updater progress too This includes updater permission request, downloading updates, downloading appcast, installing update, and so on. --- Sparkle/SPUScheduledUpdateDriver.m | 2 +- Sparkle/SPUStandardUserDriver.m | 22 +++++++++++++++------- Sparkle/SPUUIBasedUpdateDriver.h | 2 -- Sparkle/SPUUIBasedUpdateDriver.m | 12 ------------ Sparkle/SPUUpdater.h | 5 +++-- Sparkle/SPUUpdater.m | 12 ++++++++++-- Sparkle/SPUUserDriver.h | 15 ++++++++------- Sparkle/SPUUserInitiatedUpdateDriver.m | 9 ++++----- 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Sparkle/SPUScheduledUpdateDriver.m b/Sparkle/SPUScheduledUpdateDriver.m index 60e942e0..db9641ee 100644 --- a/Sparkle/SPUScheduledUpdateDriver.m +++ b/Sparkle/SPUScheduledUpdateDriver.m @@ -67,7 +67,7 @@ - (BOOL)showingUpdate { - return self.uiDriver.showingUpdate; + return self.showedUpdate; } - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *) error diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index db2f5de9..ec0937ad 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -93,7 +93,7 @@ // Only show the update alert if the app is active; otherwise, we'll wait until it is. if ([NSApp isActive]) { [self.activeUpdateAlert setInstallButtonFocus:userInitiated]; - [self.activeUpdateAlert.window makeKeyAndOrderFront:self]; + [self.activeUpdateAlert showWindow:nil]; } else { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } @@ -101,7 +101,7 @@ - (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification { - [self.activeUpdateAlert.window makeKeyAndOrderFront:self]; + [self.activeUpdateAlert showWindow:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp]; } @@ -188,7 +188,13 @@ - (void)showUpdateInFocus { - [self setUpFocusForActiveUpdateAlertWithUserInitiation:YES]; + if (self.activeUpdateAlert != nil) { + [self setUpFocusForActiveUpdateAlertWithUserInitiation:YES]; + } else if (self.permissionPrompt != nil) { + [self.permissionPrompt showWindow:nil]; + } else if (self.statusController != nil) { + [self.statusController showWindow:nil]; + } } #pragma mark Install & Relaunch Update @@ -197,11 +203,13 @@ { assert(NSThread.isMainThread); + [self createAndShowStatusController]; + [self.statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil]; [self.statusController setProgressValue:1.0]; // Fill the bar. [self.statusController setButtonEnabled:YES]; [self.statusController setButtonTitle:SULocalizedString(@"Install and Relaunch", nil) target:self action:@selector(installAndRestart:) isDefault:YES]; - [[self.statusController window] makeKeyAndOrderFront:self]; + [NSApp requestUserAttention:NSInformationalRequest]; self.installUpdateHandler = installUpdateHandler; @@ -311,7 +319,7 @@ #pragma mark Download & Install Updates -- (void)showStatusController +- (void)createAndShowStatusController { if (self.statusController == nil) { self.statusController = [[SUStatusController alloc] initWithHost:self.host]; @@ -325,7 +333,7 @@ self.cancellation = cancellation; - [self showStatusController]; + [self createAndShowStatusController]; [self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; [self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO]; } @@ -399,7 +407,7 @@ self.cancellation = nil; - [self showStatusController]; + [self createAndShowStatusController]; [self.statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; [self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:nil action:nil isDefault:NO]; [self.statusController setButtonEnabled:NO]; diff --git a/Sparkle/SPUUIBasedUpdateDriver.h b/Sparkle/SPUUIBasedUpdateDriver.h index da12d9b8..f49a564a 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.h +++ b/Sparkle/SPUUIBasedUpdateDriver.h @@ -41,8 +41,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)resumeUpdate:(id)resumableUpdate completion:(SPUUpdateDriverCompletion)completionBlock; -@property (nonatomic, readonly) BOOL showingUpdate; - - (void)abortUpdateWithError:(nullable NSError *)error; @end diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 5e681d5f..d361509c 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -33,7 +33,6 @@ @property (nonatomic) BOOL resumingInstallingUpdate; @property (nonatomic) BOOL resumingDownloadedUpdate; @property (nonatomic) BOOL preventsInstallerInteraction; -@property (nonatomic) BOOL showingUpdate; @end @@ -49,7 +48,6 @@ @synthesize resumingInstallingUpdate = _resumingInstallingUpdate; @synthesize resumingDownloadedUpdate = _resumingDownloadedUpdate; @synthesize preventsInstallerInteraction = _preventsInstallerInteraction; -@synthesize showingUpdate = _showingUpdate; - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver userInitiated:(BOOL)userInitiated updaterDelegate:(nullable id )updaterDelegate delegate:(id)delegate { @@ -117,8 +115,6 @@ [self.userDriver showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - self.showingUpdate = NO; - switch (choice) { case SPUSkipThisInformationalVersionChoice: [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; @@ -136,8 +132,6 @@ } else if (self.resumingDownloadedUpdate) { [self.userDriver showDownloadedUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - self.showingUpdate = NO; - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { case SPUInstallUpdateChoice: @@ -160,8 +154,6 @@ } else if (!self.resumingInstallingUpdate) { [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - self.showingUpdate = NO; - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { case SPUInstallUpdateChoice: @@ -183,16 +175,12 @@ } else { [self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInstallUpdateStatus choice) { dispatch_async(dispatch_get_main_queue(), ^{ - self.showingUpdate = NO; - [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; [self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction]; }); }]; } - self.showingUpdate = YES; - if ([self.delegate respondsToSelector:@selector(uiDriverDidShowUpdate)]) { [self.delegate uiDriverDidShowUpdate]; } diff --git a/Sparkle/SPUUpdater.h b/Sparkle/SPUUpdater.h index 20694741..9f4f567f 100644 --- a/Sparkle/SPUUpdater.h +++ b/Sparkle/SPUUpdater.h @@ -119,7 +119,7 @@ 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 is presently being shown. + 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. This property is suitable to use for menu item validation for seeing if -checkForUpdates can be invoked. @@ -131,7 +131,8 @@ SU_EXPORT @interface SPUUpdater : NSObject A property indicating whether or not an update session is in progress. An update session is in progress when the appcast is being downloaded, an update is being downloaded, - an update is being shown, or the installer is being started. An active session is when Sparkle's fired scheduler is running. + an update is being shown, update permission is being requested, or the installer is being started. + An active session is when Sparkle's fired scheduler is running. Note an update session may be inactive even though Sparkle's installer (ran as a separate process) may be running, or even though the update has been downloaded but the installation has been deferred. In both of these cases, an update session diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index a4b4fea1..933da125 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -56,6 +56,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @property (nonatomic) BOOL startedUpdater; @property (nonatomic, nullable) id resumableUpdate; @property (nonatomic) BOOL sessionInProgress; +@property (nonatomic) BOOL showingPermissionRequest; @property (nonatomic, copy) NSDate *updateLastCheckedDate; @@ -80,6 +81,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize startedUpdater = _startedUpdater; @synthesize resumableUpdate = _resumableUpdate; @synthesize sessionInProgress = _sessionInProgress; +@synthesize showingPermissionRequest = _showingPermissionRequest; @synthesize updateLastCheckedDate = _updateLastCheckedDate; @synthesize loggedATSWarning = _loggedATSWarning; @synthesize loggedDSAWarning = _loggedDSAWarning; @@ -307,11 +309,17 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification SPUUpdatePermissionRequest *updatePermissionRequest = [[SPUUpdatePermissionRequest alloc] initWithSystemProfile:profileInfo]; + self.showingPermissionRequest = YES; + self.sessionInProgress = YES; + __weak SPUUpdater *weakSelf = self; [self.userDriver showUpdatePermissionRequest:updatePermissionRequest reply:^(SUUpdatePermissionResponse *response) { dispatch_async(dispatch_get_main_queue(), ^{ SPUUpdater *strongSelf = weakSelf; if (strongSelf != nil) { + strongSelf.sessionInProgress = NO; + strongSelf.showingPermissionRequest = NO; + [strongSelf updatePermissionRequestFinishedWithResponse:response]; // Schedule checks, but make sure we ignore the delayed call from KVO [strongSelf resetUpdateCycle]; @@ -358,7 +366,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (BOOL)canCheckForUpdates { - return self.startedUpdater && (self.driver.showingUpdate || !self.sessionInProgress); + return self.startedUpdater && (self.showingPermissionRequest || self.driver.showingUpdate || !self.sessionInProgress); } - (void)scheduleNextUpdateCheckFiringImmediately:(BOOL)firingImmediately @@ -466,7 +474,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (void)checkForUpdates { - if (self.driver.showingUpdate) { + if (self.showingPermissionRequest || self.driver.showingUpdate) { if ([self.userDriver respondsToSelector:@selector(showUpdateInFocus)]) { [self.userDriver showUpdateInFocus]; } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 9e08a0a3..3932afb5 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -124,13 +124,6 @@ SU_EXPORT @protocol SPUUserDriver */ - (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply; -/*! - * Show the user currently presented update in utmost focus - * - * Sparkle uses this to make its update frontmost again - */ -- (void)showUpdateInFocus; - /*! * Show the user the release notes for the new update * @@ -263,6 +256,14 @@ SU_EXPORT @protocol SPUUserDriver */ - (void)showUpdateInstallationDidFinishWithAcknowledgement:(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 * diff --git a/Sparkle/SPUUserInitiatedUpdateDriver.m b/Sparkle/SPUUserInitiatedUpdateDriver.m index ca4364b2..c4aa768e 100644 --- a/Sparkle/SPUUserInitiatedUpdateDriver.m +++ b/Sparkle/SPUUserInitiatedUpdateDriver.m @@ -18,6 +18,7 @@ @property (nonatomic, readonly) SPUUIBasedUpdateDriver *uiDriver; @property (nonatomic, readonly) id userDriver; @property (nonatomic) BOOL showingUserInitiatedProgress; +@property (nonatomic) BOOL showingUpdate; @property (nonatomic) BOOL aborted; @end @@ -27,6 +28,7 @@ @synthesize uiDriver = _uiDriver; @synthesize userDriver = _userDriver; @synthesize showingUserInitiatedProgress = _showingUserInitiatedProgress; +@synthesize showingUpdate = _showingUpdate; @synthesize aborted = _aborted; - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate @@ -58,6 +60,8 @@ }); }; + self.showingUpdate = YES; + if ([self.userDriver respondsToSelector:@selector(showUserInitiatedUpdateCheckWithCancellation:)]) { [self.userDriver showUserInitiatedUpdateCheckWithCancellation:cancelUpdateCheck]; } else { @@ -91,11 +95,6 @@ [self.uiDriver resumeUpdate:resumableUpdate completion:completionBlock]; } -- (BOOL)showingUpdate -{ - return self.uiDriver.showingUpdate; -} - - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error { [self abortUpdateWithError:error];