Restart my application after an automatic update?

In OS X, how can I automatically restart my application after pulling out the updated version?

I looked around, and starting up seems to be the likely way to do this, but I can't seem to find out about it. I can't seem to find any good resources talking specifically about this.

I could create a script or a separate process for this, but this seems awkward at best, I expect that there will be a better solution.

+3
source share
2 answers

A separate process is a good solution, look at the Sparkle infrastructure (most applications use it for autoupdating), they also use this standalone application - https://github.com/andymatuschak/Sparkle/blob/master/relaunch.m

+3
source

Just expanding the answer to Julia, since I had to restart the application for a reason other than updating, I looked at how Sparkle works -

( 11/2011) Sparkle , finish_installation.app, Resources Sparkle. Sparkle, -, finish_application application_support , , :

NSString *relaunchToolPath = [NSString stringWithFormat:@"%@/finish_installation.app/Contents/MacOS/finish_installation", tempDir];
[NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", nil]];
[NSApp terminate:self];

, , (?), finish_application.

finish_installation , , ​​ , , (pid = 1)

if(getppid() == 1)...
if (GetProcessForPID(parentprocessid, &psn) == procNotFound)...

:

[[NSWorkspace sharedWorkspace] openFile: appPath];

: , finish_installation , , - :

ProcessSerialNumber     psn = { 0, kCurrentProcess };
TransformProcessType( &psn, kProcessTransformToForegroundApplication );
+2

Source: https://habr.com/ru/post/1776769/


All Articles