From 79e53bf1f55ff42f7750b2bb31d3aa9a2cb6c62e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 1 Jan 2025 14:24:23 +0800 Subject: [PATCH] Improve macos system proxy code --- .../Handler/SysProxy/ProxySettingOSX.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs index 8c536fa4..6d7524a4 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs @@ -2,10 +2,6 @@ { public class ProxySettingOSX { - /* - * 仅测试了,MacOS 13.7.1 x86 版本,其他版本有待确认 - */ - /// /// 应用接口类型 /// @@ -18,13 +14,15 @@ public static async Task SetProxy(string host, int port, string exceptions) { - var lstCmd = GetSetCmds(host, port, exceptions); + var lstInterface = await GetListNetworkServices(); + var lstCmd = GetSetCmds(lstInterface, host, port, exceptions); await ExecCmd(lstCmd); } public static async Task UnsetProxy() { - var lstCmd = GetUnsetCmds(); + var lstInterface = await GetListNetworkServices(); + var lstCmd = GetUnsetCmds(lstInterface); await ExecCmd(lstCmd); } @@ -42,10 +40,10 @@ } } - private static List GetSetCmds(string host, int port, string exceptions) + private static List GetSetCmds(List lstInterface, string host, int port, string exceptions) { List lstCmd = []; - foreach (var interf in LstInterface) + foreach (var interf in lstInterface) { foreach (var type in LstTypes) { @@ -70,10 +68,10 @@ return lstCmd; } - private static List GetUnsetCmds() + private static List GetUnsetCmds(List lstInterface) { List lstCmd = []; - foreach (var interf in LstInterface) + foreach (var interf in lstInterface) { foreach (var type in LstTypes) { @@ -87,5 +85,16 @@ return lstCmd; } + + public static async Task> GetListNetworkServices() + { + var services = await Utils.GetListNetworkServices(); + if (services.IsNullOrEmpty()) + { + return LstInterface; + } + var lst = services.Split(Environment.NewLine); + return lst.Length > 0 ? LstInterface.Intersect(lst).ToList() : LstInterface; + } } } \ No newline at end of file