Pass installer interaction flag to drivers and use delegate once

This commit is contained in:
Zorg committed 2016-08-21 15:14:47 -04:00
1 parent 55d58a2203
commit 6a8680464b
13 files changed
+42 -47

No files matched your search

+4 -1
View File
@@ -551,7 +551,10 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
} else if (self.resumableUpdate != nil) {
[self.driver resumeDownloadedUpdate:(SUDownloadedUpdate * _Nonnull)self.resumableUpdate completion:completionBlock];
} else {
[self.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[self userAgentString] httpHeaders:[self httpHeaders] completion:completionBlock];
BOOL allowsInstallerInteraction =
(![self.delegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)] || [self.delegate updaterShouldAllowInstallerInteraction:self]);
[self.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[self userAgentString] httpHeaders:[self httpHeaders] preventingInstallerInteraction:!allowsInstallerInteraction completion:completionBlock];
}
} else {
// I think this is really unlikely to occur but better be safe
+2 -2
View File
@@ -53,11 +53,11 @@
return self;
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders preventingInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(SUUpdateDriverCompletion)completionBlock
{
[self.coreDriver prepareCheckForUpdatesWithCompletion:completionBlock];
[self.coreDriver preflightForUpdatePermissionWithReply:^(NSError * _Nullable error) {
[self.coreDriver preflightForUpdatePermissionPreventingInstallerInteraction:preventsInstallerInteraction reply:^(NSError * _Nullable error) {
if (error != nil) {
[self abortUpdateWithError:error];
} else {
+1 -1
View File
@@ -187,7 +187,7 @@
} while(--finiteRecursion && errorToDisplay);
}
// Notify host app that update has aborted
// Notify host app that updater has aborted
if ([self.updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) {
[self.updaterDelegate updater:self.updater didAbortWithError:(NSError * _Nonnull)error];
}
+2 -2
View File
@@ -53,9 +53,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock;
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply;
- (void)preflightForUpdatePermissionPreventingInstallerInteraction:(BOOL)preventsInstallerInteraction reply:(void (^)(NSError * _Nullable))reply;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall;
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
+11 -6
View File
@@ -35,6 +35,7 @@
@property (nonatomic, readonly) SUHost *host;
@property (nonatomic) BOOL resumingInstallingUpdate;
@property (nonatomic) BOOL silentInstall;
@property (nonatomic) BOOL preventsInstallerInteraction;
@property (nonatomic, readonly, weak) id updater; // if we didn't have legacy support, I'd remove this..
@property (nullable, nonatomic, readonly, weak) id <SPUUpdaterDelegate>updaterDelegate;
@property (nonatomic) NSString *userAgent;
@@ -51,6 +52,7 @@
@synthesize host = _host;
@synthesize resumingInstallingUpdate = _resumingInstallingUpdate;
@synthesize silentInstall = _silentInstall;
@synthesize preventsInstallerInteraction = _preventsInstallerInteraction;
@synthesize updater = _updater;
@synthesize updaterDelegate = _updaterDelegate;
@synthesize userAgent = _userAgent;
@@ -80,14 +82,17 @@
[self.basicDriver prepareCheckForUpdatesWithCompletion:completionBlock];
}
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply
- (void)preflightForUpdatePermissionPreventingInstallerInteraction:(BOOL)preventsInstallerInteraction reply:(void (^)(NSError * _Nullable))reply
{
// Save for later
self.preventsInstallerInteraction = preventsInstallerInteraction;
// 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
if (!preventsInstallerInteraction) {
reply(nil);
} else {
// Otherwise check if we have sufficient privileges to update without interaction
@@ -101,7 +106,7 @@
}
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall
{
self.userAgent = userAgent;
self.silentInstall = silentInstall;
@@ -143,7 +148,7 @@
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem];
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
} else {
if (![self.updaterDelegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)] || [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater]) {
if (!self.preventsInstallerInteraction) {
// Simple case - delegate allows interaction, so we should continue along
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
} else {
@@ -216,7 +221,7 @@
[self.delegate coreDriverDidStartExtractingUpdate];
}
[self.installerDriver extractDownloadedUpdate:downloadedUpdate silently:self.silentInstall completion:^(NSError * _Nullable error) {
[self.installerDriver extractDownloadedUpdate:downloadedUpdate silently:self.silentInstall preventsInstallerInteraction:self.preventsInstallerInteraction completion:^(NSError * _Nullable error) {
if (error != nil) {
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
} else {
+1 -1
View File
@@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)checkIfApplicationInstallationRequiresAuthorizationWithReply:(void (^)(BOOL requiresAuthorization))reply;
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently completion:(void (^)(NSError * _Nullable))completionHandler;
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently preventsInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(void (^)(NSError * _Nullable))completionHandler;
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
+4 -11
View File
@@ -140,7 +140,7 @@
}
// This can be called multiple times (eg: if a delta update fails, this may be called again with a regular update item)
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently completion:(void (^)(NSError * _Nullable))completionHandler
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently preventsInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(void (^)(NSError * _Nullable))completionHandler
{
self.updateItem = downloadedUpdate.updateItem;
self.temporaryDirectory = downloadedUpdate.temporaryDirectory;
@@ -149,7 +149,7 @@
self.currentStage = SPUInstallerNotStarted;
if (self.installerConnection == nil) {
[self launchAutoUpdateSilently:silently completion:completionHandler];
[self launchAutoUpdateSilently:silently preventsInstallerInteraction:preventsInstallerInteraction completion:completionHandler];
} else {
// The Install tool is already alive; just send out installation input data again
[self sendInstallationData];
@@ -363,7 +363,7 @@
}];
}
- (void)launchAutoUpdateSilently:(BOOL)silently completion:(void (^)(NSError *_Nullable))completionHandler
- (void)launchAutoUpdateSilently:(BOOL)silently preventsInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(void (^)(NSError *_Nullable))completionHandler
{
id<SUInstallerLauncherProtocol> installerLauncher = nil;
__block BOOL retrievedLaunchStatus = NO;
@@ -410,13 +410,6 @@
installerLauncher = launcherConnection.remoteObjectProxy;
}
// This determines if our updater delegate allows interaction
// If the delegate disallows interaction, then the update cannot be continued
BOOL updaterAllowsInteraction = YES;
if ([self.updaterDelegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)]) {
updaterAllowsInteraction = [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater];
}
// Our driver (automatic or UI based) has a say if interaction is allowed as well
// An automatic driver may disallow interaction but the updater could try again later a UI based driver that does allow interaction
BOOL driverAllowsInteraction = !silently;
@@ -429,7 +422,7 @@
// The installer launcher could be in a XPC service, so we don't want to do localization in there
NSString *authorizationPrompt = [NSString stringWithFormat:SULocalizedString(@"%1$@ wants to update.", nil), self.host.name];
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:updaterAllowsInteraction completion:^(SUInstallerLauncherStatus result) {
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result) {
dispatch_async(dispatch_get_main_queue(), ^{
retrievedLaunchStatus = YES;
[launcherConnection invalidate];
+1 -1
View File
@@ -34,7 +34,7 @@
return self;
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders preventingInstallerInteraction:(BOOL)__unused preventsInstallerInteraction completion:(SUUpdateDriverCompletion)completionBlock
{
// We don't preflight for update permission in this driver because we are just interested if an update is available
+2 -2
View File
@@ -35,11 +35,11 @@
return self;
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders preventingInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(SUUpdateDriverCompletion)completionBlock
{
[self.uiDriver prepareCheckForUpdatesWithCompletion:completionBlock];
[self.uiDriver preflightForUpdatePermissionWithReply:^(NSError * _Nullable error) {
[self.uiDriver preflightForUpdatePermissionPreventingInstallerInteraction:preventsInstallerInteraction reply:^(NSError * _Nullable error) {
if (error != nil) {
// Don't tell the user about the permission error for scheduled update checks
[self abortUpdateWithError:nil];
+2 -2
View File
@@ -32,9 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)prepareCheckForUpdatesWithCompletion:(SUUpdateDriverCompletion)completionBlock;
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply;
- (void)preflightForUpdatePermissionPreventingInstallerInteraction:(BOOL)preventsInstallerInteraction reply:(void (^)(NSError * _Nullable))reply;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates;
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
+9 -15
View File
@@ -31,6 +31,7 @@
@property (nonatomic, readonly) id<SPUUserDriver> userDriver;
@property (nonatomic) BOOL resumingInstallingUpdate;
@property (nonatomic) BOOL resumingDownloadedUpdate;
@property (nonatomic) BOOL preventsInstallerInteraction;
@end
@@ -44,6 +45,7 @@
@synthesize delegate = _delegate;
@synthesize resumingInstallingUpdate = _resumingInstallingUpdate;
@synthesize resumingDownloadedUpdate = _resumingDownloadedUpdate;
@synthesize preventsInstallerInteraction = _preventsInstallerInteraction;
- (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
{
@@ -65,12 +67,14 @@
[self.coreDriver prepareCheckForUpdatesWithCompletion:completionBlock];
}
- (void)preflightForUpdatePermissionWithReply:(void (^)(NSError * _Nullable))reply
- (void)preflightForUpdatePermissionPreventingInstallerInteraction:(BOOL)preventsInstallerInteraction reply:(void (^)(NSError * _Nullable))reply
{
[self.coreDriver preflightForUpdatePermissionWithReply:reply];
self.preventsInstallerInteraction = preventsInstallerInteraction;
[self.coreDriver preflightForUpdatePermissionPreventingInstallerInteraction:preventsInstallerInteraction reply:reply];
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates
{
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates requiresSilentInstall:NO];
}
@@ -94,16 +98,6 @@
}
}
- (BOOL)canDisplayInstallerUserInterface
{
// Are we allowed to perform updates that may require interaction?
BOOL updaterAllowsInteraction = YES;
if ([self.updaterDelegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)]) {
updaterAllowsInteraction = [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater];
}
return updaterAllowsInteraction;
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
{
if (self.resumingDownloadedUpdate) {
@@ -145,7 +139,7 @@
[self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem reply:^(SPUInstallUpdateStatus choice) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
[self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:[self canDisplayInstallerUserInterface]];
[self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:!self.preventsInstallerInteraction];
});
}];
}
@@ -214,7 +208,7 @@
if (!willInstallImmediately) {
[self.userDriver showReadyToInstallAndRelaunch:^(SPUInstallUpdateStatus installUpdateStatus) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreDriver finishInstallationWithResponse:installUpdateStatus displayingUserInterface:[self canDisplayInstallerUserInterface]];
[self.coreDriver finishInstallationWithResponse:installUpdateStatus displayingUserInterface:!self.preventsInstallerInteraction];
});
}];
}
+1 -1
View File
@@ -14,7 +14,7 @@ typedef void (^SUUpdateDriverCompletion)(BOOL shouldShowUpdateImmediately, SUDow
@protocol SUUpdateDriver <NSObject>
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders preventingInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(SUUpdateDriverCompletion)completionBlock;
- (void)resumeInstallingUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
+2 -2
View File
@@ -40,11 +40,11 @@
return self;
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders preventingInstallerInteraction:(BOOL)preventsInstallerInteraction completion:(SUUpdateDriverCompletion)completionBlock
{
[self.uiDriver prepareCheckForUpdatesWithCompletion:completionBlock];
[self.uiDriver preflightForUpdatePermissionWithReply:^(NSError * _Nullable error) {
[self.uiDriver preflightForUpdatePermissionPreventingInstallerInteraction:preventsInstallerInteraction reply:^(NSError * _Nullable error) {
if (!self.aborted) {
if (error != nil) {
[self abortUpdateWithError:error];