mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-18 10:25:00 +03:00
fix(macos): do not unload the LaunchAgent when updating auto-start (#10567)
Saving the settings runs AutoStartupHandler.UpdateTask, which on macOS first ran "launchctl unload -w" on the v2rayN LaunchAgent. When v2rayN was started by that agent at login, launchd terminates the job processes on unload, so v2rayN received SIGTERM and exited before it could delete and re-create the plist. The "-w" also left the job disabled, so the next login did not start v2rayN although auto-start was still enabled. The agent only has RunAtLoad, so unloading it has no effect other than killing its processes. Removing the plist is enough to stop the next start; enabling still writes the plist and runs "launchctl load -w". Fixes #10522
This commit is contained in:
@@ -251,19 +251,16 @@ public static class AutoStartupHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
var launchAgentPath = GetLaunchAgentPathMacOS();
|
||||
if (File.Exists(launchAgentPath))
|
||||
{
|
||||
var args = new[] { "-c", $"launchctl unload -w \"{launchAgentPath}\"" };
|
||||
await Utils.GetCliWrapOutput(Global.LinuxBash, args);
|
||||
|
||||
File.Delete(launchAgentPath);
|
||||
}
|
||||
// Do not "launchctl unload" the agent: launchd then terminates the job's processes, which is
|
||||
// v2rayN itself when it was started at login. The agent only runs at load, so removing the
|
||||
// plist is enough to stop the next start.
|
||||
File.Delete(GetLaunchAgentPathMacOS());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
|
||||
Reference in New Issue
Block a user