Launch AutoUpdate via NSWorkspace instead of NSTask

This will allow the app to run normally without being terminated because
a XPC service was terminated
This commit is contained in:
Zorg committed 2016-02-14 09:47:16 -05:00
1 parent 2ef497afcd
commit 96fb18e0df
3 files changed
+40 -11

No files matched your search

+4 -1
View File
@@ -49,7 +49,10 @@ static const NSTimeInterval SUParentQuitCheckInterval = .25;
- (void)startListeningWithCompletion:(void (^)(void))completionBlock
{
BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already
#warning Review this code later as well
// Parent process may not be the app we're installing, so don't rely on that
//BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already
BOOL alreadyTerminated = (kill(self.processIdentifier, 0) != 0);
if (alreadyTerminated)
[self cleanupWithCompletion:completionBlock];
else
+29 -6
View File
@@ -510,17 +510,40 @@
if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) {
pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater];
}
[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath],
pathToRelaunch,
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
self.tempDir,
relaunch ? @"1" : @"0",
showUI ? @"1" : @"0"]];
#warning Review this code later..
pid_t processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
for (NSRunningApplication *runningApplication in [[NSWorkspace sharedWorkspace] runningApplications]) {
if ([runningApplication.bundleURL.path isEqual:self.host.bundlePath]) {
processIdentifier = runningApplication.processIdentifier;
break;
}
}
NSArray *launchArguments = @[[self.host bundlePath],
pathToRelaunch,
[NSString stringWithFormat:@"%d", processIdentifier],
self.tempDir,
relaunch ? @"1" : @"0",
showUI ? @"1" : @"0"];
// Don't launch the app via a NSTask; it may be terminated prematurely if we are in a XPC service currently
NSError *launchError = nil;
if ([[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:relaunchToolPath] options:NSWorkspaceLaunchDefault configuration:@{NSWorkspaceLaunchConfigurationArguments : launchArguments} error:&launchError] == nil) {
SULog(@"Failed to launch autoupdate app: %@", launchError);
}
[self terminateApp];
}
- (void)terminateApp
{
for (NSRunningApplication *runningApplication in [[NSWorkspace sharedWorkspace] runningApplications]) {
if ([runningApplication.bundleURL.path isEqual:self.host.bundlePath]) {
[runningApplication terminate];
}
}
[NSApp terminate:self];
}
+7 -4
View File
@@ -114,10 +114,13 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
}
-(void)showAlertText:(NSString *)text informativeText:(NSString *)informativeText {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = text;
alert.informativeText = informativeText;
[self.driver showAlert:alert];
#warning create a delegate for this
SULog(@"Failed to check requirements.. %@; %@", text, informativeText);
// NSAlert *alert = [[NSAlert alloc] init];
// alert.messageText = text;
// alert.informativeText = informativeText;
// [self.driver showAlert:alert];
}
-(void)checkIfConfiguredProperly {