Skip to content

Commit

Permalink
Improve macos system proxy code
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 1, 2025
1 parent 31de7ec commit 79e53bf
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
{
public class ProxySettingOSX
{
/*
* 仅测试了,MacOS 13.7.1 x86 版本,其他版本有待确认
*/

/// <summary>
/// 应用接口类型
/// </summary>
Expand All @@ -18,13 +14,15 @@ public class ProxySettingOSX

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);
}

Expand All @@ -42,10 +40,10 @@ private static async Task ExecCmd(List<CmdItem> lstCmd)
}
}

private static List<CmdItem> GetSetCmds(string host, int port, string exceptions)
private static List<CmdItem> GetSetCmds(List<string> lstInterface, string host, int port, string exceptions)
{
List<CmdItem> lstCmd = [];
foreach (var interf in LstInterface)
foreach (var interf in lstInterface)
{
foreach (var type in LstTypes)
{
Expand All @@ -70,10 +68,10 @@ private static List<CmdItem> GetSetCmds(string host, int port, string exceptions
return lstCmd;
}

private static List<CmdItem> GetUnsetCmds()
private static List<CmdItem> GetUnsetCmds(List<string> lstInterface)
{
List<CmdItem> lstCmd = [];
foreach (var interf in LstInterface)
foreach (var interf in lstInterface)
{
foreach (var type in LstTypes)
{
Expand All @@ -87,5 +85,16 @@ private static List<CmdItem> GetUnsetCmds()

return lstCmd;
}

public static async Task<List<string>> 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;
}
}
}

0 comments on commit 79e53bf

Please sign in to comment.