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:
Aleksey Fedorov
2026-11-13 16:31:06 +10:00
committed by GitHub
parent d5338f673c
commit 6288b3909e
2 changed files with 86 additions and 8 deletions
@@ -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")]