mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Don't check or download updates if updater isn't allowed interaction
This only affects updater delegates that return NO from -updaterShouldAllowInstallerInteraction: This improves the user experience in sparkle-cli where now the checking can be aborted before even downloading the update feed, if it knows ahead of time that installation will fail.
This commit is contained in:
1 parent
7dd066d894
commit
47f08be1a0
15 files changed
+211
-29
No files matched your search
@@ -378,4 +378,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL))reply
|
||||
{
|
||||
// No need to execute on main queue
|
||||
reply(SPUNeedsSystemAuthorizationAccess(hostBundlePath, SPUInstallationTypeApplication));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -12,5 +12,7 @@
|
||||
@protocol SUInstallerLauncherProtocol
|
||||
|
||||
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus))completionHandler;
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL requiresAuthorization))reply;
|
||||
|
||||
@end
|
||||
Vendored
+9
-1
@@ -55,7 +55,15 @@
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO requiresSilentInstall:YES completion:completionBlock];
|
||||
[self.coreDriver prepareCheckForUpdatesWithCompletion:completionBlock];
|
||||
|
||||
[self.coreDriver preflightForUpdatePermissionWithReply:^(NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
[self abortUpdateWithError:error];
|
||||
} else {
|
||||
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO requiresSilentInstall:YES];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)__unused completionBlock __attribute__((noreturn))
|
||||
|
||||
Vendored
+3
-1
@@ -30,7 +30,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id <SUBasicUpdateDriverDelegate>)delegate;
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock;
|
||||
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock;
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates;
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
|
||||
|
||||
|
||||
Vendored
+5
-2
@@ -60,10 +60,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock
|
||||
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
self.completionBlock = completionBlock;
|
||||
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates
|
||||
{
|
||||
if ([self.host isRunningOnReadOnlyVolume])
|
||||
{
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [self.host name]] }]];
|
||||
|
||||
Vendored
+5
-1
@@ -51,7 +51,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id<SUCoreBasedUpdateDriverDelegate>)delegate;
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall completion:(SUUpdateDriverCompletion)completionBlock;
|
||||
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock;
|
||||
|
||||
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply;
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall;
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
|
||||
|
||||
|
||||
Vendored
+48
-4
@@ -15,6 +15,9 @@
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUDownloadedUpdate.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SULocalizations.h"
|
||||
#import "SPUInstallationType.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -72,12 +75,38 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall completion:(SUUpdateDriverCompletion)completionBlock
|
||||
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.basicDriver prepareCheckForUpdatesWithCompletion:completionBlock];
|
||||
}
|
||||
|
||||
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply
|
||||
{
|
||||
// If we don't allow interaction, make sure we have sufficient privileges to update
|
||||
// If we don't, then we should abort early before trying to check for updates
|
||||
// Note if we don't have permission to update an application update without interaction,
|
||||
// then we won't have permission for package type of updates either (converse is not true)
|
||||
if (![self.updaterDelegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)] || [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater]) {
|
||||
// Simple case where installer interaction is allowed
|
||||
reply(nil);
|
||||
} else {
|
||||
// Otherwise check if we have sufficient privileges to update without interaction
|
||||
[self.installerDriver checkIfApplicationInstallationRequiresAuthorizationWithReply:^(BOOL requiresAuthorization) {
|
||||
if (requiresAuthorization) {
|
||||
reply([NSError errorWithDomain:SUSparkleErrorDomain code:SUNotAllowedInteractionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"No new update has been checked because the installation will require interaction, which has been prevented.", nil)] }]);
|
||||
} else {
|
||||
reply(nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall
|
||||
{
|
||||
self.userAgent = userAgent;
|
||||
self.silentInstall = silentInstall;
|
||||
|
||||
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates completion:completionBlock];
|
||||
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
@@ -93,6 +122,9 @@
|
||||
self.downloadedUpdate = downloadedUpdate;
|
||||
self.silentInstall = NO;
|
||||
|
||||
// Note if installer interaction isn't allowed, we shouldn't have downloaded the update, and shouldn't be able to get here
|
||||
// So no need to do a test if we can perform an update without authorization
|
||||
|
||||
[self.basicDriver resumeDownloadedUpdate:downloadedUpdate completion:completionBlock];
|
||||
}
|
||||
|
||||
@@ -109,9 +141,21 @@
|
||||
|
||||
if (self.resumingInstallingUpdate) {
|
||||
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
} else {
|
||||
if (![self.updaterDelegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)] || [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater]) {
|
||||
// Simple case - delegate allows interaction, so we should continue along
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
} else {
|
||||
// Package type installations will always require installer interaction as long as we don't support running as root
|
||||
// If it's not a package type installation, we should be okay since we did an auth check before checking for updates above
|
||||
if (![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) {
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNotAllowedInteractionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"A new update is available but cannot be installed because interaction has been prevented.", nil)] }]];
|
||||
} else {
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
|
||||
}
|
||||
|
||||
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem
|
||||
|
||||
Vendored
+2
-1
@@ -55,7 +55,8 @@ typedef NS_ENUM(OSStatus, SUError) {
|
||||
SUInstallationError = 4005,
|
||||
SUDowngradeError = 4006,
|
||||
SUInstallationCanceledError = 4007,
|
||||
SUInstallationAuthorizeLaterError = 4008
|
||||
SUInstallationAuthorizeLaterError = 4008,
|
||||
SUNotAllowedInteractionError = 4009
|
||||
};
|
||||
|
||||
#endif
|
||||
Vendored
+2
@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem;
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithReply:(void (^)(BOOL requiresAuthorization))reply;
|
||||
|
||||
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently completion:(void (^)(NSError * _Nullable))completionHandler;
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
|
||||
|
||||
Vendored
+57
@@ -24,6 +24,7 @@
|
||||
#import "SUInstallerConnectionProtocol.h"
|
||||
#import "SUXPCInstallerConnection.h"
|
||||
#import "SUDownloadedUpdate.h"
|
||||
#import "SPUInstallationType.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -305,6 +306,62 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithReply:(void (^)(BOOL requiresAuthorization))reply
|
||||
{
|
||||
id<SUInstallerLauncherProtocol> installerLauncher = nil;
|
||||
__block BOOL madeReply = NO;
|
||||
NSXPCConnection *launcherConnection = nil;
|
||||
|
||||
if (!SPUXPCServiceExists(@INSTALLER_LAUNCHER_BUNDLE_ID)) {
|
||||
installerLauncher = [[SUInstallerLauncher alloc] init];
|
||||
} else {
|
||||
launcherConnection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_LAUNCHER_BUNDLE_ID];
|
||||
launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
[launcherConnection resume];
|
||||
|
||||
launcherConnection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!madeReply) {
|
||||
// We'll break the retain cycle in the invalidation handler
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
||||
[launcherConnection invalidate];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
launcherConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!madeReply) {
|
||||
// If something went horribly wrong, just guess that we won't require authorization
|
||||
reply(NO);
|
||||
|
||||
// Break the retain cycle
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
||||
launcherConnection.interruptionHandler = nil;
|
||||
launcherConnection.invalidationHandler = nil;
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
installerLauncher = launcherConnection.remoteObjectProxy;
|
||||
}
|
||||
|
||||
[installerLauncher checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:self.host.bundlePath reply:^(BOOL requiresAuthorization) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!madeReply) {
|
||||
madeReply = YES;
|
||||
[launcherConnection invalidate];
|
||||
|
||||
reply(requiresAuthorization);
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)launchAutoUpdateSilently:(BOOL)silently completion:(void (^)(NSError *_Nullable))completionHandler
|
||||
{
|
||||
id<SUInstallerLauncherProtocol> installerLauncher = nil;
|
||||
|
||||
Vendored
+5
-1
@@ -36,7 +36,11 @@
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO completion:completionBlock];
|
||||
// We don't preflight for update permission in this driver because we are just interested if an update is available
|
||||
|
||||
[self.basicDriver prepareCheckForUpdatesWithCompletion:completionBlock];
|
||||
|
||||
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
|
||||
Vendored
+16
-1
@@ -37,7 +37,16 @@
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO completion:completionBlock];
|
||||
[self.uiDriver prepareCheckForUpdatesWithCompletion:completionBlock];
|
||||
|
||||
[self.uiDriver preflightForUpdatePermissionWithReply:^(NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
// Don't tell the user about the permission error for scheduled update checks
|
||||
[self abortUpdateWithError:nil];
|
||||
} else {
|
||||
[self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:YES];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
@@ -56,6 +65,12 @@
|
||||
[self abortUpdateWithError:nil];
|
||||
}
|
||||
|
||||
- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)__unused error
|
||||
{
|
||||
// Don't tell the user that a non-UI update error occurred for scheduled update checks
|
||||
[self abortUpdateWithError:nil];
|
||||
}
|
||||
|
||||
- (void)uiDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:error];
|
||||
|
||||
Vendored
+6
-1
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol SUUIBasedUpdateDriverDelegate <NSObject>
|
||||
|
||||
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
|
||||
- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
|
||||
- (void)uiDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
|
||||
|
||||
@optional
|
||||
@@ -29,7 +30,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id<SUUIBasedUpdateDriverDelegate>)delegate;
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock;
|
||||
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock;
|
||||
|
||||
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply;
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates;
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
|
||||
|
||||
|
||||
Vendored
+14
-3
@@ -60,9 +60,19 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock
|
||||
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates requiresSilentInstall:NO completion:completionBlock];
|
||||
[self.coreDriver prepareCheckForUpdatesWithCompletion:completionBlock];
|
||||
}
|
||||
|
||||
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply
|
||||
{
|
||||
[self.coreDriver preflightForUpdatePermissionWithReply:reply];
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates
|
||||
{
|
||||
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates requiresSilentInstall:NO];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
@@ -228,7 +238,8 @@
|
||||
|
||||
- (void)coreDriverIsRequestingAbortUpdateWithError:(NSError *)error
|
||||
{
|
||||
[self.delegate uiDriverIsRequestingAbortUpdateWithError:error];
|
||||
// A delegate may want to handle this type of error specially
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(nullable NSError *)error
|
||||
|
||||
+31
-13
@@ -19,6 +19,7 @@
|
||||
@property (nonatomic, readonly) SUUIBasedUpdateDriver *uiDriver;
|
||||
@property (nonatomic, readonly) id<SPUUserDriver> userDriver;
|
||||
@property (nonatomic) BOOL showingUserInitiatedProgress;
|
||||
@property (nonatomic) BOOL aborted;
|
||||
|
||||
@end
|
||||
|
||||
@@ -27,6 +28,7 @@
|
||||
@synthesize uiDriver = _uiDriver;
|
||||
@synthesize userDriver = _userDriver;
|
||||
@synthesize showingUserInitiatedProgress = _showingUserInitiatedProgress;
|
||||
@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
|
||||
{
|
||||
@@ -40,23 +42,33 @@
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
self.showingUserInitiatedProgress = YES;
|
||||
[self.uiDriver prepareCheckForUpdatesWithCompletion:completionBlock];
|
||||
|
||||
[self.userDriver showUserInitiatedUpdateCheckWithCompletion:^(SPUUserInitiatedCheckStatus completionStatus) {
|
||||
switch (completionStatus) {
|
||||
case SPUUserInitiatedCheckDone:
|
||||
break;
|
||||
case SPUUserInitiatedCheckCanceled:
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.showingUserInitiatedProgress) {
|
||||
[self abortUpdate];
|
||||
[self.uiDriver preflightForUpdatePermissionWithReply:^(NSError * _Nullable error) {
|
||||
if (!self.aborted) {
|
||||
if (error != nil) {
|
||||
[self abortUpdateWithError:error];
|
||||
} 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;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}];
|
||||
|
||||
[self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:YES];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
[self.uiDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:YES completion:completionBlock];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
|
||||
@@ -74,6 +86,11 @@
|
||||
[self abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)uiDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:error];
|
||||
@@ -98,6 +115,7 @@
|
||||
[self.userDriver dismissUserInitiatedUpdateCheck];
|
||||
self.showingUserInitiatedProgress = NO;
|
||||
}
|
||||
self.aborted = YES;
|
||||
[self.uiDriver abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user