mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
With JoinExistingSession, the agent doesn't need to submit the intaller ever
This commit is contained in:
1 parent
21ad358772
commit
a1d43997d9
6 files changed
+26
-336
No files matched your search
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// InstallerProgressLauncher.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/17/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol InstallerProgressLauncherDelegate <NSObject>
|
||||
|
||||
- (void)installerProgressLauncherDidInvalidate;
|
||||
- (void)installerProgressLauncherDidSubmitJob;
|
||||
|
||||
@end
|
||||
|
||||
@interface InstallerProgressLauncher : NSObject
|
||||
|
||||
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle installerPath:(NSString *)installerPath allowingInteraction:(BOOL)allowingInteraction delegate:(id<InstallerProgressLauncherDelegate>)delegate;
|
||||
|
||||
- (void)startListener;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,140 +0,0 @@
|
||||
//
|
||||
// InstallerProgressLauncher.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/17/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "InstallerProgressLauncher.h"
|
||||
#import "SUMessageTypes.h"
|
||||
#import "SUInstallerProgressLauncherProtocol.h"
|
||||
#import "SUSubmitInstaller.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#define REQUEST_AUTHORIZATION_TIMEOUT 7ull
|
||||
|
||||
@interface InstallerProgressLauncher () <NSXPCListenerDelegate>
|
||||
|
||||
@property (nonatomic) NSXPCListener *xpcListener;
|
||||
@property (nonatomic) NSXPCConnection *activeConnection;
|
||||
@property (nonatomic, readonly) NSBundle *hostBundle;
|
||||
@property (nonatomic, copy, readonly) NSString *installerPath;
|
||||
@property (nonatomic, readonly) BOOL allowsInteraction;
|
||||
@property (nonatomic, weak) id<InstallerProgressLauncherDelegate> delegate;
|
||||
@property (nonatomic) BOOL connected;
|
||||
|
||||
@end
|
||||
|
||||
@implementation InstallerProgressLauncher
|
||||
|
||||
@synthesize xpcListener = _xpcListener;
|
||||
@synthesize activeConnection = _activeConnection;
|
||||
@synthesize hostBundle = _hostBundle;
|
||||
@synthesize installerPath = _installerPath;
|
||||
@synthesize allowsInteraction = _allowsInteraction;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize connected = _connected;
|
||||
|
||||
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle installerPath:(NSString *)installerPath allowingInteraction:(BOOL)allowingInteraction delegate:(id<InstallerProgressLauncherDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
NSString *bundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(bundleIdentifier != nil);
|
||||
|
||||
_hostBundle = hostBundle;
|
||||
_installerPath = [installerPath copy];
|
||||
_allowsInteraction = allowingInteraction;
|
||||
_delegate = delegate;
|
||||
|
||||
_xpcListener = [[NSXPCListener alloc] initWithMachServiceName:SUProgressAgentLauncherServiceNameForBundleIdentifier(bundleIdentifier)];
|
||||
_xpcListener.delegate = self;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startListener
|
||||
{
|
||||
[self.xpcListener resume];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
// Declare local variable for the delegate, so that if the delegate invokes -invalidate, we won't be in an infinite recursion
|
||||
id<InstallerProgressLauncherDelegate> delegate = self.delegate;
|
||||
self.delegate = nil;
|
||||
[delegate installerProgressLauncherDidInvalidate];
|
||||
|
||||
[self.activeConnection invalidate];
|
||||
[self.xpcListener invalidate];
|
||||
|
||||
self.activeConnection = nil;
|
||||
self.xpcListener = nil;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)connection
|
||||
{
|
||||
if (self.activeConnection != nil) {
|
||||
SULog(@"Error: active connection for progress launcher already exists");
|
||||
[connection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerProgressLauncherProtocol)];
|
||||
connection.exportedObject = self;
|
||||
|
||||
self.activeConnection = connection;
|
||||
|
||||
__weak InstallerProgressLauncher *weakSelf = self;
|
||||
connection.interruptionHandler = ^{
|
||||
[weakSelf.activeConnection invalidate];
|
||||
};
|
||||
|
||||
connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
InstallerProgressLauncher *strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
strongSelf.activeConnection = nil;
|
||||
[strongSelf invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(REQUEST_AUTHORIZATION_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
SULog(@"Dispatch timeout invoked");
|
||||
if (!self.connected) {
|
||||
[self invalidate];
|
||||
}
|
||||
});
|
||||
|
||||
[connection resume];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)requestUserAuthorizationWithReply:(void (^)(SUAuthorizationReply))reply
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.connected = YES;
|
||||
|
||||
SUAuthorizationReply submissionReply = [SUSubmitInstaller submitInstallerAtPath:self.installerPath withHostBundle:self.hostBundle allowingInteraction:self.allowsInteraction inSystemDomain:YES];
|
||||
|
||||
if (submissionReply == SUAuthorizationReplyFailure) {
|
||||
SULog(@"Error: failed to submit installer in system domain");
|
||||
}
|
||||
|
||||
reply(submissionReply);
|
||||
|
||||
if (submissionReply == SUAuthorizationReplySuccess) {
|
||||
[self.delegate installerProgressLauncherDidSubmitJob];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)connectionDidInitiateWithReply:(void (^)(void))acknowledgement
|
||||
{
|
||||
acknowledgement();
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -12,21 +12,10 @@
|
||||
#import "SUMessageTypes.h"
|
||||
#import "SUSystemAuthorization.h"
|
||||
#import "SUSubmitInstaller.h"
|
||||
#import "SUInstallerProgressLauncherProtocol.h"
|
||||
|
||||
#define AUTHORIZATION_REPLY_TIMEOUT 7ull
|
||||
|
||||
@interface SUInstallerLauncher ()
|
||||
|
||||
@property (nonatomic, nullable) NSXPCConnection *activeConnection;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUInstallerLauncher
|
||||
|
||||
@synthesize activeConnection = _activeConnection;
|
||||
|
||||
- (BOOL)submitProgressToolAtPath:(NSString *)progressToolPath withHostBundle:(NSBundle *)hostBundle allowingInteraction:(BOOL)allowingInteraction installerPath:(NSString *)installerPath shouldSubmitInstaller:(BOOL)shouldSubmitInstaller
|
||||
- (BOOL)submitProgressToolAtPath:(NSString *)progressToolPath withHostBundle:(NSBundle *)hostBundle inSystemDomainForInstaller:(BOOL)inSystemDomainForInstaller
|
||||
{
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
|
||||
@@ -47,7 +36,7 @@
|
||||
NSString *hostBundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
NSArray<NSString *> *arguments = @[executablePath, hostBundlePath, @(allowingInteraction).stringValue, installerPath, @(shouldSubmitInstaller).stringValue];
|
||||
NSArray<NSString *> *arguments = @[executablePath, hostBundlePath, @(inSystemDomainForInstaller).stringValue];
|
||||
|
||||
#warning support running under system domain if updater is running as root - this means we would have to try running job under a different user
|
||||
CFStringRef domain = kSMDomainUserLaunchd;
|
||||
@@ -79,14 +68,7 @@
|
||||
jobDictionary[@"RunAtLoad"] = @NO;
|
||||
jobDictionary[@"NICE"] = @0;
|
||||
jobDictionary[@"LaunchOnlyOnce"] = @YES;
|
||||
|
||||
NSMutableDictionary *machServicesDictionary = [[NSMutableDictionary alloc] init];
|
||||
machServicesDictionary[SUStatusInfoServiceNameForBundleIdentifier(hostBundleIdentifier)] = @YES;
|
||||
if (shouldSubmitInstaller) {
|
||||
machServicesDictionary[SUProgressAgentLauncherServiceNameForBundleIdentifier(hostBundleIdentifier)] = @YES;
|
||||
}
|
||||
|
||||
jobDictionary[@"MachServices"] = [machServicesDictionary copy];
|
||||
jobDictionary[@"MachServices"] = @{SUStatusInfoServiceNameForBundleIdentifier(hostBundleIdentifier) : @YES};
|
||||
|
||||
CFErrorRef submitError = NULL;
|
||||
submittedJob = SMJobSubmit(domain, (__bridge CFDictionaryRef)(jobDictionary), auth, &submitError);
|
||||
@@ -103,90 +85,34 @@
|
||||
return (submittedJob == true);
|
||||
}
|
||||
|
||||
- (void)waitForProgressAgentWithHostBundle:(NSBundle *)hostBundle completion:(void (^)(SUAuthorizationReply))completionHandler
|
||||
{
|
||||
NSString *hostBundleIdentifier = hostBundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:SUProgressAgentLauncherServiceNameForBundleIdentifier(hostBundleIdentifier) options:(NSXPCConnectionOptions)0];
|
||||
|
||||
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerProgressLauncherProtocol)];
|
||||
|
||||
self.activeConnection = connection;
|
||||
|
||||
__weak SUInstallerLauncher *weakSelf = self;
|
||||
connection.interruptionHandler = ^{
|
||||
[weakSelf.activeConnection invalidate];
|
||||
};
|
||||
|
||||
__block BOOL invokedCompletion = NO;
|
||||
|
||||
connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!invokedCompletion) {
|
||||
invokedCompletion = YES;
|
||||
completionHandler(SUAuthorizationReplyFailure);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[connection resume];
|
||||
|
||||
id<SUInstallerProgressLauncherProtocol> launcher = connection.remoteObjectProxy;
|
||||
|
||||
__block BOOL intiatedConnection = NO;
|
||||
[launcher connectionDidInitiateWithReply:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
intiatedConnection = YES;
|
||||
|
||||
[launcher requestUserAuthorizationWithReply:^(SUAuthorizationReply reply) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!invokedCompletion) {
|
||||
invokedCompletion = YES;
|
||||
[weakSelf.activeConnection invalidate];
|
||||
completionHandler(reply);
|
||||
}
|
||||
});
|
||||
}];
|
||||
});
|
||||
}];
|
||||
|
||||
// If we initiated a connection, we can't time out because the user could just be taking a really long time to reply
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(AUTHORIZATION_REPLY_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!intiatedConnection && !invokedCompletion) {
|
||||
[weakSelf.activeConnection invalidate];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath guidedInstallation:(BOOL)guidedInstallation allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath];
|
||||
|
||||
BOOL submittedInstaller = NO;
|
||||
BOOL preflighted = NO;
|
||||
|
||||
// Only submit a job here if we are preflighted (already running root in which case we use system domain),
|
||||
// or if we do not have to ask the user for authorization
|
||||
BOOL needsSystemAuthorization = SUNeedsSystemAuthorizationAccess(hostBundlePath, guidedInstallation, &preflighted);
|
||||
BOOL shouldSubmitInstallerImmediately = (!needsSystemAuthorization || preflighted);
|
||||
if (shouldSubmitInstallerImmediately) {
|
||||
submittedInstaller = ([SUSubmitInstaller submitInstallerAtPath:installerPath withHostBundle:hostBundle allowingInteraction:allowingInteraction inSystemDomain:needsSystemAuthorization] == SUAuthorizationReplySuccess);
|
||||
}
|
||||
|
||||
// if we need to use the system domain and we aren't already root and we aren't allowed interaction, then try sometime later when interaction is allowed
|
||||
if (needsSystemAuthorization && !preflighted && !allowingInteraction) {
|
||||
completionHandler(SUAuthorizationReplyAuthorizeLater);
|
||||
} else {
|
||||
BOOL submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle allowingInteraction:allowingInteraction installerPath:installerPath shouldSubmitInstaller:!shouldSubmitInstallerImmediately];
|
||||
BOOL submittedInstaller = ([SUSubmitInstaller submitInstallerAtPath:installerPath withHostBundle:hostBundle allowingInteraction:allowingInteraction inSystemDomain:needsSystemAuthorization] == SUAuthorizationReplySuccess);
|
||||
|
||||
if (!submittedProgressTool) {
|
||||
completionHandler(SUAuthorizationReplyFailure);
|
||||
} else if (shouldSubmitInstallerImmediately) {
|
||||
completionHandler(submittedInstaller ? SUAuthorizationReplySuccess : SUAuthorizationReplyFailure);
|
||||
} else {
|
||||
[self waitForProgressAgentWithHostBundle:hostBundle completion:completionHandler];
|
||||
if (!submittedInstaller) {
|
||||
SULog(@"Failed to submit installer job");
|
||||
}
|
||||
|
||||
BOOL submittedProgressTool = NO;
|
||||
if (submittedInstaller) {
|
||||
submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle inSystemDomainForInstaller:needsSystemAuthorization];
|
||||
|
||||
if (!submittedProgressTool) {
|
||||
SULog(@"Failed to submit progress tool job");
|
||||
}
|
||||
}
|
||||
|
||||
completionHandler(submittedProgressTool ? SUAuthorizationReplySuccess : SUAuthorizationReplyFailure);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// SUInstallerProgressLauncherProtocol.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/17/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerAgentInitiationProtocol.h"
|
||||
#import "SUAuthorizationReply.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUInstallerProgressLauncherProtocol <SUInstallerAgentInitiationProtocol>
|
||||
|
||||
- (void)requestUserAuthorizationWithReply:(void (^)(SUAuthorizationReply))reply;
|
||||
|
||||
// Redeclare this method from SUInstallerAgentInitiationProtocol because XPC decoders on older OS systems (eg: 10.8) do not traverse parent protocols
|
||||
- (void)connectionDidInitiateWithReply:(void (^)(void))acknowledgement;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -102,7 +102,6 @@
|
||||
72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B071C82C9600013C1C5 /* SULocalizations.h */; };
|
||||
721652611D3C437E00FD13D8 /* SUSubmitInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 722194771D3C4251004C34FF /* SUSubmitInstaller.m */; };
|
||||
721652621D3C44A100FD13D8 /* SUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SUSystemAuthorization.m */; };
|
||||
721652651D3C744700FD13D8 /* InstallerProgressLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 721652641D3C744700FD13D8 /* InstallerProgressLauncher.m */; };
|
||||
721BC20E1D1CDE55002BC71E /* SULocalCacheDirectory.h in Headers */ = {isa = PBXBuildFile; fileRef = 721BC20C1D1CDE55002BC71E /* SULocalCacheDirectory.h */; };
|
||||
721BC20F1D1CDE55002BC71E /* SULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SULocalCacheDirectory.m */; };
|
||||
721BC2101D1CDE55002BC71E /* SULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SULocalCacheDirectory.m */; };
|
||||
@@ -760,9 +759,6 @@
|
||||
7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = "<group>"; };
|
||||
72162B051C82C8B30013C1C5 /* SUParameterAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUParameterAssert.h; sourceTree = "<group>"; };
|
||||
72162B071C82C9600013C1C5 /* SULocalizations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULocalizations.h; sourceTree = "<group>"; };
|
||||
721652631D3C744700FD13D8 /* InstallerProgressLauncher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InstallerProgressLauncher.h; path = InstallerLauncher/InstallerProgressLauncher.h; sourceTree = SOURCE_ROOT; };
|
||||
721652641D3C744700FD13D8 /* InstallerProgressLauncher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InstallerProgressLauncher.m; path = InstallerLauncher/InstallerProgressLauncher.m; sourceTree = SOURCE_ROOT; };
|
||||
721652661D3C76E500FD13D8 /* SUInstallerProgressLauncherProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUInstallerProgressLauncherProtocol.h; path = InstallerLauncher/SUInstallerProgressLauncherProtocol.h; sourceTree = SOURCE_ROOT; };
|
||||
721652671D3C8FED00FD13D8 /* SUAuthorizationReply.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SUAuthorizationReply.h; path = InstallerLauncher/SUAuthorizationReply.h; sourceTree = SOURCE_ROOT; };
|
||||
721BC2061D17A532002BC71E /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
|
||||
721BC2081D17A553002BC71E /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
|
||||
@@ -1557,10 +1553,6 @@
|
||||
722194521D3BFEB7004C34FF /* SUInstallerAgentInitiationProtocol.h */,
|
||||
72D9547F1CBACC35006F28BD /* InstallerProgressAppController.h */,
|
||||
72D954801CBACC35006F28BD /* InstallerProgressAppController.m */,
|
||||
721652671D3C8FED00FD13D8 /* SUAuthorizationReply.h */,
|
||||
721652661D3C76E500FD13D8 /* SUInstallerProgressLauncherProtocol.h */,
|
||||
721652631D3C744700FD13D8 /* InstallerProgressLauncher.h */,
|
||||
721652641D3C744700FD13D8 /* InstallerProgressLauncher.m */,
|
||||
72D954841CBAD418006F28BD /* ShowInstallerProgress.h */,
|
||||
72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */,
|
||||
7267E5A31D3D8A8A00D1BF90 /* StatusInfo.h */,
|
||||
@@ -1635,6 +1627,7 @@
|
||||
726E07AE1CAF08D6001A286B /* InstallerLauncher */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
721652671D3C8FED00FD13D8 /* SUAuthorizationReply.h */,
|
||||
726E07AF1CAF08D6001A286B /* SUInstallerLauncherProtocol.h */,
|
||||
726E07B01CAF08D6001A286B /* SUInstallerLauncher.h */,
|
||||
726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */,
|
||||
@@ -2590,7 +2583,6 @@
|
||||
72D954811CBACC35006F28BD /* InstallerProgressAppController.m in Sources */,
|
||||
72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */,
|
||||
721C24611CB75C5D005440CB /* SUHost.m in Sources */,
|
||||
721652651D3C744700FD13D8 /* InstallerProgressLauncher.m in Sources */,
|
||||
722194791D3C4251004C34FF /* SUSubmitInstaller.m in Sources */,
|
||||
721C245E1CB757DE005440CB /* SUConstants.m in Sources */,
|
||||
721C245D1CB757C4005440CB /* SUApplicationInfo.m in Sources */,
|
||||
|
||||
+7
-41
@@ -13,7 +13,6 @@
|
||||
#import "SUApplicationInfo.h"
|
||||
#import "SUInstallerAgentProtocol.h"
|
||||
#import "SUInstallerAgentInitiationProtocol.h"
|
||||
#import "InstallerProgressLauncher.h"
|
||||
#import "StatusInfo.h"
|
||||
#import <ServiceManagement/ServiceManagement.h>
|
||||
|
||||
@@ -24,7 +23,7 @@
|
||||
*/
|
||||
static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
|
||||
@interface InstallerProgressAppController () <NSApplicationDelegate, SUInstallerAgentProtocol, InstallerProgressLauncherDelegate>
|
||||
@interface InstallerProgressAppController () <NSApplicationDelegate, SUInstallerAgentProtocol>
|
||||
|
||||
@property (nonatomic, readonly) NSApplication *application;
|
||||
@property (nonatomic, weak) id<InstallerProgressDelegate> delegate;
|
||||
@@ -32,7 +31,6 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
@property (nonatomic) BOOL connected;
|
||||
@property (nonatomic) BOOL repliedToRegistration;
|
||||
@property (nonatomic, readonly) NSBundle *hostBundle;
|
||||
@property (nonatomic, readonly, nullable) InstallerProgressLauncher *progressLauncher;
|
||||
@property (nonatomic) StatusInfo *statusInfo;
|
||||
@property (nonatomic) BOOL submittedLauncherJob;
|
||||
|
||||
@@ -48,7 +46,6 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
@synthesize connected = _connected;
|
||||
@synthesize repliedToRegistration = _repliedToRegistration;
|
||||
@synthesize hostBundle = _hostBundle;
|
||||
@synthesize progressLauncher = _progressLauncher;
|
||||
@synthesize statusInfo = _statusInfo;
|
||||
@synthesize submittedLauncherJob = _submittedLauncherJob;
|
||||
|
||||
@@ -56,8 +53,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
if (arguments.count != 5) {
|
||||
SULog(@"Error: Invalid arguments");
|
||||
if (arguments.count != 3) {
|
||||
SULog(@"Error: Invalid number of arguments supplied: %@", arguments);
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE];
|
||||
}
|
||||
|
||||
@@ -79,18 +76,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE];
|
||||
}
|
||||
|
||||
BOOL allowingInteraction = arguments[2].boolValue;
|
||||
|
||||
NSString *installerPath = arguments[3];
|
||||
if (installerPath.length == 0) {
|
||||
SULog(@"Error: Installer path length is 0");
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE];
|
||||
}
|
||||
|
||||
BOOL shouldSubmitInstaller = arguments[4].boolValue;
|
||||
if (shouldSubmitInstaller) {
|
||||
_progressLauncher = [[InstallerProgressLauncher alloc] initWithHostBundle:_hostBundle installerPath:installerPath allowingInteraction:allowingInteraction delegate:self];
|
||||
}
|
||||
BOOL systemDomain = arguments[2].boolValue;
|
||||
NSXPCConnectionOptions connectionOptions = systemDomain ? NSXPCConnectionPrivileged : 0;
|
||||
_connection = [[NSXPCConnection alloc] initWithMachServiceName:SUProgressAgentServiceNameForBundleIdentifier(hostBundleIdentifier) options:connectionOptions];
|
||||
|
||||
_statusInfo = [[StatusInfo alloc] initWithHostBundleIdentifier:hostBundleIdentifier];
|
||||
|
||||
@@ -99,9 +87,6 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
_application = application;
|
||||
_delegate = delegate;
|
||||
|
||||
NSXPCConnectionOptions connectionOptions = shouldSubmitInstaller ? NSXPCConnectionPrivileged : 0;
|
||||
_connection = [[NSXPCConnection alloc] initWithMachServiceName:SUProgressAgentServiceNameForBundleIdentifier(hostBundleIdentifier) options:connectionOptions];
|
||||
|
||||
_connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerAgentProtocol)];
|
||||
_connection.exportedObject = self;
|
||||
|
||||
@@ -154,36 +139,17 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)__unused notification
|
||||
{
|
||||
if (self.progressLauncher == nil) {
|
||||
[self startConnection];
|
||||
} else {
|
||||
[self.progressLauncher startListener];
|
||||
}
|
||||
[self startConnection];
|
||||
}
|
||||
|
||||
- (void)cleanupAndExitWithStatus:(int)status __attribute__((noreturn))
|
||||
{
|
||||
[self.statusInfo invalidate];
|
||||
[self.connection invalidate];
|
||||
[self.progressLauncher invalidate];
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
||||
- (void)installerProgressLauncherDidSubmitJob
|
||||
{
|
||||
self.submittedLauncherJob = YES;
|
||||
[self startConnection];
|
||||
}
|
||||
|
||||
- (void)installerProgressLauncherDidInvalidate
|
||||
{
|
||||
if (!self.submittedLauncherJob) {
|
||||
SULog(@"Installer progress launcher invalidated");
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)registerRelaunchBundlePath:(NSString *)relaunchBundlePath reply:(void (^)(NSNumber *))reply
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
Reference in new issue
Block a user