mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-30 05:28:50 +00:00
Improve logic for allowing installer interaction
We now distinguish between the updater delegate allowing interaction and the update driver allowing interaction. We also remove an interaction allowed flag from the AppInstaller, letting shouldShowUI flag suffice.
This commit is contained in:
1 parent
f9e2609fa1
commit
646ed6f3c4
8 files changed
+28
-34
No files matched your search
@@ -11,7 +11,7 @@
|
||||
|
||||
@interface AppInstaller : NSObject <SUUnarchiverDelegate>
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier allowingInteraction:(BOOL)allowsInteraction;
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier;
|
||||
|
||||
- (void)start;
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
@property (nonatomic, strong) TerminationListener *terminationListener;
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *hostBundleIdentifier;
|
||||
@property (nonatomic, readonly) BOOL allowsInteraction;
|
||||
@property (nonatomic) SUHost *host;
|
||||
@property (nonatomic) SUInstallationInputData *installationData;
|
||||
@property (nonatomic, assign) BOOL shouldRelaunch;
|
||||
@@ -87,7 +86,6 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
@synthesize agentConnection = _agentConnection;
|
||||
@synthesize receivedUpdaterPong = _receivedUpdaterPong;
|
||||
@synthesize hostBundleIdentifier = _hostBundleIdentifier;
|
||||
@synthesize allowsInteraction = _allowsInteraction;
|
||||
@synthesize terminationListener = _terminationListener;
|
||||
@synthesize host = _host;
|
||||
@synthesize installationData = _installationData;
|
||||
@@ -102,7 +100,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
@synthesize performedStage3Installation = _performedStage3Installation;
|
||||
@synthesize agentConnectionCounter = _agentConnectionCounter;
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier allowingInteraction:(BOOL)allowsInteraction
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
@@ -110,8 +108,6 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
_hostBundleIdentifier = [hostBundleIdentifier copy];
|
||||
|
||||
_allowsInteraction = allowsInteraction;
|
||||
|
||||
_xpcListener = [[NSXPCListener alloc] initWithMachServiceName:SUInstallerServiceNameForBundleIdentifier(hostBundleIdentifier)];
|
||||
_xpcListener.delegate = self;
|
||||
|
||||
@@ -443,7 +439,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
NSError *installerError = nil;
|
||||
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationData.installationType updateDirectory:self.installationData.updateDirectoryPath allowingInteraction:self.allowsInteraction versionComparator:[SUStandardVersionComparator standardVersionComparator] error:&installerError];
|
||||
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationData.installationType updateDirectory:self.installationData.updateDirectoryPath versionComparator:[SUStandardVersionComparator standardVersionComparator] error:&installerError];
|
||||
|
||||
if (installer == nil) {
|
||||
SULog(@"Error: Failed to create installer instance with error: %@", installerError);
|
||||
|
||||
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUInstaller : NSObject
|
||||
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory allowingInteraction:(BOOL)allowsInteraction versionComparator:(id <SUVersionComparison>)comparator error:(NSError **)error;
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory versionComparator:(id <SUVersionComparison>)comparator error:(NSError **)error;
|
||||
|
||||
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory allowingInteraction:(BOOL)allowsInteraction versionComparator:(id <SUVersionComparison>)comparator error:(NSError * __autoreleasing *)error
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory versionComparator:(id <SUVersionComparison>)comparator error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
BOOL isGuided = NO;
|
||||
@@ -144,14 +144,7 @@
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found package installer but '%@=%@' was probably missing in the appcast item enclosure", SUAppcastAttributeInstallationType, SUInstallationTypePackage] }];
|
||||
}
|
||||
} else {
|
||||
#warning review this
|
||||
// Even if we expect an ordinary package, if we don't allow interaction (eg: because we're already running root) -
|
||||
// we should try a guided installation instead - because an ordinary package installation may not work well
|
||||
if (allowsInteraction) {
|
||||
installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath];
|
||||
} else {
|
||||
installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath];
|
||||
}
|
||||
installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath];
|
||||
}
|
||||
} else {
|
||||
if (![expectedInstallationType isEqualToString:SUInstallationTypeApplication]) {
|
||||
|
||||
+2
-3
@@ -6,14 +6,13 @@ int main(int __unused argc, const char __unused *argv[])
|
||||
@autoreleasepool
|
||||
{
|
||||
NSArray<NSString *> *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count != 3) {
|
||||
if (args.count != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
NSString *hostBundleIdentifier = args[1];
|
||||
BOOL allowsInteraction = args[2].boolValue;
|
||||
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier allowingInteraction:allowsInteraction];
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier];
|
||||
[appInstaller start];
|
||||
|
||||
// Ignore SIGTERM because we are going to catch it ourselves
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
return (submittedJob == true);
|
||||
}
|
||||
|
||||
- (SUAuthorizationReply)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle authorizationPrompt:(NSString *)authorizationPrompt allowingInteraction:(BOOL)allowingInteraction inSystemDomain:(BOOL)systemDomain
|
||||
- (SUAuthorizationReply)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain
|
||||
{
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
NSString *hostBundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
NSArray<NSString *> *arguments = @[installerPath, hostBundleIdentifier, @(allowingInteraction).stringValue];
|
||||
NSArray<NSString *> *arguments = @[installerPath, hostBundleIdentifier];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus createStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
|
||||
@@ -260,7 +260,7 @@
|
||||
return reply;
|
||||
}
|
||||
|
||||
- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler
|
||||
- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUAuthorizationReply))completionHandler
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath];
|
||||
@@ -268,14 +268,12 @@
|
||||
BOOL needsSystemAuthorization = SUNeedsSystemAuthorizationAccess(hostBundlePath, installationType);
|
||||
|
||||
// if we need to use the system domain and we aren't allowed interaction, then try sometime later when interaction is allowed
|
||||
if (needsSystemAuthorization && !allowingInteraction) {
|
||||
if (needsSystemAuthorization && !allowingUpdaterInteraction) {
|
||||
completionHandler(SUAuthorizationReplyFailure);
|
||||
} else if (needsSystemAuthorization && !allowingDriverInteraction) {
|
||||
completionHandler(SUAuthorizationReplyAuthorizeLater);
|
||||
} else {
|
||||
SUAuthorizationReply installerReply = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle authorizationPrompt:authorizationPrompt allowingInteraction:allowingInteraction inSystemDomain:needsSystemAuthorization];
|
||||
|
||||
if (installerReply == SUAuthorizationReplyFailure) {
|
||||
SULog(@"Failed to submit installer job");
|
||||
}
|
||||
SUAuthorizationReply installerReply = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle authorizationPrompt:authorizationPrompt inSystemDomain:needsSystemAuthorization];
|
||||
|
||||
BOOL submittedProgressTool = NO;
|
||||
if (installerReply == SUAuthorizationReplySuccess) {
|
||||
@@ -284,6 +282,8 @@
|
||||
if (!submittedProgressTool) {
|
||||
SULog(@"Failed to submit progress tool job");
|
||||
}
|
||||
} else if (installerReply == SUAuthorizationReplyFailure) {
|
||||
SULog(@"Failed to submit installer job");
|
||||
}
|
||||
|
||||
if (installerReply == SUAuthorizationReplyCanceled) {
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
|
||||
@protocol SUInstallerLauncherProtocol
|
||||
|
||||
- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler;
|
||||
- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUAuthorizationReply))completionHandler;
|
||||
|
||||
@end
|
||||
Vendored
+10
-4
@@ -416,12 +416,17 @@
|
||||
installerLauncher = launcherConnection.remoteObjectProxy;
|
||||
}
|
||||
|
||||
#warning review this...
|
||||
BOOL shouldAllowInstallerInteraction = !silently;
|
||||
// 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:)]) {
|
||||
shouldAllowInstallerInteraction = [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater];
|
||||
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;
|
||||
|
||||
NSString *hostBundlePath = self.host.bundle.bundlePath;
|
||||
assert(hostBundlePath != nil);
|
||||
|
||||
@@ -430,13 +435,14 @@
|
||||
|
||||
// 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 launchInstallerAtPath:relaunchToolPath progressToolPath:progressToolPath withHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingInteraction:shouldAllowInstallerInteraction completion:^(SUAuthorizationReply result) {
|
||||
[installerLauncher launchInstallerAtPath:relaunchToolPath progressToolPath:progressToolPath withHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:updaterAllowsInteraction completion:^(SUAuthorizationReply result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
retrievedLaunchStatus = YES;
|
||||
[launcherConnection invalidate];
|
||||
|
||||
switch (result) {
|
||||
case SUAuthorizationReplyFailure:
|
||||
SULog(@"Error: Failed to gain authorization required to update target");
|
||||
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while launching the installer. Please try again later.", nil) }]);
|
||||
break;
|
||||
case SUAuthorizationReplyCanceled:
|
||||
|
||||
Reference in new issue
Block a user