From 1bb301e82a3e2eecb1afaab7558aff6c4324bc2f Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 9 Apr 2016 11:39:02 -0400 Subject: [PATCH] Change updateInProgress to canCheckForUpdates This more accurately reflects its intended purpose. From the beginning, the user cannot check for updates until the updater is ready; however this doesn't mean that the update is in progress. --- Sparkle/SUStandardUpdaterController.m | 2 +- Sparkle/SUStandardUserDriver.m | 8 ++++---- Sparkle/SUStandardUserDriverProtocol.h | 2 +- Sparkle/SUUpdater.m | 6 +++--- Sparkle/SUUserDriver.h | 6 +++--- Sparkle/SUUserDriverCoreComponent.h | 4 ++-- Sparkle/SUUserDriverCoreComponent.m | 12 ++++++------ TestApplication/SUPopUpTitlebarUserDriver.m | 8 ++++---- .../SURemoteUpdateSettingsWindowController.m | 2 +- Tests/SUUpdaterTest.m | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Sparkle/SUStandardUpdaterController.m b/Sparkle/SUStandardUpdaterController.m index ee114dd9..ee68bf62 100644 --- a/Sparkle/SUStandardUpdaterController.m +++ b/Sparkle/SUStandardUpdaterController.m @@ -66,7 +66,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (BOOL)validateMenuItem:(NSMenuItem *)item { if ([item action] == @selector(checkForUpdates:)) { - return !self.userDriver.updateInProgress; + return self.userDriver.canCheckForUpdates; } return YES; } diff --git a/Sparkle/SUStandardUserDriver.m b/Sparkle/SUStandardUserDriver.m index 09fc8985..5e903cbf 100644 --- a/Sparkle/SUStandardUserDriver.m +++ b/Sparkle/SUStandardUserDriver.m @@ -67,16 +67,16 @@ return self.coreComponent.idlesOnUpdateChecks; } -- (void)showUpdateInProgress:(BOOL)isUpdateInProgress +- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates { dispatch_async(dispatch_get_main_queue(), ^{ - [self.coreComponent showUpdateInProgress:isUpdateInProgress]; + [self.coreComponent showCanCheckForUpdates:canCheckForUpdates]; }); } -- (BOOL)isUpdateInProgress +- (BOOL)canCheckForUpdates { - return self.coreComponent.updateInProgress; + return self.coreComponent.canCheckForUpdates; } #pragma mark Check Updates Timer diff --git a/Sparkle/SUStandardUserDriverProtocol.h b/Sparkle/SUStandardUserDriverProtocol.h index 87244ab5..341a8570 100644 --- a/Sparkle/SUStandardUserDriverProtocol.h +++ b/Sparkle/SUStandardUserDriverProtocol.h @@ -27,7 +27,7 @@ A typical application may rely on this property for its check for updates menu item validation */ -@property (nonatomic, readonly, getter=isUpdateInProgress) BOOL updateInProgress; +@property (nonatomic, readonly) BOOL canCheckForUpdates; /*! Indicates whether or not a currently pending update check will be initiated in the future diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 21a37ee6..e1d7b3d6 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -228,6 +228,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if (firingImmediately) { [self checkForUpdatesInBackground]; } else { + [self.userDriver showCanCheckForUpdates:YES]; + [self retrieveNextUpdateCheckInterval:^(NSTimeInterval updateCheckInterval) { // How long has it been since last we checked for an update? NSDate *lastCheckDate = [self lastUpdateCheckDate]; @@ -398,8 +400,6 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id [self scheduleNextUpdateCheck]; return; } - - [self.userDriver showUpdateInProgress:YES]; [self checkIfConfiguredProperly]; @@ -411,7 +411,6 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id SUUpdater *strongSelf = weakSelf; if (strongSelf != nil) { strongSelf.driver = nil; - [strongSelf.userDriver showUpdateInProgress:NO]; [strongSelf updateLastUpdateCheckDate]; [strongSelf scheduleNextUpdateCheckFiringImmediately:shouldShowUpdateImmediately]; } @@ -420,6 +419,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id [SUProbeInstallStatus probeInstallerInProgressForHost:self.host completion:^(BOOL success) { dispatch_async(dispatch_get_main_queue(), ^{ SUUpdater *strongSelf = weakSelf; + [strongSelf.userDriver showCanCheckForUpdates:NO]; if (strongSelf != nil) { if (!success) { [strongSelf.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[strongSelf userAgentString] httpHeaders:[strongSelf httpHeaders] completion:completionBlock]; diff --git a/Sparkle/SUUserDriver.h b/Sparkle/SUUserDriver.h index 82d88921..ca232176 100644 --- a/Sparkle/SUUserDriver.h +++ b/Sparkle/SUUserDriver.h @@ -32,14 +32,14 @@ NS_ASSUME_NONNULL_BEGIN @protocol SUUserDriver /*! - * Show that an update is or is not in progress. + * Show that an update can be checked by the user or not * - * A client may choose to update the interface letting the user know the updater is or is not busy. + * A client may choose to update the interface letting the user know if they can check for updates. * For example, this can be used for menu item validation on the "Check for Updates" action. * * This can be called from any thread. */ -- (void)showUpdateInProgress:(BOOL)isUpdateInProgress; +- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates; /*! * Idle on timed updater checks. diff --git a/Sparkle/SUUserDriverCoreComponent.h b/Sparkle/SUUserDriverCoreComponent.h index 588be10f..5d4c26c6 100644 --- a/Sparkle/SUUserDriverCoreComponent.h +++ b/Sparkle/SUUserDriverCoreComponent.h @@ -22,9 +22,9 @@ SU_EXPORT @interface SUUserDriverCoreComponent : NSObject @property (nonatomic, readonly) BOOL idlesOnUpdateChecks; -- (void)showUpdateInProgress:(BOOL)isUpdateInProgress; +- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates; -@property (nonatomic, readonly, getter=isUpdateInProgress) BOOL updateInProgress; +@property (nonatomic, readonly) BOOL canCheckForUpdates; @property (nonatomic, readonly) BOOL willInitiateNextUpdateCheck; diff --git a/Sparkle/SUUserDriverCoreComponent.m b/Sparkle/SUUserDriverCoreComponent.m index dc6a1a04..6e7d5691 100644 --- a/Sparkle/SUUserDriverCoreComponent.m +++ b/Sparkle/SUUserDriverCoreComponent.m @@ -17,7 +17,7 @@ @interface SUUserDriverCoreComponent () @property (nonatomic) BOOL idlesOnUpdateChecks; -@property (nonatomic) BOOL updateInProgress; +@property (nonatomic) BOOL canCheckForUpdates; @property (nonatomic) NSTimer *checkUpdateTimer; @property (nonatomic, copy) void (^checkForUpdatesReply)(SUUpdateCheckTimerStatus); @@ -33,7 +33,7 @@ @synthesize delegate = _delegate; @synthesize idlesOnUpdateChecks = _idlesOnUpdateChecks; -@synthesize updateInProgress = _updateInProgress; +@synthesize canCheckForUpdates = _canCheckForUpdates; @synthesize checkUpdateTimer = _checkUpdateTimer; @synthesize checkForUpdatesReply = _checkForUpdatesReply; @synthesize installUpdateHandler = _installUpdateHandler; @@ -59,9 +59,9 @@ self.idlesOnUpdateChecks = shouldIdleOnUpdateChecks; } -- (void)showUpdateInProgress:(BOOL)isUpdateInProgress +- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates { - self.updateInProgress = isUpdateInProgress; + self.canCheckForUpdates = canCheckForUpdates; } #pragma mark Check Updates Timer @@ -212,8 +212,6 @@ { // Note: self.idlesOnUpdateChecks is intentionally not touched in case this instance is re-used - self.updateInProgress = NO; - [self acceptAcknowledgement]; [self cancelUpdateCheckStatus]; [self cancelDownloadStatus]; @@ -236,6 +234,8 @@ // Dismiss the installation normally [self dismissUpdateInstallation]; + + self.canCheckForUpdates = YES; } @end diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index cd6736e9..12b2c9e4 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -115,16 +115,16 @@ return self.coreComponent.idlesOnUpdateChecks; } -- (void)showUpdateInProgress:(BOOL)isUpdateInProgress +- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates { dispatch_async(dispatch_get_main_queue(), ^{ - [self.coreComponent showUpdateInProgress:isUpdateInProgress]; + [self.coreComponent showCanCheckForUpdates:canCheckForUpdates]; }); } -- (BOOL)isUpdateInProgress +- (BOOL)canCheckForUpdates { - return self.coreComponent.updateInProgress; + return self.coreComponent.canCheckForUpdates; } #pragma mark Check Updates Timer diff --git a/TestApplication/SURemoteUpdateSettingsWindowController.m b/TestApplication/SURemoteUpdateSettingsWindowController.m index 30348d93..506dd7d6 100644 --- a/TestApplication/SURemoteUpdateSettingsWindowController.m +++ b/TestApplication/SURemoteUpdateSettingsWindowController.m @@ -153,7 +153,7 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { if (menuItem.action == @selector(checkForUpdates:)) { - return (self.userDriver != nil && !self.userDriver.updateInProgress); + return (self.userDriver != nil && self.userDriver.canCheckForUpdates); } else if (menuItem.action == @selector(invalidateConnection:)) { return (self.connection != nil); } diff --git a/Tests/SUUpdaterTest.m b/Tests/SUUpdaterTest.m index e37752bc..4d1e31a8 100644 --- a/Tests/SUUpdaterTest.m +++ b/Tests/SUUpdaterTest.m @@ -19,7 +19,7 @@ @implementation SUUselessUserDriver -- (void)showUpdateInProgress:(BOOL)__unused isUpdateInProgress {} +- (void)showCanCheckForUpdates:(BOOL)__unused canCheckForUpdates {} - (void)idleOnUpdateChecks:(BOOL)__unused shouldIdleOnUpdateChecks {}