Skip to content

Commit

Permalink
添加:MacOS 代理配置与清除 (2dust#6018)
Browse files Browse the repository at this point in the history
* 添加:MacOS 代理配置与清除

* 修复:点击表头排序时,超时服务器排在前面的问题
  • Loading branch information
fonaix authored Nov 8, 2024
1 parent c4b490e commit 5fb4eda
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
69 changes: 69 additions & 0 deletions v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,81 @@
{
public class ProxySettingOSX
{
/*
* 仅测试了,MacOS 13.7.1 x86 版本,其他版本有待确认
*/
/// <summary>
/// 应用接口类型
/// </summary>
private static readonly List<string> LstInterface = ["Ethernet", "Wi-Fi", "Thunderbolt Bridge"];

/// <summary>
/// 代理类型,对应 http,https,socks
/// </summary>
private static readonly List<string> LstTypes = ["setwebproxy", "setsecurewebproxy", "setsocksfirewallproxy"];

public static async Task SetProxy(string host, int port)
{
var lstCmd = GetSetCmds(host, port);
await ExecCmd(lstCmd);
}


public static async Task UnsetProxy()
{
var lstCmd = GetUnsetCmds();
await ExecCmd(lstCmd);
}


private static async Task ExecCmd(List<CmdItem> lstCmd)
{
foreach (var cmd in lstCmd)
{
if (cmd is null || cmd.Cmd.IsNullOrEmpty() || cmd.Arguments is null)
{
continue;
}

await Task.Delay(10);
await Utils.GetCliWrapOutput(cmd.Cmd, cmd.Arguments);
}
}

private static List<CmdItem> GetSetCmds(string host, int port)
{
List<CmdItem> lstCmd = [];
foreach (var interf in LstInterface)
{
foreach (var type in LstTypes)
{
lstCmd.Add(new CmdItem()
{
Cmd = "networksetup",
Arguments = [$"-{type}", interf, host, (type.Contains("socks") ? (port - 1) : port).ToString()]
});
}
}

return lstCmd;
}

private static List<CmdItem> GetUnsetCmds()
{
List<CmdItem> lstCmd = [];
foreach (var interf in LstInterface)
{
foreach (var type in LstTypes)
{
lstCmd.Add(new CmdItem()
{
Cmd = "networksetup",
Arguments = [$"-{type}state", interf, "off"]
});
}
}

return lstCmd;
}
}
}
2 changes: 1 addition & 1 deletion v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
Binding="{Binding SubRemarks}"
Header="{x:Static resx:ResUI.LvSubscription}"
Tag="SubRemarks" />
<DataGridTemplateColumn SortMemberPath="Delay" Tag="Delay">
<DataGridTemplateColumn SortMemberPath="Delay" Tag="DelayVal">
<DataGridTemplateColumn.Header>
<TextBlock Text="{x:Static resx:ResUI.LvTestDelay}" />
</DataGridTemplateColumn.Header>
Expand Down
8 changes: 8 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ProfilesView(Window window)
lstProfiles.SelectionChanged += lstProfiles_SelectionChanged;
lstProfiles.DoubleTapped += LstProfiles_DoubleTapped;
lstProfiles.LoadingRow += LstProfiles_LoadingRow;
lstProfiles.Sorting += LstProfiles_Sorting;
//if (_config.uiItem.enableDragDropSort)
//{
// lstProfiles.AllowDrop = true;
Expand Down Expand Up @@ -92,6 +93,13 @@ public ProfilesView(Window window)
ViewModel?.RefreshServers();
}

private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e)
{
e.Handled = true;
await ViewModel?.SortServer(e.Column.Tag.ToString());
e.Handled = false;
}

//#region Event

private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
Expand Down

0 comments on commit 5fb4eda

Please sign in to comment.