From 5fb4edae2d9fcf588c2051c0606c8f047acef9b6 Mon Sep 17 00:00:00 2001 From: fonaix Date: Fri, 8 Nov 2024 09:21:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9AMacOS=20=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E9=85=8D=E7=BD=AE=E4=B8=8E=E6=B8=85=E9=99=A4=20(#6018?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加:MacOS 代理配置与清除 * 修复:点击表头排序时,超时服务器排在前面的问题 --- .../Handler/SysProxy/ProxySettingOSX.cs | 69 +++++++++++++++++++ .../v2rayN.Desktop/Views/ProfilesView.axaml | 2 +- .../Views/ProfilesView.axaml.cs | 8 +++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs index e2eb4e26..8ba1e043 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs @@ -2,12 +2,81 @@ { public class ProxySettingOSX { + /* + * 仅测试了,MacOS 13.7.1 x86 版本,其他版本有待确认 + */ + /// + /// 应用接口类型 + /// + private static readonly List LstInterface = ["Ethernet", "Wi-Fi", "Thunderbolt Bridge"]; + + /// + /// 代理类型,对应 http,https,socks + /// + private static readonly List 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 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 GetSetCmds(string host, int port) + { + List 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 GetUnsetCmds() + { + List lstCmd = []; + foreach (var interf in LstInterface) + { + foreach (var type in LstTypes) + { + lstCmd.Add(new CmdItem() + { + Cmd = "networksetup", + Arguments = [$"-{type}state", interf, "off"] + }); + } + } + + return lstCmd; } } } \ No newline at end of file diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml index 5cc3d6f6..73265c92 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml @@ -204,7 +204,7 @@ Binding="{Binding SubRemarks}" Header="{x:Static resx:ResUI.LvSubscription}" Tag="SubRemarks" /> - + diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 1ac0cad3..9983f8c7 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -32,6 +32,7 @@ namespace v2rayN.Desktop.Views lstProfiles.SelectionChanged += lstProfiles_SelectionChanged; lstProfiles.DoubleTapped += LstProfiles_DoubleTapped; lstProfiles.LoadingRow += LstProfiles_LoadingRow; + lstProfiles.Sorting += LstProfiles_Sorting; //if (_config.uiItem.enableDragDropSort) //{ // lstProfiles.AllowDrop = true; @@ -92,6 +93,13 @@ namespace v2rayN.Desktop.Views 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 UpdateViewHandler(EViewAction action, object? obj)