From 2f783e01f0a847f0bdc1f0a3ac994caa4ed2336d Mon Sep 17 00:00:00 2001 From: Zorg Date: Thu, 15 Apr 2021 22:56:41 -0700 Subject: [PATCH 1/5] Show the present update in focus when checkForUpdates is invoked When the update is shown to the user, the menu item for checking for updates is no longer disabled. Instead it is enabled, and when invoked, will bring the update to utmost focus back to the user again. This is consistent with other options (eg Preferences...) that bring up windows. Improved user experience here is that updates are now less "lost". We (re)define properties on SPUUpdater: canCheckForUpdates - to mean that the user can check for updates (start a new update check or show the already present update frontmost) sessionInProgress - to mean if Sparkle's internal driver / scheduler is running (i.e, downloading appcast or update, showing update, starting installation). --- Sparkle/SPUAutomaticUpdateDriver.m | 5 ++ Sparkle/SPUProbingUpdateDriver.m | 5 ++ Sparkle/SPUScheduledUpdateDriver.m | 8 ++++ Sparkle/SPUStandardUserDriver.m | 16 +++---- Sparkle/SPUUIBasedUpdateDriver.h | 4 +- Sparkle/SPUUIBasedUpdateDriver.m | 12 +++-- Sparkle/SPUUpdateDriver.h | 2 + Sparkle/SPUUpdater.h | 30 ++++++++++-- Sparkle/SPUUpdater.m | 51 +++++++++++---------- Sparkle/SPUUserDriver.h | 14 +++--- Sparkle/SPUUserInitiatedUpdateDriver.m | 12 +++++ Sparkle/SUUpdateAlert.h | 3 +- Sparkle/SUUpdateAlert.m | 9 +++- Sparkle/SUUpdater.m | 2 +- TestApplication/SUPopUpTitlebarUserDriver.m | 11 ++--- sparkle-cli/SPUCommandLineUserDriver.m | 8 ++-- 16 files changed, 129 insertions(+), 63 deletions(-) diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 0515a9d7..91f54179 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -89,6 +89,11 @@ } } +- (BOOL)showingUpdate +{ + return NO; +} + - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently { self.willInstallSilently = willInstallSilently; diff --git a/Sparkle/SPUProbingUpdateDriver.m b/Sparkle/SPUProbingUpdateDriver.m index 965f4b71..6cd8fc3b 100644 --- a/Sparkle/SPUProbingUpdateDriver.m +++ b/Sparkle/SPUProbingUpdateDriver.m @@ -60,6 +60,11 @@ [self abortUpdate]; } +- (BOOL)showingUpdate +{ + return NO; +} + - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error { [self abortUpdateWithError:error]; diff --git a/Sparkle/SPUScheduledUpdateDriver.m b/Sparkle/SPUScheduledUpdateDriver.m index f648b607..8029c138 100644 --- a/Sparkle/SPUScheduledUpdateDriver.m +++ b/Sparkle/SPUScheduledUpdateDriver.m @@ -19,6 +19,7 @@ @property (nonatomic, readonly) SPUUIBasedUpdateDriver *uiDriver; @property (nonatomic) BOOL showedUpdate; +@property (nonatomic) BOOL showingUpdate; @end @@ -26,6 +27,7 @@ @synthesize uiDriver = _uiDriver; @synthesize showedUpdate = _showedUpdate; +@synthesize showingUpdate = _showingUpdate; - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate { @@ -63,6 +65,12 @@ - (void)uiDriverDidShowUpdate { self.showedUpdate = YES; + self.showingUpdate = YES; +} + +- (void)uiDriverFinishedShowingUpdate +{ + self.showingUpdate = NO; } - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *) error diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index ec544826..db2f5de9 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -57,13 +57,6 @@ return self; } -#pragma mark Is Update Busy? - -- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates -{ - assert(NSThread.isMainThread); -} - #pragma mark Update Permission - (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)request reply:(void (^)(SUUpdatePermissionResponse *))reply @@ -99,9 +92,7 @@ // Only show the update alert if the app is active; otherwise, we'll wait until it is. if ([NSApp isActive]) { - if (!userInitiated) { - [self.activeUpdateAlert disableKeyboardShortcutForInstallButton]; - } + [self.activeUpdateAlert setInstallButtonFocus:userInitiated]; [self.activeUpdateAlert.window makeKeyAndOrderFront:self]; } else { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; @@ -195,6 +186,11 @@ [self.activeUpdateAlert showReleaseNotesFailedToDownload]; } +- (void)showUpdateInFocus +{ + [self setUpFocusForActiveUpdateAlertWithUserInitiation:YES]; +} + #pragma mark Install & Relaunch Update - (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler diff --git a/Sparkle/SPUUIBasedUpdateDriver.h b/Sparkle/SPUUIBasedUpdateDriver.h index 188822e7..bcba39d6 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.h +++ b/Sparkle/SPUUIBasedUpdateDriver.h @@ -17,10 +17,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; - (void)uiDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; +- (void)uiDriverDidShowUpdate; +- (void)uiDriverFinishedShowingUpdate; + @optional - (void)basicDriverDidFinishLoadingAppcast; -- (void)uiDriverDidShowUpdate; @end diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index d361509c..4ab14602 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -115,6 +115,8 @@ [self.userDriver showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate uiDriverFinishedShowingUpdate]; + switch (choice) { case SPUSkipThisInformationalVersionChoice: [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; @@ -132,6 +134,8 @@ } else if (self.resumingDownloadedUpdate) { [self.userDriver showDownloadedUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate uiDriverFinishedShowingUpdate]; + [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { case SPUInstallUpdateChoice: @@ -154,6 +158,8 @@ } else if (!self.resumingInstallingUpdate) { [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate uiDriverFinishedShowingUpdate]; + [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { case SPUInstallUpdateChoice: @@ -175,15 +181,15 @@ } else { [self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInstallUpdateStatus choice) { dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate uiDriverFinishedShowingUpdate]; + [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; [self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction]; }); }]; } - if ([self.delegate respondsToSelector:@selector(uiDriverDidShowUpdate)]) { - [self.delegate uiDriverDidShowUpdate]; - } + [self.delegate uiDriverDidShowUpdate]; if (updateItem.releaseNotesURL != nil && (![updaterDelegate respondsToSelector:@selector(updaterShouldDownloadReleaseNotes:)] || [updaterDelegate updaterShouldDownloadReleaseNotes:self.updater])) { NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; diff --git a/Sparkle/SPUUpdateDriver.h b/Sparkle/SPUUpdateDriver.h index b991ba99..6a451492 100644 --- a/Sparkle/SPUUpdateDriver.h +++ b/Sparkle/SPUUpdateDriver.h @@ -25,6 +25,8 @@ typedef void (^SPUUpdateDriverCompletion)(BOOL shouldShowUpdateImmediately, id)resumableUpdate completion:(SPUUpdateDriverCompletion)completionBlock; +@property (nonatomic, readonly) BOOL showingUpdate; + // A likely implementation of -abortUpdate is invoking -abortUpdateWithError: by passing nil - (void)abortUpdate; diff --git a/Sparkle/SPUUpdater.h b/Sparkle/SPUUpdater.h index ff896eb3..20694741 100644 --- a/Sparkle/SPUUpdater.h +++ b/Sparkle/SPUUpdater.h @@ -79,9 +79,15 @@ SU_EXPORT @interface SPUUpdater : NSObject Checks for updates, and displays progress while doing so. This is meant for users initiating an update check. + + If an update session isn't in progress, the user will be shown that a check for new updates is occurring. + If a new update is already being shown, that update will be shown to the user in active focus. + This may find a resumable update that has already been downloaded or has begun installing, or this may find a new update that can start to be downloaded if the user requests it. This will find updates that the user has opted into skipping. + + See canCheckForUpdates property which can determine if this method may be invoked. */ - (void)checkForUpdates; @@ -111,16 +117,30 @@ SU_EXPORT @interface SPUUpdater : NSObject - (void)checkForUpdateInformation; /*! - A property indicating whether or not updates can be checked. + A property indicating whether or not updates can be checked by the user. - This property is useful for determining whether update checks can be made programatically or by the user. - An update check cannot be made when an on-going update check is in progress. + 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. - Note this property does not reflect whether or not an update itself is in progress. For example, - an update check can be done to check if there's an already started update that can be resumed. + This property is suitable to use for menu item validation for seeing if -checkForUpdates can be invoked. + + Note this property does not reflect whether or not an update session is in progress. Please see sessionInProgress property instead. */ @property (nonatomic, readonly) BOOL canCheckForUpdates; +/*! + 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. + + 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 + may be activated and resumed at a later point (automatically or manually). + + See also canCheckForUpdates property which is more suited for menu item validation. + */ +@property (nonatomic, readonly) BOOL sessionInProgress; + /*! A property indicating whether or not to check for updates automatically. diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 2971837e..a4b4fea1 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -55,7 +55,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @property (nonatomic, readonly) SPUUpdaterTimer *updaterTimer; @property (nonatomic) BOOL startedUpdater; @property (nonatomic, nullable) id resumableUpdate; -@property (nonatomic) BOOL canCheckForUpdates; +@property (nonatomic) BOOL sessionInProgress; @property (nonatomic, copy) NSDate *updateLastCheckedDate; @@ -79,7 +79,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize sparkleBundle = _sparkleBundle; @synthesize startedUpdater = _startedUpdater; @synthesize resumableUpdate = _resumableUpdate; -@synthesize canCheckForUpdates = _canCheckForUpdates; +@synthesize sessionInProgress = _sessionInProgress; @synthesize updateLastCheckedDate = _updateLastCheckedDate; @synthesize loggedATSWarning = _loggedATSWarning; @synthesize loggedDSAWarning = _loggedDSAWarning; @@ -147,12 +147,11 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } self.startedUpdater = YES; - [self setCanCheckForUpdates:YES]; // Start updater on next update cycle so we make sure the application invoking the updater is ready // This also gives the developer a cycle to check for updates before Sparkle's update cycle scheduler kicks in dispatch_async(dispatch_get_main_queue(), ^{ - if ([self canCheckForUpdates]) { + if (!self.sessionInProgress) { [self startUpdateCycle]; } }); @@ -357,11 +356,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification [self scheduleNextUpdateCheckFiringImmediately:NO]; } -- (void)setCanCheckForUpdates:(BOOL)canCheckForUpdates +- (BOOL)canCheckForUpdates { - _canCheckForUpdates = canCheckForUpdates; - - [self.userDriver showCanCheckForUpdates:canCheckForUpdates]; + return self.startedUpdater && (self.driver.showingUpdate || !self.sessionInProgress); } - (void)scheduleNextUpdateCheckFiringImmediately:(BOOL)firingImmediately @@ -416,11 +413,11 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification return; } - if (!self.canCheckForUpdates) { - SULog(SULogLevelError, @"Error: -checkForUpdatesInBackground called but .canCheckForUpdates == NO"); + if (self.sessionInProgress) { + SULog(SULogLevelError, @"Error: -checkForUpdatesInBackground called but .sessionInProgress == YES"); } - [self setCanCheckForUpdates:NO]; + self.sessionInProgress = YES; // We don't want the probe check to act on the driver if the updater is going near death __weak SPUUpdater *weakSelf = self; @@ -469,26 +466,34 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (void)checkForUpdates { - __weak SPUUpdater *weakSelf = self; + if (self.driver.showingUpdate) { + if ([self.userDriver respondsToSelector:@selector(showUpdateInFocus)]) { + [self.userDriver showUpdateInFocus]; + } + return; + } + if (!self.startedUpdater) { SULog(SULogLevelError, @"Error: checkForUpdates - updater hasn't been started yet. Please call -startUpdater: first"); return; } - if (!self.canCheckForUpdates) { - SULog(SULogLevelError, @"Error: -checkForUpdates called but .canCheckForUpdates == NO"); + if (self.sessionInProgress) { + SULog(SULogLevelError, @"Error: -checkForUpdates called but .sessionInProgress == YES"); } if (self.driver != nil) { return; } - [self setCanCheckForUpdates:NO]; + self.sessionInProgress = YES; id theUpdateDriver = [[SPUUserInitiatedUpdateDriver alloc] initWithHost:self.host applicationBundle:self.applicationBundle sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver updaterDelegate:self.delegate]; NSString *bundleIdentifier = self.host.bundle.bundleIdentifier; assert(bundleIdentifier != nil); + + __weak SPUUpdater *weakSelf = self; [SPUProbeInstallStatus probeInstallerInProgressForHostBundleIdentifier:bundleIdentifier completion:^(BOOL installerInProgress) { dispatch_async(dispatch_get_main_queue(), ^{ SPUUpdater *strongSelf = weakSelf; @@ -514,11 +519,11 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification return; } - if (!self.canCheckForUpdates) { - SULog(SULogLevelError, @"Error: -checkForUpdateInformation called but .canCheckForUpdates == NO"); + if (self.sessionInProgress) { + SULog(SULogLevelError, @"Error: -checkForUpdateInformation called but .sessionInProgress == YES"); } - [self setCanCheckForUpdates:NO]; + self.sessionInProgress = YES; NSString *bundleIdentifier = self.host.bundle.bundleIdentifier; assert(bundleIdentifier != nil); @@ -544,7 +549,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if( [self.delegate respondsToSelector: @selector((updaterMayCheckForUpdates:))] && ![self.delegate updaterMayCheckForUpdates:self] ) { - [self setCanCheckForUpdates:YES]; + self.sessionInProgress = NO; [self scheduleNextUpdateCheck]; return; } @@ -560,7 +565,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification SULog(SULogLevelError, @"Sparkle configuration error (%ld): %@", (long)configurationError.code, configurationError.localizedDescription); SULog(SULogLevelDefault, @"Disabling scheduled updates.."); - [self setCanCheckForUpdates:YES]; + self.sessionInProgress = NO; [self.driver abortUpdateWithError:configurationError]; self.driver = nil; @@ -575,7 +580,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if (strongSelf != nil) { strongSelf.resumableUpdate = resumableUpdate; strongSelf.driver = nil; - [strongSelf setCanCheckForUpdates:YES]; + self.sessionInProgress = NO; [strongSelf updateLastUpdateCheckDate]; [strongSelf scheduleNextUpdateCheckFiringImmediately:shouldShowUpdateImmediately]; } @@ -591,7 +596,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } else { // I think this is really unlikely to occur but better be safe [self.driver abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInvalidFeedURLError userInfo:@{ NSLocalizedDescriptionKey: @"Sparkle cannot form a valid feed URL." }]]; - [self setCanCheckForUpdates:YES]; + self.sessionInProgress = NO; self.driver = nil; } } @@ -608,7 +613,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification return; // not even ready yet } - if (self.canCheckForUpdates) { + if (!self.sessionInProgress) { [self cancelNextUpdateCycle]; [self scheduleNextUpdateCheck]; } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 00391c4a..9e08a0a3 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -32,13 +32,6 @@ NS_ASSUME_NONNULL_BEGIN */ SU_EXPORT @protocol SPUUserDriver -/*! - * Show that an update can be checked by the user or not - * - * A client may choose to update the interface letting the user know if they can check for updates. - */ -- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates; - /*! * Show an updater permission request to the user * @@ -131,6 +124,13 @@ 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 * diff --git a/Sparkle/SPUUserInitiatedUpdateDriver.m b/Sparkle/SPUUserInitiatedUpdateDriver.m index 5bcdaa28..499f2da3 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 @@ -26,6 +27,7 @@ @synthesize uiDriver = _uiDriver; @synthesize userDriver = _userDriver; +@synthesize showingUpdate = _showingUpdate; @synthesize showingUserInitiatedProgress = _showingUserInitiatedProgress; @synthesize aborted = _aborted; @@ -91,6 +93,16 @@ [self.uiDriver resumeUpdate:resumableUpdate completion:completionBlock]; } +- (void)uiDriverDidShowUpdate +{ + self.showingUpdate = YES; +} + +- (void)uiDriverFinishedShowingUpdate +{ + self.showingUpdate = NO; +} + - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error { [self abortUpdateWithError:error]; diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 09f9cbf7..e737881c 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -32,7 +32,8 @@ - (IBAction)installUpdate:sender; - (IBAction)skipThisVersion:sender; - (IBAction)remindMeLater:sender; -- (void)disableKeyboardShortcutForInstallButton; + +- (void)setInstallButtonFocus:(BOOL)focus; @end diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 76fa5705..2064828c 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -133,8 +133,13 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; } -- (void)disableKeyboardShortcutForInstallButton { - self.installButton.keyEquivalent = @""; +- (void)setInstallButtonFocus:(BOOL)focus +{ + if (focus) { + self.installButton.keyEquivalent = @"\r"; + } else { + self.installButton.keyEquivalent = @""; + } } - (void)endWithSelection:(SPUUpdateAlertChoice)choice diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 0065dde1..cb8c7efe 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -212,7 +212,7 @@ static NSMutableDictionary *sharedUpdaters = nil; { // This is not quite true -- we may be able to check / resume an update if one is in progress // But this is a close enough approximation for 1.x updater API - return !self.updater.canCheckForUpdates; + return self.updater.sessionInProgress; } // Not implemented properly at the moment - leaning towards it not be in the future diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 46d58477..db6108eb 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -96,12 +96,6 @@ self.updateButtonAction = nil; } -#pragma mark Can Check for Updates? - -- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates -{ -} - #pragma mark Update Permission - (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)__unused request reply:(void (^)(SUUpdatePermissionResponse *))reply @@ -182,6 +176,11 @@ { } +- (void)showUpdateInFocus +{ + [self.window makeKeyAndOrderFront:nil]; +} + #pragma mark Install & Relaunch Update - (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 2ca61bdf..e8ba6e03 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -41,10 +41,6 @@ return self; } -- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates -{ -} - - (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)__unused request reply:(void (^)(SUUpdatePermissionResponse *))reply { if (self.updatePermissionResponse == nil) { @@ -138,6 +134,10 @@ reply(SPUDismissInformationalNoticeChoice); } +- (void)showUpdateInFocus +{ +} + - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { if (self.verbose) { From 6b3d2af21a4f48151e96885b01eab912a1496d8a Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 00:01:37 -0700 Subject: [PATCH 2/5] Simplify UI driver storing showingUpdate state --- Sparkle/SPUScheduledUpdateDriver.m | 7 ++----- Sparkle/SPUUIBasedUpdateDriver.h | 6 +++--- Sparkle/SPUUIBasedUpdateDriver.m | 16 +++++++++++----- Sparkle/SPUUserInitiatedUpdateDriver.m | 11 ++--------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Sparkle/SPUScheduledUpdateDriver.m b/Sparkle/SPUScheduledUpdateDriver.m index 8029c138..60e942e0 100644 --- a/Sparkle/SPUScheduledUpdateDriver.m +++ b/Sparkle/SPUScheduledUpdateDriver.m @@ -19,7 +19,6 @@ @property (nonatomic, readonly) SPUUIBasedUpdateDriver *uiDriver; @property (nonatomic) BOOL showedUpdate; -@property (nonatomic) BOOL showingUpdate; @end @@ -27,7 +26,6 @@ @synthesize uiDriver = _uiDriver; @synthesize showedUpdate = _showedUpdate; -@synthesize showingUpdate = _showingUpdate; - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate { @@ -65,12 +63,11 @@ - (void)uiDriverDidShowUpdate { self.showedUpdate = YES; - self.showingUpdate = YES; } -- (void)uiDriverFinishedShowingUpdate +- (BOOL)showingUpdate { - self.showingUpdate = NO; + return self.uiDriver.showingUpdate; } - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *) error diff --git a/Sparkle/SPUUIBasedUpdateDriver.h b/Sparkle/SPUUIBasedUpdateDriver.h index bcba39d6..da12d9b8 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.h +++ b/Sparkle/SPUUIBasedUpdateDriver.h @@ -17,11 +17,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; - (void)uiDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; -- (void)uiDriverDidShowUpdate; -- (void)uiDriverFinishedShowingUpdate; - @optional +- (void)uiDriverDidShowUpdate; - (void)basicDriverDidFinishLoadingAppcast; @end @@ -43,6 +41,8 @@ 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 4ab14602..5e681d5f 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -33,6 +33,7 @@ @property (nonatomic) BOOL resumingInstallingUpdate; @property (nonatomic) BOOL resumingDownloadedUpdate; @property (nonatomic) BOOL preventsInstallerInteraction; +@property (nonatomic) BOOL showingUpdate; @end @@ -48,6 +49,7 @@ @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 { @@ -115,7 +117,7 @@ [self.userDriver showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - [self.delegate uiDriverFinishedShowingUpdate]; + self.showingUpdate = NO; switch (choice) { case SPUSkipThisInformationalVersionChoice: @@ -134,7 +136,7 @@ } else if (self.resumingDownloadedUpdate) { [self.userDriver showDownloadedUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - [self.delegate uiDriverFinishedShowingUpdate]; + self.showingUpdate = NO; [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { @@ -158,7 +160,7 @@ } else if (!self.resumingInstallingUpdate) { [self.userDriver showUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ - [self.delegate uiDriverFinishedShowingUpdate]; + self.showingUpdate = NO; [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { @@ -181,7 +183,7 @@ } else { [self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInstallUpdateStatus choice) { dispatch_async(dispatch_get_main_queue(), ^{ - [self.delegate uiDriverFinishedShowingUpdate]; + self.showingUpdate = NO; [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; [self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction]; @@ -189,7 +191,11 @@ }]; } - [self.delegate uiDriverDidShowUpdate]; + self.showingUpdate = YES; + + if ([self.delegate respondsToSelector:@selector(uiDriverDidShowUpdate)]) { + [self.delegate uiDriverDidShowUpdate]; + } if (updateItem.releaseNotesURL != nil && (![updaterDelegate respondsToSelector:@selector(updaterShouldDownloadReleaseNotes:)] || [updaterDelegate updaterShouldDownloadReleaseNotes:self.updater])) { NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; diff --git a/Sparkle/SPUUserInitiatedUpdateDriver.m b/Sparkle/SPUUserInitiatedUpdateDriver.m index 499f2da3..ca4364b2 100644 --- a/Sparkle/SPUUserInitiatedUpdateDriver.m +++ b/Sparkle/SPUUserInitiatedUpdateDriver.m @@ -18,7 +18,6 @@ @property (nonatomic, readonly) SPUUIBasedUpdateDriver *uiDriver; @property (nonatomic, readonly) id userDriver; @property (nonatomic) BOOL showingUserInitiatedProgress; -@property (nonatomic) BOOL showingUpdate; @property (nonatomic) BOOL aborted; @end @@ -27,7 +26,6 @@ @synthesize uiDriver = _uiDriver; @synthesize userDriver = _userDriver; -@synthesize showingUpdate = _showingUpdate; @synthesize showingUserInitiatedProgress = _showingUserInitiatedProgress; @synthesize aborted = _aborted; @@ -93,14 +91,9 @@ [self.uiDriver resumeUpdate:resumableUpdate completion:completionBlock]; } -- (void)uiDriverDidShowUpdate +- (BOOL)showingUpdate { - self.showingUpdate = YES; -} - -- (void)uiDriverFinishedShowingUpdate -{ - self.showingUpdate = NO; + return self.uiDriver.showingUpdate; } - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error From d9e0265d7676fbcf04bbd2d4a3e927556ba65beb Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 11:32:00 -0700 Subject: [PATCH 3/5] 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]; From 8ff356bc7da76baf7c6d9ed0b37e386e93dd8c19 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Apr 2021 12:16:34 -0700 Subject: [PATCH 4/5] Update documentation on checkForUpdates --- Sparkle/SPUUpdater.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Sparkle/SPUUpdater.h b/Sparkle/SPUUpdater.h index 9f4f567f..de9e559d 100644 --- a/Sparkle/SPUUpdater.h +++ b/Sparkle/SPUUpdater.h @@ -76,16 +76,15 @@ SU_EXPORT @interface SPUUpdater : NSObject - (BOOL)startUpdater:(NSError * __autoreleasing *)error; /*! - Checks for updates, and displays progress while doing so. + Checks for updates, and displays progress while doing so if needed. - This is meant for users initiating an update check. + This is meant for users initiating a new update check or checking the current update progress. - If an update session isn't in progress, the user will be shown that a check for new updates is occurring. - If a new update is already being shown, that update will be shown to the user in active focus. + 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, 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. - This may find a resumable update that has already been downloaded or has begun installing, or - this may find a new update that can start to be downloaded if the user requests it. - This will find updates that the user has opted into skipping. + This will find updates that the user has previously opted into skipping. See canCheckForUpdates property which can determine if this method may be invoked. */ @@ -135,8 +134,8 @@ SU_EXPORT @interface SPUUpdater : NSObject 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 - may be activated and resumed at a later point (automatically or manually). + or even though the update has been downloaded but the installation has been deferred. In both of these cases, a new update session + may be activated with the update resumed at a later point (automatically or manually). See also canCheckForUpdates property which is more suited for menu item validation. */ From cc4c02f467d58b5a9b3dcfb615ce2ef43891809c Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 17 Apr 2021 16:36:28 -0700 Subject: [PATCH 5/5] Add showUpdateInFocus implementation to Test App user driver --- TestApplication/SUPopUpTitlebarUserDriver.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index eaace13c..28bc33f8 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -165,6 +165,15 @@ - (void)showUpdateInFocus { [self.window makeKeyAndOrderFront:nil]; + + if (self.updateButton.enabled) { + // Not the proper way to do things but ignoring warnings in Test App. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-messaging-id" +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [self.updateButton.target performSelector:self.updateButton.action withObject:self.updateButton]; +#pragma clang diagnostic pop + } } #pragma mark Install & Relaunch Update