diff --git a/InstallerLauncher/SUInstallerLauncher.m b/InstallerLauncher/SUInstallerLauncher.m index 1914d59a..e6ee1bd0 100644 --- a/InstallerLauncher/SUInstallerLauncher.m +++ b/InstallerLauncher/SUInstallerLauncher.m @@ -378,4 +378,10 @@ }); } +- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL))reply +{ + // No need to execute on main queue + reply(SPUNeedsSystemAuthorizationAccess(hostBundlePath, SPUInstallationTypeApplication)); +} + @end diff --git a/InstallerLauncher/SUInstallerLauncherProtocol.h b/InstallerLauncher/SUInstallerLauncherProtocol.h index e141be75..c3c03bce 100644 --- a/InstallerLauncher/SUInstallerLauncherProtocol.h +++ b/InstallerLauncher/SUInstallerLauncherProtocol.h @@ -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 diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index af26df29..55895793 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -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)) diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index f8bc1346..a20f99dc 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -30,7 +30,9 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithHost:(SUHost *)host updater:(id)updater updaterDelegate:(nullable id )updaterDelegate delegate:(id )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; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 02250f1c..df5f278c 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -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]] }]]; diff --git a/Sparkle/SUCoreBasedUpdateDriver.h b/Sparkle/SUCoreBasedUpdateDriver.h index 7f296316..ae4d7bb8 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.h +++ b/Sparkle/SUCoreBasedUpdateDriver.h @@ -51,7 +51,11 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id )updaterDelegate delegate:(id)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; diff --git a/Sparkle/SUCoreBasedUpdateDriver.m b/Sparkle/SUCoreBasedUpdateDriver.m index 9bd11d05..5579f3ba 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.m +++ b/Sparkle/SUCoreBasedUpdateDriver.m @@ -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 diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index aae5ca7b..c0fc4d06 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -55,7 +55,8 @@ typedef NS_ENUM(OSStatus, SUError) { SUInstallationError = 4005, SUDowngradeError = 4006, SUInstallationCanceledError = 4007, - SUInstallationAuthorizeLaterError = 4008 + SUInstallationAuthorizeLaterError = 4008, + SUNotAllowedInteractionError = 4009 }; #endif diff --git a/Sparkle/SUInstallerDriver.h b/Sparkle/SUInstallerDriver.h index ea435136..6bf69128 100644 --- a/Sparkle/SUInstallerDriver.h +++ b/Sparkle/SUInstallerDriver.h @@ -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; diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index bab49760..7869663e 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -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 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 installerLauncher = nil; diff --git a/Sparkle/SUProbingUpdateDriver.m b/Sparkle/SUProbingUpdateDriver.m index 40370e95..b7d5d578 100644 --- a/Sparkle/SUProbingUpdateDriver.m +++ b/Sparkle/SUProbingUpdateDriver.m @@ -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 diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 279d4acf..7c43b116 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -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]; diff --git a/Sparkle/SUUIBasedUpdateDriver.h b/Sparkle/SUUIBasedUpdateDriver.h index 2958292b..8ea8a435 100644 --- a/Sparkle/SUUIBasedUpdateDriver.h +++ b/Sparkle/SUUIBasedUpdateDriver.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SUUIBasedUpdateDriverDelegate - (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 )userDriver updaterDelegate:(nullable id )updaterDelegate delegate:(id)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; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index c094acbd..4e7b6d54 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -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 diff --git a/Sparkle/SUUserInitiatedUpdateDriver.m b/Sparkle/SUUserInitiatedUpdateDriver.m index c0848a79..105d4553 100644 --- a/Sparkle/SUUserInitiatedUpdateDriver.m +++ b/Sparkle/SUUserInitiatedUpdateDriver.m @@ -19,6 +19,7 @@ @property (nonatomic, readonly) SUUIBasedUpdateDriver *uiDriver; @property (nonatomic, readonly) id 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 )userDriver updaterDelegate:(nullable id )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]; }