Add new user driver methods to cancel update checks / downloads

Remove SPUUserDriverCoreComponent dependency from sparkle-cli and the Test App too, which really wasn't helping at all.
This commit is contained in:
Zorg committed 2021-04-11 23:15:02 -07:00
1 parent 9052ea912d
commit 2d9bf07b18
9 files changed
+110 -146

No files matched your search

+8 -8
View File
@@ -217,11 +217,11 @@
#pragma mark Check for Updates
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion
- (void)showUserInitiatedUpdateCheckWithCancellation:(void (^)(void))cancellation
{
assert(NSThread.isMainThread);
[self.coreComponent registerUpdateCheckStatusHandler:updateCheckStatusCompletion];
[self.coreComponent registerCancellation:cancellation];
self.checkingController = [[SUStatusController alloc] initWithHost:self.host];
[[self.checkingController window] center]; // Force the checking controller to load its window.
@@ -248,7 +248,7 @@
- (void)cancelCheckForUpdates:(id)__unused sender
{
[self.coreComponent cancelUpdateCheckStatus];
[self.coreComponent cancel];
[self closeCheckingWindow];
}
@@ -256,7 +256,7 @@
{
assert(NSThread.isMainThread);
[self.coreComponent completeUpdateCheckStatus];
[self.coreComponent clearCancellation];
[self closeCheckingWindow];
}
@@ -320,11 +320,11 @@
}
}
- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion
- (void)showDownloadInitiatedWithCancellation:(void (^)(void))cancellation
{
assert(NSThread.isMainThread);
[self.coreComponent registerDownloadStatusHandler:downloadUpdateStatusCompletion];
[self.coreComponent registerCancellation:cancellation];
[self showStatusController];
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
@@ -333,7 +333,7 @@
- (void)cancelDownload:(id)__unused sender
{
[self.coreComponent cancelDownloadStatus];
[self.coreComponent cancel];
}
- (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
@@ -395,7 +395,7 @@
{
assert(NSThread.isMainThread);
[self.coreComponent completeDownloadStatus];
[self.coreComponent clearCancellation];
[self showStatusController];
[self.statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
+12 -10
View File
@@ -18,16 +18,6 @@
#import <Foundation/Foundation.h>
#endif
typedef NS_ENUM(NSUInteger, SPUUserInitiatedCheckStatus) {
SPUUserInitiatedCheckDone __deprecated_msg("Deprecated because SPUUserInitiatedCheckDone has no effect. Just don't reply with this status."),
SPUUserInitiatedCheckCanceled
};
typedef NS_ENUM(NSUInteger, SPUDownloadUpdateStatus) {
SPUDownloadUpdateDone __deprecated_msg("Deprecated because SPUDownloadUpdateDone has no effect. Just don't reply with this status."),
SPUDownloadUpdateCanceled
};
typedef NS_ENUM(NSUInteger, SPUInstallUpdateStatus) {
SPUInstallUpdateNow,
SPUInstallAndRelaunchUpdateNow,
@@ -45,4 +35,16 @@ typedef NS_ENUM(NSInteger, SPUInformationalUpdateAlertChoice) {
SPUSkipThisInformationalVersionChoice
};
// Deprecated
typedef NS_ENUM(NSUInteger, SPUUserInitiatedCheckStatus) {
SPUUserInitiatedCheckDone,
SPUUserInitiatedCheckCanceled
};
// Deprecated
typedef NS_ENUM(NSUInteger, SPUDownloadUpdateStatus) {
SPUDownloadUpdateDone,
SPUDownloadUpdateCanceled
};
#endif /* SPUStatusCompletionResults_h */
+23 -16
View File
@@ -201,25 +201,32 @@
- (void)downloadDriverWillBeginDownload
{
[self.userDriver showDownloadInitiatedWithCompletion:^(SPUDownloadUpdateStatus downloadCompletionStatus) {
switch (downloadCompletionStatus) {
void (^cancelDownload)(void) = ^{
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.updaterDelegate respondsToSelector:@selector((userDidCancelDownload:))]) {
[self.updaterDelegate userDidCancelDownload:self.updater];
}
[self.delegate uiDriverIsRequestingAbortUpdateWithError:nil];
});
};
if ([self.userDriver respondsToSelector:@selector(showDownloadInitiatedWithCancellation:)]) {
[self.userDriver showDownloadInitiatedWithCancellation:cancelDownload];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
case SPUDownloadUpdateDone:
// Note this status is documented to have no effect
[self.userDriver showDownloadInitiatedWithCompletion:^(SPUDownloadUpdateStatus downloadCompletionStatus) {
switch (downloadCompletionStatus) {
#pragma clang diagnostic pop
break;
case SPUDownloadUpdateCanceled:
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.updaterDelegate respondsToSelector:@selector((userDidCancelDownload:))]) {
[self.updaterDelegate userDidCancelDownload:self.updater];
}
[self.delegate uiDriverIsRequestingAbortUpdateWithError:nil];
});
break;
}
}];
case SPUDownloadUpdateDone:
break;
case SPUDownloadUpdateCanceled:
cancelDownload();
break;
}
}];
}
}
- (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
+14 -6
View File
@@ -55,10 +55,10 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
*
* Respond to the user initiating an update check. Sparkle uses this to show the user a window with an indeterminate progress bar.
*
* @param updateCheckStatusCompletion A reply that can be used to cancel the update check with SPUUserInitiatedCheckCanceled.
* @param cancellation Invoke this cancellation block to cancel the update check.
* Attempts to canceling can be made before -dismissUserInitiatedUpdateCheck is invoked.
*/
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion;
- (void)showUserInitiatedUpdateCheckWithCancellation:(void (^)(void))cancellation;
/*!
* Dismiss the user initiated update check from the user
@@ -179,10 +179,9 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
*
* Let the user know that downloading the new update started.
*
* @param downloadUpdateStatusCompletion A reply of SPUDownloadUpdateCanceled can be used to cancel
* the download at any point before -showDownloadDidStartExtractingUpdate is invoked.
* @param cancellation Invoke this cancellation block to cancel the download at any point before -showDownloadDidStartExtractingUpdate is invoked.
*/
- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion;
- (void)showDownloadInitiatedWithCancellation:(void (^)(void))cancellation;
/*!
* Show the user the content length of the new update that will be downloaded
@@ -267,16 +266,25 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
/*!
* Dismiss the current update installation
*
* Stop and tear down everything. Reply to all outstanding reply/completion blocks.
* Stop and tear down everything.
* Dismiss all update windows, alerts, progress, etc from the user.
* Basically, stop everything that could have been started. Sparkle may invoke this when aborting or finishing an update.
*/
- (void)dismissUpdateInstallation;
/*
* 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
- (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))acknowledgement __deprecated_msg("Implement -showUpdateNotFoundWithError:acknowledgement: instead");
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion __deprecated_msg("Implement -showUserInitiatedUpdateCheckWithCancellation: instead");
- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion __deprecated_msg("Implement -showDownloadInitiatedWithCancellation: instead");
@end
NS_ASSUME_NONNULL_END
+3 -7
View File
@@ -24,13 +24,9 @@ SU_EXPORT @interface SPUUserDriverCoreComponent : NSObject
- (void)registerInstallUpdateHandler:(void (^)(SPUInstallUpdateStatus))installUpdateHandler;
- (void)installUpdateWithChoice:(SPUInstallUpdateStatus)choice;
- (void)registerUpdateCheckStatusHandler:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion;
- (void)cancelUpdateCheckStatus;
- (void)completeUpdateCheckStatus;
- (void)registerDownloadStatusHandler:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion;
- (void)cancelDownloadStatus;
- (void)completeDownloadStatus;
- (void)registerCancellation:(void (^)(void))cancellation;
- (void)cancel;
- (void)clearCancellation;
- (void)registerAcknowledgement:(void (^)(void))acknowledgement;
- (void)acceptAcknowledgement;
+14 -37
View File
@@ -14,8 +14,7 @@
@interface SPUUserDriverCoreComponent ()
@property (nonatomic, copy) void (^installUpdateHandler)(SPUInstallUpdateStatus);
@property (nonatomic, copy) void (^updateCheckStatusCompletion)(SPUUserInitiatedCheckStatus);
@property (nonatomic, copy) void (^downloadStatusCompletion)(SPUDownloadUpdateStatus);
@property (nonatomic, copy) void (^cancellation)(void);
@property (nonatomic, copy) void (^acknowledgement)(void);
@end
@@ -23,8 +22,7 @@
@implementation SPUUserDriverCoreComponent
@synthesize installUpdateHandler = _installUpdateHandler;
@synthesize updateCheckStatusCompletion = _updateCheckStatusCompletion;
@synthesize downloadStatusCompletion = _downloadStatusCompletion;
@synthesize cancellation = _cancellation;
@synthesize acknowledgement = _acknowledgement;
#pragma mark Install Updates
@@ -50,44 +48,24 @@
}
}
#pragma mark Update Check Status
#pragma mark Cancellation
- (void)registerUpdateCheckStatusHandler:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion
- (void)registerCancellation:(void (^)(void))cancellation
{
self.updateCheckStatusCompletion = updateCheckStatusCompletion;
self.cancellation = cancellation;
}
- (void)cancelUpdateCheckStatus
- (void)cancel
{
if (self.updateCheckStatusCompletion != nil) {
self.updateCheckStatusCompletion(SPUUserInitiatedCheckCanceled);
self.updateCheckStatusCompletion = nil;
if (self.cancellation != nil) {
self.cancellation();
self.cancellation = nil;
}
}
- (void)completeUpdateCheckStatus
- (void)clearCancellation
{
self.updateCheckStatusCompletion = nil;
}
#pragma mark Download Status
- (void)registerDownloadStatusHandler:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion
{
self.downloadStatusCompletion = downloadUpdateStatusCompletion;
}
- (void)cancelDownloadStatus
{
if (self.downloadStatusCompletion != nil) {
self.downloadStatusCompletion(SPUDownloadUpdateCanceled);
self.downloadStatusCompletion = nil;
}
}
- (void)completeDownloadStatus
{
self.downloadStatusCompletion = nil;
self.cancellation = nil;
}
#pragma mark Simple Acknoledgments
@@ -109,10 +87,9 @@
- (void)dismissUpdateInstallation
{
[self acceptAcknowledgement];
[self cancelUpdateCheckStatus];
[self cancelDownloadStatus];
[self dismissInstallAndRestart];
self.acknowledgement = nil;
self.cancellation = nil;
self.installUpdateHandler = nil;
}
@end
+21 -14
View File
@@ -50,23 +50,30 @@
} else {
self.showingUserInitiatedProgress = YES;
[self.userDriver showUserInitiatedUpdateCheckWithCompletion:^(SPUUserInitiatedCheckStatus completionStatus) {
switch (completionStatus) {
void (^cancelUpdateCheck)(void) = ^{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.showingUserInitiatedProgress) {
[self abortUpdate];
}
});
};
if ([self.userDriver respondsToSelector:@selector(showUserInitiatedUpdateCheckWithCancellation:)]) {
[self.userDriver showUserInitiatedUpdateCheckWithCancellation:cancelUpdateCheck];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
case SPUUserInitiatedCheckDone:
// Note this status is documented to have no effect
[self.userDriver showUserInitiatedUpdateCheckWithCompletion:^(SPUUserInitiatedCheckStatus completionStatus) {
#pragma clang diagnostic pop
break;
case SPUUserInitiatedCheckCanceled:
dispatch_async(dispatch_get_main_queue(), ^{
if (self.showingUserInitiatedProgress) {
[self abortUpdate];
}
});
break;
}
}];
switch (completionStatus) {
case SPUUserInitiatedCheckDone:
break;
case SPUUserInitiatedCheckCanceled:
cancelUpdateCheck();
break;
}
}];
}
[self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:NO includesSkippedUpdates:YES];
}
+8 -27
View File
@@ -13,7 +13,6 @@
@property (nonatomic, readonly) NSWindow *window;
@property (nonatomic, nullable) SUInstallUpdateViewController *installUpdateViewController;
@property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent;
@property (nonatomic) NSTitlebarAccessoryViewController *accessoryViewController;
@property (nonatomic) BOOL addedAccessory;
@property (nonatomic) NSButton *updateButton;
@@ -27,7 +26,6 @@
@synthesize window = _window;
@synthesize installUpdateViewController = _installUpdateViewController;
@synthesize coreComponent = _coreComponent;
@synthesize accessoryViewController = _accessoryViewController;
@synthesize addedAccessory = _addedAccessory;
@synthesize updateButton = _updateButton;
@@ -40,7 +38,6 @@
self = [super init];
if (self != nil) {
_window = window;
_coreComponent = [[SPUUserDriverCoreComponent alloc] init];
}
return self;
}
@@ -189,63 +186,52 @@
- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler
{
[self.coreComponent registerInstallUpdateHandler:installUpdateHandler];
__weak SUPopUpTitlebarUserDriver *weakSelf = self;
[self addUpdateButtonWithTitle:@"Install & Relaunch" action:^(NSButton *__unused button) {
[weakSelf.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow];
installUpdateHandler(SPUInstallAndRelaunchUpdateNow);
}];
}
#pragma mark Check for Updates
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion
- (void)showUserInitiatedUpdateCheckWithCancellation:(void (^)(void))__unused cancellation
{
[self.coreComponent registerUpdateCheckStatusHandler:updateCheckStatusCompletion];
[self addUpdateButtonWithTitle:@"Checking for Updates…"];
}
- (void)dismissUserInitiatedUpdateCheck
{
[self.coreComponent completeUpdateCheckStatus];
[self removeUpdateButton];
}
#pragma mark Update Errors
- (void)acceptAcknowledgementAfterDelay
- (void)acceptAcknowledgementAfterDelay:(void (^)(void))acknowledgement
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Installation will be dismissed shortly after this
[self.coreComponent acceptAcknowledgement];
acknowledgement();
});
}
- (void)showUpdaterError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement
{
[self.coreComponent registerAcknowledgement:acknowledgement];
NSLog(@"Error: %@", error);
[self addUpdateButtonWithTitle:@"Update Errored!" action:nil];
[self acceptAcknowledgementAfterDelay];
[self acceptAcknowledgementAfterDelay:acknowledgement];
}
- (void)showUpdateNotFoundWithError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement
{
[self.coreComponent registerAcknowledgement:acknowledgement];
[self addUpdateButtonWithTitle:@"No Update Available" action:nil];
[self acceptAcknowledgementAfterDelay];
[self acceptAcknowledgementAfterDelay:acknowledgement];
}
#pragma mark Download & Install Updates
- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion
- (void)showDownloadInitiatedWithCancellation:(void (^)(void))__unused cancellation
{
[self.coreComponent registerDownloadStatusHandler:downloadUpdateStatusCompletion];
}
- (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
@@ -272,7 +258,6 @@
- (void)showDownloadDidStartExtractingUpdate
{
[self.coreComponent completeDownloadStatus];
[self addUpdateButtonWithTitle:@"Extracting…"];
}
@@ -294,19 +279,15 @@
- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement
{
[self.coreComponent registerAcknowledgement:acknowledgement];
[self addUpdateButtonWithTitle:@"Installation Finished!"];
[self acceptAcknowledgementAfterDelay];
[self acceptAcknowledgementAfterDelay:acknowledgement];
}
#pragma mark Aborting Everything
- (void)dismissUpdateInstallation
{
[self.coreComponent dismissUpdateInstallation];
[self removeUpdateButton];
}
+7 -21
View File
@@ -17,7 +17,6 @@
@property (nonatomic, nullable, readonly) SUUpdatePermissionResponse *updatePermissionResponse;
@property (nonatomic, readonly) BOOL deferInstallation;
@property (nonatomic, readonly) BOOL verbose;
@property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent;
@property (nonatomic) uint64_t bytesDownloaded;
@property (nonatomic) uint64_t bytesToDownload;
@@ -28,7 +27,6 @@
@synthesize updatePermissionResponse = _updatePermissionResponse;
@synthesize deferInstallation = _deferInstallation;
@synthesize verbose = _verbose;
@synthesize coreComponent = _coreComponent;
@synthesize bytesDownloaded = _bytesDownloaded;
@synthesize bytesToDownload = _bytesToDownload;
@@ -39,7 +37,6 @@
_updatePermissionResponse = updatePermissionResponse;
_deferInstallation = deferInstallation;
_verbose = verbose;
_coreComponent = [[SPUUserDriverCoreComponent alloc] init];
}
return self;
}
@@ -62,9 +59,8 @@
}
}
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion
- (void)showUserInitiatedUpdateCheckWithCancellation:(void (^)(void))__unused cancellation
{
[self.coreComponent registerUpdateCheckStatusHandler:updateCheckStatusCompletion];
if (self.verbose) {
fprintf(stderr, "Checking for Updates...\n");
}
@@ -72,7 +68,6 @@
- (void)dismissUserInitiatedUpdateCheck
{
[self.coreComponent completeUpdateCheckStatus];
}
- (void)displayReleaseNotes:(const char * _Nullable)releaseNotes
@@ -124,16 +119,15 @@
- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply
{
[self.coreComponent registerInstallUpdateHandler:reply];
[self showUpdateWithAppcastItem:appcastItem updateAdjective:@"resumable"];
if (self.deferInstallation) {
if (self.verbose) {
fprintf(stderr, "Deferring Installation.\n");
}
[self.coreComponent installUpdateWithChoice:SPUDismissUpdateInstallation];
reply(SPUDismissUpdateInstallation);
} else {
[self.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow];
reply(SPUInstallAndRelaunchUpdateNow);
}
}
@@ -187,10 +181,8 @@
exit(EXIT_FAILURE);
}
- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion
- (void)showDownloadInitiatedWithCancellation:(void (^)(void))__unused cancellation
{
[self.coreComponent registerDownloadStatusHandler:downloadUpdateStatusCompletion];
if (self.verbose) {
fprintf(stderr, "Downloading Update...\n");
}
@@ -221,8 +213,6 @@
- (void)showDownloadDidStartExtractingUpdate
{
[self.coreComponent completeDownloadStatus];
if (self.verbose) {
fprintf(stderr, "Extracting update...\n");
}
@@ -237,15 +227,13 @@
- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler
{
[self.coreComponent registerInstallUpdateHandler:installUpdateHandler];
if (self.deferInstallation) {
if (self.verbose) {
fprintf(stderr, "Deferring Installation.\n");
}
[self.coreComponent installUpdateWithChoice:SPUDismissUpdateInstallation];
installUpdateHandler(SPUDismissUpdateInstallation);
} else {
[self.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow];
installUpdateHandler(SPUInstallAndRelaunchUpdateNow);
}
}
@@ -258,13 +246,11 @@
- (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement
{
[self.coreComponent registerAcknowledgement:acknowledgement];
if (self.verbose) {
fprintf(stderr, "Installation Finished.\n");
}
[self.coreComponent acceptAcknowledgement];
acknowledgement();
}
- (void)dismissUpdateInstallation __attribute__((noreturn))