mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-29 05:24:26 +00:00
We now use XPC for communication between Sparkle.framework and Autoupdate. Autoupdate is now ran as a launchd agaent/daemon. (Most of the time, it acts as an agent). Using XPC can only be done from non-sandboxed processes, so a connection and status service had to be created. Currently, the GUI progress tool doesn't work properly, but everything else should be behaving like before.
75 lines
3.5 KiB
Objective-C
75 lines
3.5 KiB
Objective-C
//
|
|
// 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"
|
|
#import "SUMessageTypes.h"
|
|
#import <ServiceManagement/SMLoginItem.h>
|
|
#import "SUSystemAuthorization.h"
|
|
|
|
@implementation SUInstallerLauncher
|
|
|
|
- (void)launchInstallerAtPath:(NSString *)installerPath withHostBundleIdentifier:(NSString *)hostBundleIdentifier allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(BOOL success))completionHandler
|
|
{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
SUFileManager *fileManager = [SUFileManager defaultManager];
|
|
|
|
NSURL *installerURL = [NSURL fileURLWithPath:installerPath];
|
|
|
|
NSError *quarantineError = nil;
|
|
if (![fileManager releaseItemFromQuarantineAtRootURL:installerURL 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);
|
|
}
|
|
|
|
NSString *executablePath = [[[installerPath stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent:@"MacOS"] stringByAppendingPathComponent:@SPARKLE_RELAUNCH_TOOL_NAME];
|
|
|
|
NSError *ownershipError = nil;
|
|
if (![fileManager changeOwnerAndGroupOfItemAtRootURL:[NSURL fileURLWithPath:executablePath] toMatchURL:installerURL error:&ownershipError]) {
|
|
// This may or may not be a fatal error
|
|
SULog(@"Failed to change ownership on installer executable at %@ with error %@", executablePath, ownershipError);
|
|
}
|
|
|
|
NSArray *arguments = @[hostBundleIdentifier, @(allowingInteraction).stringValue];
|
|
|
|
BOOL grantsSystemPrivilege = NO;
|
|
AuthorizationRef auth = SUCreateAuthorization(&grantsSystemPrivilege);
|
|
Boolean submittedJob = false;
|
|
if (auth != NULL) {
|
|
CFStringRef domain = (grantsSystemPrivilege ? kSMDomainSystemLaunchd : kSMDomainUserLaunchd);
|
|
NSString *label = [NSString stringWithFormat:@"%@-sparkle-updater", hostBundleIdentifier];
|
|
|
|
CFErrorRef removeError = NULL;
|
|
if (!SMJobRemove(domain, (__bridge CFStringRef)(label), auth, true, &removeError)) {
|
|
if (removeError != NULL) {
|
|
SULog(@"Remove error: %@", removeError);
|
|
CFRelease(removeError);
|
|
}
|
|
}
|
|
|
|
NSDictionary *jobDictionary = @{@"Label" : label, @"ProgramArguments" : [@[executablePath] arrayByAddingObjectsFromArray:arguments], @"EnableTransactions" : @NO, @"KeepAlive" : @{@"SuccessfulExit" : @NO}, @"RunAtLoad" : @NO, @"NICE" : @0, @"LaunchOnlyOnce": @YES, @"MachServices" : @{SUAutoUpdateServiceNameForBundleIdentifier(hostBundleIdentifier) : @YES, SUStatusInfoServiceNameForBundleIdentifier(hostBundleIdentifier) : @YES}};
|
|
|
|
CFErrorRef submitError = NULL;
|
|
submittedJob = SMJobSubmit(domain, (__bridge CFDictionaryRef)(jobDictionary), auth, &submitError);
|
|
if (!submittedJob) {
|
|
if (submitError != NULL) {
|
|
SULog(@"Submit error: %@", submitError);
|
|
CFRelease(submitError);
|
|
}
|
|
}
|
|
|
|
AuthorizationFree(auth, kAuthorizationFlagDefaults);
|
|
}
|
|
|
|
completionHandler(submittedJob == true);
|
|
});
|
|
}
|
|
|
|
@end
|