Merge pull request #1827 from sparkle-project/show-update-focus

Show the present update in focus when checkForUpdates is invoked
This commit is contained in:
Mayur Pawashe authored and GitHub committed 2021-04-18 18:29:11 -07:00
commit fe8b6b3e2a
15 files changed
+144 -71

No files matched your search

+5
View File
@@ -89,6 +89,11 @@
}
}
- (BOOL)showingUpdate
{
return NO;
}
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
{
self.willInstallSilently = willInstallSilently;
+5
View File
@@ -60,6 +60,11 @@
[self abortUpdate];
}
- (BOOL)showingUpdate
{
return NO;
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
{
[self abortUpdateWithError:error];
+5
View File
@@ -65,6 +65,11 @@
self.showedUpdate = YES;
}
- (BOOL)showingUpdate
{
return self.showedUpdate;
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *) error
{
// Don't tell the user that no update was found or some appcast fetch error occurred for scheduled update checks if we haven't shown the update
+20 -16
View File
@@ -65,13 +65,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
@@ -107,10 +100,8 @@
// 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.window makeKeyAndOrderFront:self];
[self.activeUpdateAlert setInstallButtonFocus:userInitiated];
[self.activeUpdateAlert showWindow:nil];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
}
@@ -118,7 +109,7 @@
- (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification
{
[self.activeUpdateAlert.window makeKeyAndOrderFront:self];
[self.activeUpdateAlert showWindow:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp];
}
@@ -159,17 +150,30 @@
[self.activeUpdateAlert showReleaseNotesFailedToDownload];
}
- (void)showUpdateInFocus
{
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
- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))installUpdateHandler
{
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;
@@ -279,7 +283,7 @@
#pragma mark Download & Install Updates
- (void)showStatusController
- (void)createAndShowStatusController
{
if (self.statusController == nil) {
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
@@ -293,7 +297,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];
}
@@ -367,7 +371,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];
+1 -1
View File
@@ -19,8 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
@optional
- (void)basicDriverDidFinishLoadingAppcast;
- (void)uiDriverDidShowUpdate;
- (void)basicDriverDidFinishLoadingAppcast;
@end
+2
View File
@@ -25,6 +25,8 @@ typedef void (^SPUUpdateDriverCompletion)(BOOL shouldShowUpdateImmediately, id<S
- (void)resumeUpdate:(id<SPUResumableUpdate>)resumableUpdate completion:(SPUUpdateDriverCompletion)completionBlock;
@property (nonatomic, readonly) BOOL showingUpdate;
// A likely implementation of -abortUpdate is invoking -abortUpdateWithError: by passing nil
- (void)abortUpdate;
+30 -10
View File
@@ -76,12 +76,17 @@ 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 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 is meant for users initiating a new update check or checking the current update progress.
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 will find updates that the user has previously opted into skipping.
See canCheckForUpdates property which can determine if this method may be invoked.
*/
- (void)checkForUpdates;
@@ -111,16 +116,31 @@ 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 or its progress is being shown to the user.
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, 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, 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.
*/
@property (nonatomic, readonly) BOOL sessionInProgress;
/*!
A property indicating whether or not to check for updates automatically.
+36 -23
View File
@@ -55,7 +55,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
@property (nonatomic, readonly) SPUUpdaterTimer *updaterTimer;
@property (nonatomic) BOOL startedUpdater;
@property (nonatomic, nullable) id<SPUResumableUpdate> resumableUpdate;
@property (nonatomic) BOOL canCheckForUpdates;
@property (nonatomic) BOOL sessionInProgress;
@property (nonatomic) BOOL showingPermissionRequest;
@property (nonatomic, copy) NSDate *updateLastCheckedDate;
@@ -79,7 +80,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
@synthesize sparkleBundle = _sparkleBundle;
@synthesize startedUpdater = _startedUpdater;
@synthesize resumableUpdate = _resumableUpdate;
@synthesize canCheckForUpdates = _canCheckForUpdates;
@synthesize sessionInProgress = _sessionInProgress;
@synthesize showingPermissionRequest = _showingPermissionRequest;
@synthesize updateLastCheckedDate = _updateLastCheckedDate;
@synthesize loggedATSWarning = _loggedATSWarning;
@synthesize loggedDSAWarning = _loggedDSAWarning;
@@ -147,12 +149,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];
}
});
@@ -308,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];
@@ -357,11 +364,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
[self scheduleNextUpdateCheckFiringImmediately:NO];
}
- (void)setCanCheckForUpdates:(BOOL)canCheckForUpdates
- (BOOL)canCheckForUpdates
{
_canCheckForUpdates = canCheckForUpdates;
[self.userDriver showCanCheckForUpdates:canCheckForUpdates];
return self.startedUpdater && (self.showingPermissionRequest || self.driver.showingUpdate || !self.sessionInProgress);
}
- (void)scheduleNextUpdateCheckFiringImmediately:(BOOL)firingImmediately
@@ -416,11 +421,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 +474,34 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
- (void)checkForUpdates
{
__weak SPUUpdater *weakSelf = self;
if (self.showingPermissionRequest || 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 <SPUUpdateDriver> 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 +527,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 +557,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 +573,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 +588,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 +604,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 +621,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
return; // not even ready yet
}
if (self.canCheckForUpdates) {
if (!self.sessionInProgress) {
[self cancelNextUpdateCycle];
[self scheduleNextUpdateCheck];
}
+8 -7
View File
@@ -32,13 +32,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
SU_EXPORT @protocol SPUUserDriver <NSObject>
/*!
* 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
*
@@ -233,6 +226,14 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
*/
- (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
*
+4
View File
@@ -18,6 +18,7 @@
@property (nonatomic, readonly) SPUUIBasedUpdateDriver *uiDriver;
@property (nonatomic, readonly) id<SPUUserDriver> 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 <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate
@@ -58,6 +60,8 @@
});
};
self.showingUpdate = YES;
if ([self.userDriver respondsToSelector:@selector(showUserInitiatedUpdateCheckWithCancellation:)]) {
[self.userDriver showUserInitiatedUpdateCheckWithCancellation:cancelUpdateCheck];
} else {
+2 -1
View File
@@ -28,7 +28,8 @@
- (IBAction)installUpdate:sender;
- (IBAction)skipThisVersion:sender;
- (IBAction)remindMeLater:sender;
- (void)disableKeyboardShortcutForInstallButton;
- (void)setInstallButtonFocus:(BOOL)focus;
@end
+7 -2
View File
@@ -100,8 +100,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:(SPUUserUpdateChoice)choice
+1 -1
View File
@@ -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
+14 -6
View File
@@ -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
@@ -168,6 +162,20 @@
{
}
- (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
- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))installUpdateHandler
+4 -4
View File
@@ -41,10 +41,6 @@
return self;
}
- (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates
{
}
- (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)__unused request reply:(void (^)(SUUpdatePermissionResponse *))reply
{
if (self.updatePermissionResponse == nil) {
@@ -133,6 +129,10 @@
}
}
- (void)showUpdateInFocus
{
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
{
if (self.verbose) {