diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index d38c7db3..1a94c835 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -220,8 +220,6 @@ 725CB95B1C7121830064365A /* SPUStandardUserDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 725CB9591C7121830064365A /* SPUStandardUserDriver.m */; }; 725F97771C8A62F500265BE4 /* SUAdHocCodeSigning.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */; }; 725F97781C8A65AC00265BE4 /* SUAdHocCodeSigning.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */; }; - 725F977B1C8A896F00265BE4 /* SPUUserDriverCoreComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 725F97791C8A896F00265BE4 /* SPUUserDriverCoreComponent.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 725F977C1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F977A1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m */; }; 725F97841C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97831C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m */; }; 725F97A51C8B304D00265BE4 /* SUInstallUpdateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97A31C8B304D00265BE4 /* SUInstallUpdateViewController.m */; }; 725F97A61C8B304D00265BE4 /* SUInstallUpdateViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 725F97A41C8B304D00265BE4 /* SUInstallUpdateViewController.xib */; }; @@ -365,7 +363,6 @@ 72A5D5D71D6929F80009E5AC /* SUUpdatePermissionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */; }; 72A5D5D81D6929F80009E5AC /* SPUUpdaterCycle.m in Sources */ = {isa = PBXBuildFile; fileRef = 720E217A1D0D00BF003A311C /* SPUUpdaterCycle.m */; }; 72A5D5D91D6929F90009E5AC /* SPUUpdaterTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */; }; - 72A5D5DA1D6929F90009E5AC /* SPUUserDriverCoreComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F977A1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m */; }; 72A5D5DC1D692A4E0009E5AC /* SUCodeSigningVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5991D3D8A5A00D1BF90 /* SUCodeSigningVerifier.m */; }; 72A5D5DE1D692ACC0009E5AC /* SparkleCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A5D5DD1D692ACC0009E5AC /* SparkleCore.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5DF1D692B570009E5AC /* SUAppcast.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5FB9409C4F04600B25A18 /* SUAppcast.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -379,7 +376,6 @@ 72A5D5E71D692BB00009E5AC /* SPUUpdatePermissionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 72DBA37B1D60CC34002594A8 /* SPUUpdatePermissionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5E81D692BBB0009E5AC /* SUUpdatePermissionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5E91D692BC80009E5AC /* SPUUserDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 725CB9561C7120410064365A /* SPUUserDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 72A5D5EA1D692BC80009E5AC /* SPUUserDriverCoreComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 725F97791C8A896F00265BE4 /* SPUUserDriverCoreComponent.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5EB1D692BD40009E5AC /* SPUDownloadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5EF1D692C440009E5AC /* Autoupdate in Copy Tools */ = {isa = PBXBuildFile; fileRef = 72B398D21D3D879300EE297F /* Autoupdate */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 72A5D5F01D692C4B0009E5AC /* Updater.app in Copy Tools */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -1203,8 +1199,6 @@ 725CB9591C7121830064365A /* SPUStandardUserDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUStandardUserDriver.m; sourceTree = ""; }; 725F97741C8A62F500265BE4 /* SUAdHocCodeSigning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAdHocCodeSigning.h; sourceTree = ""; }; 725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAdHocCodeSigning.m; sourceTree = ""; }; - 725F97791C8A896F00265BE4 /* SPUUserDriverCoreComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUserDriverCoreComponent.h; sourceTree = ""; }; - 725F977A1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUserDriverCoreComponent.m; sourceTree = ""; }; 725F97821C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPopUpTitlebarUserDriver.h; sourceTree = ""; }; 725F97831C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPopUpTitlebarUserDriver.m; sourceTree = ""; }; 725F97A21C8B304D00265BE4 /* SUInstallUpdateViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUInstallUpdateViewController.h; sourceTree = ""; }; @@ -2153,8 +2147,6 @@ 726E4A361C89116000C57C6A /* SPUStandardUserDriverDelegate.h */, 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */, 725CB9561C7120410064365A /* SPUUserDriver.h */, - 725F97791C8A896F00265BE4 /* SPUUserDriverCoreComponent.h */, - 725F977A1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m */, ); name = "User Driver"; sourceTree = ""; @@ -2414,7 +2406,6 @@ 72A5D5E41D692B770009E5AC /* SPUUpdaterDelegate.h in Headers */, 72A5D5E31D692B770009E5AC /* SPUUpdaterSettings.h in Headers */, 72A5D5E91D692BC80009E5AC /* SPUUserDriver.h in Headers */, - 72A5D5EA1D692BC80009E5AC /* SPUUserDriverCoreComponent.h in Headers */, 72A5D5DF1D692B570009E5AC /* SUAppcast.h in Headers */, 72A5D5E01D692B570009E5AC /* SUAppcastItem.h in Headers */, 72A5D5E61D692BA20009E5AC /* SUErrors.h in Headers */, @@ -2462,7 +2453,6 @@ 723ABFC4259D4CB300BDB4FA /* SUWKWebView.h in Headers */, 7293A1AE1CEE933800B957A7 /* SPUURLRequest.h in Headers */, 725CB9571C7120410064365A /* SPUUserDriver.h in Headers */, - 725F977B1C8A896F00265BE4 /* SPUUserDriverCoreComponent.h in Headers */, 72B767DE1C9CDB9700A07552 /* SPUUserInitiatedUpdateDriver.h in Headers */, 72F94F581CC44DE1002DEE68 /* SPUXPCServiceInfo.h in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, @@ -3512,7 +3502,6 @@ 72A5D5D91D6929F90009E5AC /* SPUUpdaterTimer.m in Sources */, 72A5D5BB1D6929F80009E5AC /* SPUURLDownload.m in Sources */, 72A5D5BC1D6929F80009E5AC /* SPUURLRequest.m in Sources */, - 72A5D5DA1D6929F90009E5AC /* SPUUserDriverCoreComponent.m in Sources */, 72A5D5C81D6929F80009E5AC /* SPUUserInitiatedUpdateDriver.m in Sources */, 72A5D5AD1D6929F80009E5AC /* SPUXPCServiceInfo.m in Sources */, 72A5D5B91D6929F80009E5AC /* SUAppcast.m in Sources */, @@ -3624,7 +3613,6 @@ 72F9EC401D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */, 72B09CE81CE6BCBD0052EF9E /* SPUURLDownload.m in Sources */, 7293A1AF1CEE933800B957A7 /* SPUURLRequest.m in Sources */, - 725F977C1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m in Sources */, 72B767DF1C9CDB9700A07552 /* SPUUserInitiatedUpdateDriver.m in Sources */, 72F94F591CC44DE1002DEE68 /* SPUXPCServiceInfo.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index b9c3ed0f..ec544826 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -7,7 +7,6 @@ // #import "SPUStandardUserDriver.h" -#import "SPUUserDriverCoreComponent.h" #import "SPUStandardUserDriverDelegate.h" #import "SUAppcastItem.h" #import "SUVersionDisplayProtocol.h" @@ -23,9 +22,11 @@ @property (nonatomic, readonly) SUHost *host; -@property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent; @property (nonatomic, weak, nullable, readonly) id delegate; +@property (nonatomic, copy) void (^installUpdateHandler)(SPUInstallUpdateStatus); +@property (nonatomic, copy) void (^cancellation)(void); + @property (nonatomic) SUStatusController *checkingController; @property (nonatomic) SUUpdateAlert *activeUpdateAlert; @property (nonatomic) SUStatusController *statusController; @@ -36,7 +37,8 @@ @implementation SPUStandardUserDriver @synthesize host = _host; -@synthesize coreComponent = _coreComponent; +@synthesize installUpdateHandler = _installUpdateHandler; +@synthesize cancellation = _cancellation; @synthesize delegate = _delegate; @synthesize checkingController = _checkingController; @synthesize activeUpdateAlert = _activeUpdateAlert; @@ -51,7 +53,6 @@ if (self != nil) { _host = [[SUHost alloc] initWithBundle:hostBundle]; _delegate = delegate; - _coreComponent = [[SPUUserDriverCoreComponent alloc] init]; } return self; } @@ -207,21 +208,24 @@ [[self.statusController window] makeKeyAndOrderFront:self]; [NSApp requestUserAttention:NSInformationalRequest]; - [self.coreComponent registerInstallUpdateHandler:installUpdateHandler]; + self.installUpdateHandler = installUpdateHandler; } - (void)installAndRestart:(id)__unused sender { - [self.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow]; + if (self.installUpdateHandler != nil) { + self.installUpdateHandler(SPUInstallAndRelaunchUpdateNow); + self.installUpdateHandler = nil; + } } #pragma mark Check for Updates -- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion +- (void)showUserInitiatedUpdateCheckWithCancellation:(void (^)(void))cancellation { assert(NSThread.isMainThread); - [self.coreComponent registerUpdateCheckStatusHandler:updateCheckStatusCompletion]; + self.cancellation = cancellation; self.checkingController = [[SUStatusController alloc] initWithHost:self.host]; [[self.checkingController window] center]; // Force the checking controller to load its window. @@ -248,7 +252,10 @@ - (void)cancelCheckForUpdates:(id)__unused sender { - [self.coreComponent cancelUpdateCheckStatus]; + if (self.cancellation != nil) { + self.cancellation(); + self.cancellation = nil; + } [self closeCheckingWindow]; } @@ -256,7 +263,7 @@ { assert(NSThread.isMainThread); - [self.coreComponent completeUpdateCheckStatus]; + self.cancellation = nil; [self closeCheckingWindow]; } @@ -266,28 +273,24 @@ { assert(NSThread.isMainThread); - [self.coreComponent registerAcknowledgement:acknowledgement]; - NSAlert *alert = [[NSAlert alloc] init]; alert.messageText = SULocalizedString(@"Update Error!", nil); alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]]; [alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)]; [self showAlert:alert]; - [self.coreComponent acceptAcknowledgement]; + acknowledgement(); } - (void)showUpdateNotFoundWithError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement { assert(NSThread.isMainThread); - [self.coreComponent registerAcknowledgement:acknowledgement]; - NSAlert *alert = [NSAlert alertWithError:error]; alert.alertStyle = NSAlertStyleInformational; [self showAlert:alert]; - [self.coreComponent acceptAcknowledgement]; + acknowledgement(); } - (void)showAlert:(NSAlert *)alert @@ -320,11 +323,11 @@ } } -- (void)showDownloadInitiatedWithCompletion:(void (^)(SPUDownloadUpdateStatus))downloadUpdateStatusCompletion +- (void)showDownloadInitiatedWithCancellation:(void (^)(void))cancellation { assert(NSThread.isMainThread); - [self.coreComponent registerDownloadStatusHandler:downloadUpdateStatusCompletion]; + self.cancellation = cancellation; [self showStatusController]; [self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; @@ -333,7 +336,10 @@ - (void)cancelDownload:(id)__unused sender { - [self.coreComponent cancelDownloadStatus]; + if (self.cancellation != nil) { + self.cancellation(); + self.cancellation = nil; + } } - (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength @@ -395,7 +401,7 @@ { assert(NSThread.isMainThread); - [self.coreComponent completeDownloadStatus]; + self.cancellation = nil; [self showStatusController]; [self.statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; @@ -426,8 +432,7 @@ assert(NSThread.isMainThread); // Deciding not to show anything here - [self.coreComponent registerAcknowledgement:acknowledgement]; - [self.coreComponent acceptAcknowledgement]; + acknowledgement(); } #pragma mark Aborting Everything @@ -447,7 +452,8 @@ { assert(NSThread.isMainThread); - [self.coreComponent dismissUpdateInstallation]; + self.installUpdateHandler = nil; + self.cancellation = nil; [self closeCheckingWindow]; diff --git a/Sparkle/SPUStatusCompletionResults.h b/Sparkle/SPUStatusCompletionResults.h index 38d5a6a4..0283c119 100644 --- a/Sparkle/SPUStatusCompletionResults.h +++ b/Sparkle/SPUStatusCompletionResults.h @@ -18,16 +18,6 @@ #import #endif -typedef NS_ENUM(NSUInteger, SPUUserInitiatedCheckStatus) { - SPUUserInitiatedCheckDone, - SPUUserInitiatedCheckCanceled -}; - -typedef NS_ENUM(NSUInteger, SPUDownloadUpdateStatus) { - SPUDownloadUpdateDone, - 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 */ diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 989d3611..d361509c 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -201,21 +201,32 @@ - (void)downloadDriverWillBeginDownload { - [self.userDriver showDownloadInitiatedWithCompletion:^(SPUDownloadUpdateStatus downloadCompletionStatus) { - switch (downloadCompletionStatus) { - case SPUDownloadUpdateDone: - 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; - } - }]; + 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" + [self.userDriver showDownloadInitiatedWithCompletion:^(SPUDownloadUpdateStatus downloadCompletionStatus) { + switch (downloadCompletionStatus) { +#pragma clang diagnostic pop + case SPUDownloadUpdateDone: + break; + case SPUDownloadUpdateCanceled: + cancelDownload(); + break; + } + }]; + } } - (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index c4fe937c..2971837e 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -310,12 +310,14 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification __weak SPUUpdater *weakSelf = self; [self.userDriver showUpdatePermissionRequest:updatePermissionRequest reply:^(SUUpdatePermissionResponse *response) { - SPUUpdater *strongSelf = weakSelf; - if (strongSelf != nil) { - [strongSelf updatePermissionRequestFinishedWithResponse:response]; - // Schedule checks, but make sure we ignore the delayed call from KVO - [strongSelf resetUpdateCycle]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + SPUUpdater *strongSelf = weakSelf; + if (strongSelf != nil) { + [strongSelf updatePermissionRequestFinishedWithResponse:response]; + // Schedule checks, but make sure we ignore the delayed call from KVO + [strongSelf resetUpdateCycle]; + } + }); }]; // We start the update checks and register as observer for changes after the prompt finishes diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 31c6e7e3..00391c4a 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -28,18 +28,7 @@ NS_ASSUME_NONNULL_BEGIN This protocol is used for implementing a user interface for the Sparkle updater. Sparkle's internal drivers tell an object that implements this protocol what actions to take and show to the user. - Every method in this protocol is required (i.e, not optional) and has a void return type and can optionally take a single parameter block, which waits for - a response back from the user driver. Note that every parameter block, or reply, *must* be responded to eventually - - that is, none can be ignored. Furthermore, they can only be replied to *once* - a reply or completion block should be considered - invalidated after it's once used. The faster a reply can be made, the more Sparkle may be able to idle, and so the better. Every method in this protocol can be assumed to be called from the main thread. - - It may be possible for an action that says to invalidate or dismiss something to be called multiple times in succession, and the implementor may choose to ignore further requests. (TODO: This should be verified if this actually can happen in practice). - - Note: Once upon a time, when first developing the user driver API, I had the user driver exist in a separate process from the rest of the framework (this is no longer supported). - If you're familiar with how the higher level XPC APIs work, this explains why some of the decisions above were made - (reply block executed on any thread, reply block replied only once, single reply block, void return types, idleness, no optional methods, ...) - This is somewhat of an artifact now, but I think most of these set of restrictions still enforces a well designed API. */ SU_EXPORT @protocol SPUUserDriver @@ -66,17 +55,15 @@ SU_EXPORT @protocol SPUUserDriver * * 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 indicating whether the initiated update check is done or canceled. - * Attempts to canceling can be made before -dismissUserInitiatedUpdateCheck is invoked. Replying with SPUUserInitiatedCheckDone - * on the other hand should not be done until -dismissUserInitiatedUpdateCheck is invoked. + * @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 * * Dismiss whatever was started in -showUserInitiatedUpdateCheckWithCompletion: - * This is an appropriate time to reply with SPUUserInitiatedCheckDone if not having done so already */ - (void)dismissUserInitiatedUpdateCheck; @@ -192,12 +179,9 @@ SU_EXPORT @protocol SPUUserDriver * * 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. - * A reply of SPUDownloadUpdateDone signifies that the download is done, which should not be invoked until - * -showDownloadDidStartExtractingUpdate + * @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 @@ -219,7 +203,6 @@ SU_EXPORT @protocol SPUUserDriver /*! * Show the user that the update finished downloading and started extracting * - * This is an appropriate time to reply with SPUDownloadUpdateDone if not done so already * Sparkle uses this to show an indeterminate progress bar. * * Note that an update can resume at this point after having been downloaded before, @@ -283,16 +266,25 @@ SU_EXPORT @protocol SPUUserDriver /*! * 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 diff --git a/Sparkle/SPUUserDriverCoreComponent.h b/Sparkle/SPUUserDriverCoreComponent.h deleted file mode 100644 index 4ccfdab3..00000000 --- a/Sparkle/SPUUserDriverCoreComponent.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// SUUserDriverCoreComponent.h -// Sparkle -// -// Created by Mayur Pawashe on 3/4/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#if __has_feature(modules) -#if __has_warning("-Watimport-in-framework-header") -#pragma clang diagnostic ignored "-Watimport-in-framework-header" -#endif -@import Foundation; -#else -#import -#endif -#import "SPUStatusCompletionResults.h" -#import "SUExport.h" - -@protocol SPUStandardUserDriverDelegate; - -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)registerAcknowledgement:(void (^)(void))acknowledgement; -- (void)acceptAcknowledgement; - -- (void)dismissUpdateInstallation; - -@end diff --git a/Sparkle/SPUUserDriverCoreComponent.m b/Sparkle/SPUUserDriverCoreComponent.m deleted file mode 100644 index b9f8db91..00000000 --- a/Sparkle/SPUUserDriverCoreComponent.m +++ /dev/null @@ -1,124 +0,0 @@ -// -// SUUserDriverCoreComponent.m -// Sparkle -// -// Created by Mayur Pawashe on 3/4/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import "SPUUserDriverCoreComponent.h" - - -#include "AppKitPrevention.h" - -@interface SPUUserDriverCoreComponent () - -@property (nonatomic, copy) void (^installUpdateHandler)(SPUInstallUpdateStatus); -@property (nonatomic, copy) void (^updateCheckStatusCompletion)(SPUUserInitiatedCheckStatus); -@property (nonatomic, copy) void (^downloadStatusCompletion)(SPUDownloadUpdateStatus); -@property (nonatomic, copy) void (^acknowledgement)(void); - -@end - -@implementation SPUUserDriverCoreComponent - -@synthesize installUpdateHandler = _installUpdateHandler; -@synthesize updateCheckStatusCompletion = _updateCheckStatusCompletion; -@synthesize downloadStatusCompletion = _downloadStatusCompletion; -@synthesize acknowledgement = _acknowledgement; - -#pragma mark Install Updates - -- (void)registerInstallUpdateHandler:(void (^)(SPUInstallUpdateStatus))installUpdateHandler -{ - self.installUpdateHandler = installUpdateHandler; -} - -- (void)installUpdateWithChoice:(SPUInstallUpdateStatus)choice -{ - if (self.installUpdateHandler != nil) { - self.installUpdateHandler(choice); - self.installUpdateHandler = nil; - } -} - -- (void)dismissInstallAndRestart -{ - if (self.installUpdateHandler != nil) { - self.installUpdateHandler(SPUDismissUpdateInstallation); - self.installUpdateHandler = nil; - } -} - -#pragma mark Update Check Status - -- (void)registerUpdateCheckStatusHandler:(void (^)(SPUUserInitiatedCheckStatus))updateCheckStatusCompletion -{ - self.updateCheckStatusCompletion = updateCheckStatusCompletion; -} - -- (void)cancelUpdateCheckStatus -{ - if (self.updateCheckStatusCompletion != nil) { - self.updateCheckStatusCompletion(SPUUserInitiatedCheckCanceled); - self.updateCheckStatusCompletion = nil; - } -} - -- (void)completeUpdateCheckStatus -{ - if (self.updateCheckStatusCompletion != nil) { - self.updateCheckStatusCompletion(SPUUserInitiatedCheckDone); - 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 -{ - if (self.downloadStatusCompletion != nil) { - self.downloadStatusCompletion(SPUDownloadUpdateDone); - self.downloadStatusCompletion = nil; - } -} - -#pragma mark Simple Acknoledgments - -- (void)registerAcknowledgement:(void (^)(void))acknowledgement -{ - self.acknowledgement = acknowledgement; -} - -- (void)acceptAcknowledgement -{ - if (self.acknowledgement != nil) { - self.acknowledgement(); - self.acknowledgement = nil; - } -} - -#pragma mark Aborting Everything - -- (void)dismissUpdateInstallation -{ - [self acceptAcknowledgement]; - [self cancelUpdateCheckStatus]; - [self cancelDownloadStatus]; - [self dismissInstallAndRestart]; -} - -@end diff --git a/Sparkle/SPUUserInitiatedUpdateDriver.m b/Sparkle/SPUUserInitiatedUpdateDriver.m index dd1b0064..5bcdaa28 100644 --- a/Sparkle/SPUUserInitiatedUpdateDriver.m +++ b/Sparkle/SPUUserInitiatedUpdateDriver.m @@ -50,19 +50,30 @@ } else { self.showingUserInitiatedProgress = YES; - [self.userDriver showUserInitiatedUpdateCheckWithCompletion:^(SPUUserInitiatedCheckStatus completionStatus) { - switch (completionStatus) { - case SPUUserInitiatedCheckDone: - break; - case SPUUserInitiatedCheckCanceled: - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.showingUserInitiatedProgress) { - [self abortUpdate]; - } - }); - break; - } - }]; + 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" + [self.userDriver showUserInitiatedUpdateCheckWithCompletion:^(SPUUserInitiatedCheckStatus completionStatus) { +#pragma clang diagnostic pop + switch (completionStatus) { + case SPUUserInitiatedCheckDone: + break; + case SPUUserInitiatedCheckCanceled: + cancelUpdateCheck(); + break; + } + }]; + } [self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:NO includesSkippedUpdates:YES]; } diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index a3ec078f..8ec3e01e 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -32,7 +32,6 @@ #import "SPUUserDriver.h" #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" -#import "SPUUserDriverCoreComponent.h" #import "SPUDownloadData.h" #import "SUUpdater.h" // deprecated diff --git a/Sparkle/SparkleCore.h b/Sparkle/SparkleCore.h index 5d3521e7..118672aa 100644 --- a/Sparkle/SparkleCore.h +++ b/Sparkle/SparkleCore.h @@ -29,7 +29,6 @@ #import "SPUUpdatePermissionRequest.h" #import "SUUpdatePermissionResponse.h" #import "SPUUserDriver.h" -#import "SPUUserDriverCoreComponent.h" #import "SPUDownloadData.h" #pragma clang diagnostic pop diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index d49fcb43..46d58477 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -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]; } diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 4f9c2c90..2ca61bdf 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -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))