Improve macos system proxy code

pull/6443/head
2dust 2025-01-01 14:24:23 +08:00
parent 31de7ec094
commit 79e53bf1f5
1 changed files with 19 additions and 10 deletions

View File

@ -2,10 +2,6 @@
{
public class ProxySettingOSX
{
/*
* MacOS 13.7.1 x86
*/
/// <summary>
/// 应用接口类型
/// </summary>
@ -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<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)
{
@ -70,10 +68,10 @@
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)
{
@ -87,5 +85,16 @@
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;
}
}
}