mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
Adds Linux and macOS platform guards so the analyzer can narrow calls through Utils.IsLinux() and Utils.IsMacOS(). Marks the Linux/macOS autostart and system proxy helpers with explicit platform attributes. Updates Utils.GetSystemHosts() to read /etc/hosts on Linux and macOS while keeping the existing Windows hosts and hosts.ics merge behavior.
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
namespace ServiceLib.Handler.SysProxy;
|
|
|
|
[SupportedOSPlatform("linux")]
|
|
public static class ProxySettingLinux
|
|
{
|
|
private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh";
|
|
|
|
public static async Task SetProxy(string host, int port, string exceptions)
|
|
{
|
|
List<string> args = ["manual", host, port.ToString(), exceptions];
|
|
await ExecCmd(args);
|
|
}
|
|
|
|
public static async Task UnsetProxy()
|
|
{
|
|
List<string> args = ["none"];
|
|
await ExecCmd(args);
|
|
}
|
|
|
|
private static async Task ExecCmd(List<string> args)
|
|
{
|
|
var customSystemProxyScriptPath = AppManager.Instance.Config.SystemProxyItem?.CustomSystemProxyScriptPath;
|
|
var fileName = (customSystemProxyScriptPath.IsNotEmpty() && File.Exists(customSystemProxyScriptPath))
|
|
? customSystemProxyScriptPath
|
|
: await FileUtils.CreateLinuxShellFile(_proxySetFileName, EmbedUtils.GetEmbedText(Global.ProxySetLinuxShellFileName), false);
|
|
|
|
// TODO: temporarily notify which script is being used
|
|
NoticeManager.Instance.SendMessage(fileName);
|
|
|
|
await Utils.GetCliWrapOutput(fileName, args);
|
|
}
|
|
}
|