mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-30 05:28:50 +00:00
The installer can now inherit privileges from the updater, which inherits privileges from the process that spawns the updater. As such, we can now run the updater & installer as root, and no authorization dialog can prompt up. The installer now must abort or install if the target app has terminated. Zombie processes will no longer stay around. Because the root user has no trash directory, we ignore logging the error if it was not found. We also avoid invoking mdimport which fails as root on the installed app. mdimport may have been used before for updating mdimporter files, however, it should be the developer's responsibility to ensure their mdimporter files have an updated date stamp, which will work if a user updates an app manually. Other than that, we already touch the app to register it with LaunchServices, so that should suffice.
61 lines
1.6 KiB
Objective-C
61 lines
1.6 KiB
Objective-C
//
|
|
// AppDelegate.m
|
|
// sparkle-cli
|
|
//
|
|
// Created by Mayur Pawashe on 4/10/16.
|
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
#import "AppDelegate.h"
|
|
#import <Sparkle/Sparkle.h>
|
|
#import "SUCommandLineUserDriver.h"
|
|
|
|
@interface AppDelegate () <SUUpdaterDelegate>
|
|
|
|
@property (nonatomic, readonly) SUUpdater *updater;
|
|
|
|
@end
|
|
|
|
@implementation AppDelegate
|
|
|
|
@synthesize updater = _updater;
|
|
|
|
- (instancetype)initWithBundlePath:(const char *)bundlePath
|
|
{
|
|
self = [super init];
|
|
if (self != nil) {
|
|
NSString *bundlePathString = [[NSString alloc] initWithUTF8String:bundlePath];
|
|
if (bundlePathString == nil) {
|
|
return nil;
|
|
}
|
|
|
|
NSBundle *bundle = [NSBundle bundleWithPath:bundlePathString];
|
|
if (bundle == nil) {
|
|
return nil;
|
|
}
|
|
|
|
id <SUUserDriver> userDriver = [[SUCommandLineUserDriver alloc] initWithBundle:bundle];
|
|
_updater = [[SUUpdater alloc] initWithHostBundle:bundle userDriver:userDriver delegate:self];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)updaterShouldInheritInstallPrivileges:(SUUpdater *)__unused updater
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)__unused aNotification
|
|
{
|
|
// Kick off a scheduled update check once we start the updater later
|
|
[self.updater checkForUpdates];
|
|
|
|
NSError *updaterError = nil;
|
|
if (![self.updater startUpdater:&updaterError]) {
|
|
printf("Error: Failed to initialize updater with error (%ld): %s\n", updaterError.code, updaterError.localizedDescription.UTF8String);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
@end
|