Add InstallerLauncher XPC Service

This allows Sparkle to be used as-is in a sandboxed application,
without needing to place Sparkle into its own XPC service.

Currently the main app may need to set a global mach service lookup exception
and a client download exception, however this can be fixed by creating a couple more
services. Testing for disk writability will need be done in a service too.
This commit is contained in:
Zorg committed 2016-04-01 17:54:12 -04:00
1 parent ee77bf59d5
commit 5c08e0a1d1
13 files changed
+368 -126

No files matched your search

@@ -0,0 +1,6 @@
// Installer Launcher only
INFOPLIST_FILE = InstallerLauncher/Info.plist
WRAPPER_EXTENSION = xpc
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.InstallerLauncher
CODE_SIGN_IDENTITY = -
+33
View File
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>InstallerLauncher</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 Sparkle Project. All rights reserved.</string>
<key>XPCService</key>
<dict>
<key>ServiceType</key>
<string>Application</string>
</dict>
</dict>
</plist>
+15
View File
@@ -0,0 +1,15 @@
//
// SUInstallerLauncher.h
// InstallerLauncher
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SUInstallerLauncherProtocol.h"
// Non-sandboxed XPC service used for launching our installer
// This is necessary for sandboxed applications
@interface SUInstallerLauncher : NSObject <InstallerLauncherProtocol>
@end
+38
View File
@@ -0,0 +1,38 @@
//
// SUInstallerLauncher.m
// InstallerLauncher
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import "SUInstallerLauncher.h"
#import "SUFileManager.h"
#import "SULog.h"
@implementation SUInstallerLauncher
- (void)launchInstallerAtPath:(NSString *)installerPath withArguments:(NSArray *)arguments completion:(void (^)(BOOL success))completionHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
NSError *quarantineError = nil;
SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO];
if (![fileManager releaseItemFromQuarantineAtRootURL:[NSURL fileURLWithPath:installerPath] error:&quarantineError]) {
// This may or may not be a fatal error depending on if the process is sandboxed or not
SULog(@"Failed to release quarantine on installer at %@ with error %@", installerPath, quarantineError);
}
BOOL taskDidLaunch = NO;
@try {
[NSTask launchedTaskWithLaunchPath:installerPath arguments:arguments];
taskDidLaunch = YES;
} @catch (NSException *exception) {
SULog(@"Raised exception when launching update tool: %@", exception);
}
completionHandler(taskDidLaunch);
});
}
@end
@@ -0,0 +1,15 @@
//
// InstallerLauncherProtocol.h
// InstallerLauncher
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol InstallerLauncherProtocol
- (void)launchInstallerAtPath:(NSString *)installerPath withArguments:(NSArray *)arguments completion:(void (^)(BOOL success))completionHandler;
@end
+49
View File
@@ -0,0 +1,49 @@
//
// main.m
// InstallerLauncher
//
// Created by Mayur Pawashe on 4/1/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SUInstallerLauncher.h"
@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@end
@implementation ServiceDelegate
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
// Configure the connection.
// First, set the interface that the exported object implements.
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(InstallerLauncherProtocol)];
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
SUInstallerLauncher *exportedObject = [SUInstallerLauncher new];
newConnection.exportedObject = exportedObject;
// Resuming the connection allows the system to deliver more incoming messages.
[newConnection resume];
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
return YES;
}
@end
int main(int __unused argc, const char * __unused argv[])
{
// Create the delegate for the service.
ServiceDelegate *delegate = [ServiceDelegate new];
// Set up the one NSXPCListener for this service. It will handle all incoming connections.
NSXPCListener *listener = [NSXPCListener serviceListener];
listener.delegate = delegate;
// Resuming the serviceListener starts this service. This method does not return.
[listener resume];
return 0;
}
+139
View File
@@ -167,6 +167,13 @@
726E076D1CA66180001A286B /* SUBinaryDeltaUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */; };
726E078D1CA891E9001A286B /* SUUpdaterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E078B1CA891E9001A286B /* SUUpdaterSettings.h */; settings = {ATTRIBUTES = (Public, ); }; };
726E078E1CA891E9001A286B /* SUUpdaterSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E078C1CA891E9001A286B /* SUUpdaterSettings.m */; };
726E07B21CAF08D6001A286B /* SUInstallerLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */; };
726E07B41CAF08D6001A286B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07B31CAF08D6001A286B /* main.m */; };
726E07B81CAF08D6001A286B /* InstallerLauncher.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 726E07AD1CAF08D6001A286B /* InstallerLauncher.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
726E07BE1CAF0C5C001A286B /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; };
726E07BF1CAF0C6C001A286B /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
726E07C01CAF15B7001A286B /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; };
726E07C21CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */; };
726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
726E4A1B1C86C88F00C57C6A /* TestAppHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E4A1A1C86C88F00C57C6A /* TestAppHelper.m */; };
@@ -354,6 +361,13 @@
remoteGlobalIDString = 61B5F90109C4CEE200B25A18;
remoteInfo = "Sparkle Test App";
};
726E07B61CAF08D6001A286B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 726E07AC1CAF08D6001A286B;
remoteInfo = InstallerLauncher;
};
726E4A1F1C86C88F00C57C6A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
@@ -396,6 +410,17 @@
name = "Copy Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
726E07BD1CAF08D6001A286B /* Embed XPC Services */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "$(CONTENTS_FOLDER_PATH)/XPCServices";
dstSubfolderSpec = 16;
files = (
726E07B81CAF08D6001A286B /* InstallerLauncher.xpc in Embed XPC Services */,
);
name = "Embed XPC Services";
runOnlyForDeploymentPostprocessing = 0;
};
726E4A261C86C88F00C57C6A /* Embed XPC Services */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
@@ -678,6 +703,13 @@
726E076C1CA64B9C001A286B /* SUUnarchiverProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiverProtocol.h; sourceTree = "<group>"; };
726E078B1CA891E9001A286B /* SUUpdaterSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterSettings.h; sourceTree = "<group>"; };
726E078C1CA891E9001A286B /* SUUpdaterSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterSettings.m; sourceTree = "<group>"; };
726E07AD1CAF08D6001A286B /* InstallerLauncher.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = InstallerLauncher.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
726E07AF1CAF08D6001A286B /* SUInstallerLauncherProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUInstallerLauncherProtocol.h; sourceTree = "<group>"; };
726E07B01CAF08D6001A286B /* SUInstallerLauncher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUInstallerLauncher.h; sourceTree = "<group>"; };
726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUInstallerLauncher.m; sourceTree = "<group>"; };
726E07B31CAF08D6001A286B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
726E07B51CAF08D6001A286B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigInstallerLauncher.xcconfig; sourceTree = "<group>"; };
726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverUIDelegate.h; sourceTree = "<group>"; };
726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverRemoteDelegate.h; sourceTree = "<group>"; };
726E4A111C86C44A00C57C6A /* Sparkle-Test-App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Sparkle-Test-App.entitlements"; sourceTree = "<group>"; };
@@ -833,6 +865,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
726E07AA1CAF08D6001A286B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
726E4A131C86C88F00C57C6A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@@ -866,6 +905,7 @@
8DC2EF5B0486A6940098B216 /* Sparkle.framework */,
726B2B5D1C645FC900388755 /* UI Tests.xctest */,
726E4A161C86C88F00C57C6A /* TestAppHelper.xpc */,
726E07AD1CAF08D6001A286B /* InstallerLauncher.xpc */,
);
name = Products;
sourceTree = "<group>";
@@ -984,6 +1024,7 @@
089C1665FE841158C02AAC07 /* Framework Resources */,
61B5F8F309C4CE5900B25A18 /* Other Sources */,
61F83F6E0DBFE07A006FDD30 /* Update Control */,
726E07AE1CAF08D6001A286B /* InstallerLauncher */,
61299B3A09CB056100B7442F /* User Interface */,
);
path = Sparkle;
@@ -1263,6 +1304,19 @@
path = "UI Tests";
sourceTree = "<group>";
};
726E07AE1CAF08D6001A286B /* InstallerLauncher */ = {
isa = PBXGroup;
children = (
726E07AF1CAF08D6001A286B /* SUInstallerLauncherProtocol.h */,
726E07B01CAF08D6001A286B /* SUInstallerLauncher.h */,
726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */,
726E07B31CAF08D6001A286B /* main.m */,
726E07B51CAF08D6001A286B /* Info.plist */,
);
name = InstallerLauncher;
path = ../InstallerLauncher;
sourceTree = "<group>";
};
726E4A171C86C88F00C57C6A /* TestAppHelper */ = {
isa = PBXGroup;
children = (
@@ -1338,6 +1392,7 @@
729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */,
729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */,
729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */,
726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */,
14732BC91960F70A00593899 /* make-release-package.sh */,
14652F7919A93E5F00959E44 /* set-git-version-info.sh */,
146EC84E19A68CF8004A50C5 /* Sparkle.podspec */,
@@ -1546,6 +1601,23 @@
productReference = 726B2B5D1C645FC900388755 /* UI Tests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
};
726E07AC1CAF08D6001A286B /* InstallerLauncher */ = {
isa = PBXNativeTarget;
buildConfigurationList = 726E07B91CAF08D6001A286B /* Build configuration list for PBXNativeTarget "InstallerLauncher" */;
buildPhases = (
726E07A91CAF08D6001A286B /* Sources */,
726E07AA1CAF08D6001A286B /* Frameworks */,
726E07AB1CAF08D6001A286B /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = InstallerLauncher;
productName = InstallerLauncher;
productReference = 726E07AD1CAF08D6001A286B /* InstallerLauncher.xpc */;
productType = "com.apple.product-type.xpc-service";
};
726E4A151C86C88F00C57C6A /* TestAppHelper */ = {
isa = PBXNativeTarget;
buildConfigurationList = 726E4A221C86C88F00C57C6A /* Build configuration list for PBXNativeTarget "TestAppHelper" */;
@@ -1575,11 +1647,13 @@
6131B1910DDCDE32005215F0 /* Run Script: Set Git Version Info */,
6195D4B40E40505A00D41A50 /* Run Script: Link fr_CA to fr */,
61E31A85103299750051D188 /* Run Script: Link pt to pt_BR */,
726E07BD1CAF08D6001A286B /* Embed XPC Services */,
);
buildRules = (
);
dependencies = (
55C14F97136F044100649790 /* PBXTargetDependency */,
726E07B71CAF08D6001A286B /* PBXTargetDependency */,
);
name = Sparkle;
productInstallPath = "$(HOME)/Library/Frameworks";
@@ -1612,6 +1686,9 @@
CreatedOnToolsVersion = 7.2.1;
TestTargetID = 61B5F90109C4CEE200B25A18;
};
726E07AC1CAF08D6001A286B = {
CreatedOnToolsVersion = 7.3;
};
726E4A151C86C88F00C57C6A = {
CreatedOnToolsVersion = 7.2.1;
SystemCapabilities = {
@@ -1680,6 +1757,7 @@
projectRoot = "";
targets = (
8DC2EF4F0486A6940098B216 /* Sparkle */,
726E07AC1CAF08D6001A286B /* InstallerLauncher */,
61B5F90109C4CEE200B25A18 /* Sparkle Test App */,
726E4A151C86C88F00C57C6A /* TestAppHelper */,
612279D80DB5470200AB99EA /* Sparkle Unit Tests */,
@@ -1744,6 +1822,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
726E07AB1CAF08D6001A286B /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
726E4A141C86C88F00C57C6A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
@@ -1759,6 +1844,7 @@
615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */,
55C14BEF136EF21700649790 /* SUStatus.xib in Resources */,
55C14C04136EF26100649790 /* SUUpdateAlert.xib in Resources */,
726E07C21CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig in Resources */,
55C14C19136EF2C700649790 /* SUUpdatePermissionPrompt.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1940,6 +2026,18 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
726E07A91CAF08D6001A286B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
726E07C01CAF15B7001A286B /* SULog.m in Sources */,
726E07BF1CAF0C6C001A286B /* SUConstants.m in Sources */,
726E07BE1CAF0C5C001A286B /* SUFileManager.m in Sources */,
726E07B41CAF08D6001A286B /* main.m in Sources */,
726E07B21CAF08D6001A286B /* SUInstallerLauncher.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
726E4A121C86C88F00C57C6A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@@ -2066,6 +2164,11 @@
target = 61B5F90109C4CEE200B25A18 /* Sparkle Test App */;
targetProxy = 726B2B621C645FC900388755 /* PBXContainerItemProxy */;
};
726E07B71CAF08D6001A286B /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 726E07AC1CAF08D6001A286B /* InstallerLauncher */;
targetProxy = 726E07B61CAF08D6001A286B /* PBXContainerItemProxy */;
};
726E4A201C86C88F00C57C6A /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 726E4A151C86C88F00C57C6A /* TestAppHelper */;
@@ -2279,6 +2382,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
};
name = Coverage;
};
@@ -2332,6 +2436,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
};
name = Debug;
};
@@ -2339,6 +2444,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FA1941D50D94A70100DD942E /* ConfigFrameworkRelease.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
};
name = Release;
};
@@ -2441,6 +2547,30 @@
};
name = Release;
};
726E07BA1CAF08D6001A286B /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */;
buildSettings = {
INFOPLIST_FILE = InstallerLauncher/Info.plist;
};
name = Debug;
};
726E07BB1CAF08D6001A286B /* Coverage */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */;
buildSettings = {
INFOPLIST_FILE = InstallerLauncher/Info.plist;
};
name = Coverage;
};
726E07BC1CAF08D6001A286B /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */;
buildSettings = {
INFOPLIST_FILE = InstallerLauncher/Info.plist;
};
name = Release;
};
726E4A231C86C88F00C57C6A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 726E4A271C86CAB500C57C6A /* ConfigTestAppDebugHelper.xcconfig */;
@@ -2565,6 +2695,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
726E07B91CAF08D6001A286B /* Build configuration list for PBXNativeTarget "InstallerLauncher" */ = {
isa = XCConfigurationList;
buildConfigurations = (
726E07BA1CAF08D6001A286B /* Debug */,
726E07BB1CAF08D6001A286B /* Coverage */,
726E07BC1CAF08D6001A286B /* Release */,
);
defaultConfigurationIsVisible = 0;
};
726E4A221C86C88F00C57C6A /* Build configuration list for PBXNativeTarget "TestAppHelper" */ = {
isa = XCConfigurationList;
buildConfigurations = (
+1 -32
View File
@@ -33,41 +33,10 @@ int main(int __unused argc, const char __unused *argv[])
@autoreleasepool
{
NSArray *args = [[NSProcessInfo processInfo] arguments];
if (args.count != 3) {
if (args.count != 2) {
return EXIT_FAILURE;
}
BOOL shouldRelaunchTool = [args[2] boolValue];
if (shouldRelaunchTool) {
NSURL *mainBundleURL = [[NSBundle mainBundle] bundleURL];
if (mainBundleURL == nil) {
SULog(@"Error: No bundle path located found for main bundle!");
return EXIT_FAILURE;
}
NSMutableArray *launchArguments = [args mutableCopy];
[launchArguments removeObjectAtIndex:0]; // argv[0] is not important
launchArguments[launchArguments.count - 1] = @"0"; // we don't want to relaunch the tool this time
// We want to launch our tool through LaunchServices, not through a NSTask instance
// This has a few advantages: one being that we don't inherit the privileges of the parent owner.
// Another is if we try to spawn a task, it may be prematurely terminated if the parent is like a XPC service,
// which is what the shouldRelaunchTool flag exists to prevent. Thus, a caller may specify to relaunch the tool again and
// wait until we exit. When we exit the first time, the caller will be notified, and we can launch a second instance through LS.
// The caller may not have AppKit available which is why it may not launch through LS itself.
NSError *launchError = nil;
NSRunningApplication *newRunningApplication = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:mainBundleURL options:(NSWorkspaceLaunchOptions)(NSWorkspaceLaunchDefault | NSWorkspaceLaunchNewInstance) configuration:@{NSWorkspaceLaunchConfigurationArguments : [launchArguments copy]} error:&launchError];
if (newRunningApplication == nil) {
SULog(@"Failed to create second instance of tool with error: %@", launchError);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
NSString *hostBundleIdentifier = args[1];
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier];
+7 -6
View File
@@ -153,12 +153,13 @@
NSString *temporaryDirectory = self.downloadDriver.temporaryDirectory;
assert(temporaryDirectory != nil);
NSError *error = nil;
if (![self.installerDriver extractDownloadPath:downloadPath withUpdateItem:self.updateItem temporaryDirectory:temporaryDirectory error:&error]) {
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
} else {
[self.downloadDriver cancelTrashCleanup];
}
[self.installerDriver extractDownloadPath:downloadPath withUpdateItem:self.updateItem temporaryDirectory:temporaryDirectory completion:^(NSError * _Nullable error) {
if (error != nil) {
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
} else {
[self.downloadDriver cancelTrashCleanup];
}
}];
}
- (void)downloadDriverDidFailToDownloadUpdateWithError:(NSError *)error
+1 -1
View File
@@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithHost:(SUHost *)host cachePath:(NSString *)cachePath sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id<SUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SUInstallerDriverDelegate>)delegate;
- (BOOL)extractDownloadPath:(NSString *)downloadPath withUpdateItem:(SUAppcastItem *)updateItem temporaryDirectory:(NSString *)temporaryDirectory error:(NSError * __autoreleasing *)error;
- (void)extractDownloadPath:(NSString *)downloadPath withUpdateItem:(SUAppcastItem *)updateItem temporaryDirectory:(NSString *)temporaryDirectory completion:(void (^)(NSError * _Nullable))completionHandler;
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
+54 -85
View File
@@ -20,6 +20,7 @@
#import "SUFileManager.h"
#import "SUSecureCoding.h"
#import "SUInstallationInputData.h"
#import "SUInstallerLauncherProtocol.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
@@ -173,24 +174,18 @@
return YES;
}
- (BOOL)launchInstallTool:(NSError * __autoreleasing *)error
- (void)launchInstallToolWithCompletion:(void (^)(NSError * _Nullable ))completionHandler
{
if (![self setUpLocalPort:error]) {
return NO;
NSError *localPortError = nil;
if (![self setUpLocalPort:&localPortError]) {
completionHandler(localPortError);
}
NSError *launchError = nil;
if (![self launchAutoUpdate:&launchError]) {
if (error != NULL) {
*error = launchError;
}
return NO;
}
return YES;
[self launchAutoUpdateWithCompletion:completionHandler];
}
// This can be called multiple times (eg: if a delta update fails, this may be called again with a regular update item)
- (BOOL)extractDownloadPath:(NSString *)downloadPath withUpdateItem:(SUAppcastItem *)updateItem temporaryDirectory:(NSString *)temporaryDirectory error:(NSError * __autoreleasing *)error
- (void)extractDownloadPath:(NSString *)downloadPath withUpdateItem:(SUAppcastItem *)updateItem temporaryDirectory:(NSString *)temporaryDirectory completion:(void (^)(NSError * _Nullable))completionHandler
{
self.updateItem = updateItem;
self.temporaryDirectory = temporaryDirectory;
@@ -199,13 +194,12 @@
self.currentStage = SUInstallerNotStarted;
if (self.localPort == nil) {
return [self launchInstallTool:error];
[self launchInstallToolWithCompletion:completionHandler];
} else {
// The Install tool is already alive; just send out installation input data again
[self sendInstallationData];
completionHandler(nil);
}
return YES;
}
- (void)sendInstallationData
@@ -327,7 +321,7 @@
return YES;
}
- (BOOL)launchAutoUpdate:(NSError * __autoreleasing *)outError
- (void)launchAutoUpdateWithCompletion:(void (^)(NSError *_Nullable))completionHandler
{
NSBundle *sparkleBundle = self.sparkleBundle;
@@ -349,93 +343,68 @@
// We only need to run our copy of the app by spawning a task
// Since we are copying the app to a directory that is write-accessible, we don't need to muck with owner/group IDs
if ([self preparePathForRelaunchTool:targetPath error:&error] && [fileManager copyItemAtURL:relaunchURLToCopy toURL:targetURL error:&error]) {
// Releasing quarantine is definitely important (didn't used to be) now that we launch AutoUpdate via LaunchServices
// Perhaps even if this fails, we should continue on in the hopes maybe this isn't a fatal error though
NSError *quarantineError = nil;
if (![fileManager releaseItemFromQuarantineAtRootURL:targetURL error:&quarantineError]) {
SULog(@"Failed to release quarantine on %@ with error %@", targetPath, quarantineError);
}
relaunchPath = targetPath;
} else {
if (outError != NULL) {
*outError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SURelaunchError
userInfo:@{
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]
}
];
}
NSError *prepareError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SURelaunchError
userInfo:@{
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]
}
];
return NO;
completionHandler(prepareError);
return;
}
}
NSString *relaunchToolPath = [[NSBundle bundleWithPath:relaunchPath] executablePath];
if (!relaunchToolPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath]) {
// Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
if (outError != NULL) {
*outError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SURelaunchError
userInfo:@{
NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]],
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath]
}
];
}
NSError *error =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SURelaunchError
userInfo:@{
NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]],
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath]
}
];
// We intentionally don't abandon the update here so that the host won't initiate another.
return NO;
completionHandler(error);
return;
}
NSString *hostBundleIdentifier = self.host.bundle.bundleIdentifier;
if (hostBundleIdentifier == nil) {
if (outError != NULL) {
*outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while finding the application's bundle identifier. Please try again later.", nil) }];
}
return NO;
}
// Make sure the launched task finishes & replies back.
// If it succeeds, it will have launched a second instance of the tool through LaunchServices
// This is necessary if we are a XPC process, because otherwise we risk exiting prematurely
// Further, we don't launch through LS here because we don't want to reference AppKit here
int terminationStatus = 0;
BOOL taskDidLaunch = NO;
@try {
NSTask *launchedTask = [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[hostBundleIdentifier, @"1"]];
[launchedTask waitUntilExit];
taskDidLaunch = YES;
terminationStatus = launchedTask.terminationStatus;
} @catch (NSException *exception) {
SULog(@"Raised exception when launching update tool: %@", exception);
}
if (!taskDidLaunch || terminationStatus != 0) {
if (taskDidLaunch) {
SULog(@"Update tool failed with exit code: %d", terminationStatus);
}
NSError *error =
[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while finding the application's bundle identifier. Please try again later.", nil) }];
if (outError != NULL) {
*outError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SURelaunchError
userInfo:@{
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while launching the updater. Please try again later.", nil),
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't launch relauncher at %@", relaunchToolPath]
}
];
}
return NO;
completionHandler(error);
return;
}
return YES;
NSXPCConnection *launcherConnection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.InstallerLauncher"];
launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(InstallerLauncherProtocol)];
[launcherConnection resume];
[launcherConnection.remoteObjectProxy launchInstallerAtPath:relaunchToolPath withArguments:@[hostBundleIdentifier] completion:^(BOOL success) {
[launcherConnection invalidate];
dispatch_async(dispatch_get_main_queue(), ^{
if (!success) {
NSError *error =
[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while launching the installer. Please try again later.", nil) }];
completionHandler(error);
} else {
completionHandler(nil);
}
});
}];
}
- (BOOL)mayUpdateAndRestart
+2 -2
View File
@@ -203,8 +203,8 @@ static NSString * const UPDATED_VERSION = @"2.0";
self.webServer = webServer;
// Show the Settings window
self.updateSettingsWindowController = [[SURemoteUpdateSettingsWindowController alloc] init];
//self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
//self.updateSettingsWindowController = [[SURemoteUpdateSettingsWindowController alloc] init];
self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
[self.updateSettingsWindowController showWindow:nil];
});
@@ -4,8 +4,16 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- server exception is only needed because the test app launches a web server instance -->
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
<array>
<string>org.sparkle-project.SparkleTestApp-sparkle-installer</string>
</array>
<!-- shared preference exception may only needed when the main app and Sparkle are in separate processes -->
<key>com.apple.security.temporary-exception.shared-preference.read-write</key>
<array>
<string>org.sparkle-project.SparkleTestApp</string>