From dbd4f55981628ba0c4fb13d1f82aa14580d5764a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:12:32 +0800 Subject: [PATCH] Add system proxy exception function for linux https://github.com/2dust/v2rayN/issues/6214 --- .../Handler/SysProxy/ProxySettingLinux.cs | 30 +++++++++++++++++-- .../Handler/SysProxy/SysProxyHandler.cs | 3 +- v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 9 ++++++ v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 7 +++-- v2rayN/ServiceLib/Resx/ResUI.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.ru.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 3 ++ .../Views/OptionSettingWindow.axaml | 13 ++++++-- .../Views/OptionSettingWindow.axaml.cs | 9 ++++-- 10 files changed, 73 insertions(+), 10 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs index a06d329b..27bc2403 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs @@ -2,9 +2,9 @@ { public class ProxySettingLinux { - public static async Task SetProxy(string host, int port) + public static async Task SetProxy(string host, int port, string exceptions) { - var lstCmd = GetSetCmds(host, port); + var lstCmd = GetSetCmds(host, port, exceptions); await ExecCmd(lstCmd); } @@ -29,7 +29,7 @@ } } - private static List GetSetCmds(string host, int port) + private static List GetSetCmds(string host, int port, string exceptions) { var isKde = IsKde(out var configDir); List lstType = ["", "http", "https", "socks", "ftp"]; @@ -41,6 +41,10 @@ { lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir)); } + if (exceptions.IsNotEmpty()) + { + lstCmd.AddRange(GetSetCmd4Kde("exceptions", exceptions, 0, configDir)); + } } else { @@ -48,6 +52,10 @@ { lstCmd.AddRange(GetSetCmd4Gnome(type, host, port)); } + if (exceptions.IsNotEmpty()) + { + lstCmd.AddRange(GetSetCmd4Gnome("exceptions", exceptions, 0)); + } } return lstCmd; } @@ -89,6 +97,14 @@ Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "ProxyType", "1"] }); } + else if (type == "exceptions") + { + lstCmd.Add(new() + { + Cmd = "kwriteconfig5", + Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "NoProxyFor", host] + }); + } else { var type2 = type.Equals("https") ? "http" : type; @@ -114,6 +130,14 @@ Arguments = ["set", "org.gnome.system.proxy", "mode", "manual"] }); } + else if (type == "exceptions") + { + lstCmd.Add(new() + { + Cmd = "gsettings", + Arguments = ["set", $"org.gnome.system.proxy", "ignore-hosts", JsonUtils.Serialize(host.Split(','), false)] + }); + } else { lstCmd.Add(new() diff --git a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs index 6e54c506..06b1b527 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -14,6 +14,7 @@ try { var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); + var exceptions = config.SystemProxyItem.SystemProxyExceptions; if (port <= 0) { return false; @@ -27,7 +28,7 @@ break; } case ESysProxyType.ForcedChange when Utils.IsLinux(): - await ProxySettingLinux.SetProxy(Global.Loopback, port); + await ProxySettingLinux.SetProxy(Global.Loopback, port, exceptions); break; case ESysProxyType.ForcedChange when Utils.IsOSX(): diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 95a47fcd..9a91739c 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3058,6 +3058,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Exception. Do not use proxy server for addresses,with a comma (,) 的本地化字符串。 + /// + public static string TbSettingsExceptionTip2 { + get { + return ResourceManager.GetString("TbSettingsExceptionTip2", resourceCulture); + } + } + /// /// 查找类似 Follow System Theme 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index a7d1b4d1..2391c97d 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1380,11 +1380,14 @@ جیسون خام XHTTP Extra, فرمت: { XHTTPObject } - + هنگام بستن پنجره در سینی پنهان شوید تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000) - + + Exception. Do not use proxy server for addresses,with a comma (,) + + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index d3256609..6de29b69 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1387,4 +1387,7 @@ Number per time for auto batch during speedtest(max 1000) + + Exception. Do not use proxy server for addresses,with a comma (,) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 773e9006..eadd3978 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1387,4 +1387,7 @@ Number per time for auto batch during speedtest(max 1000) + + Exception. Do not use proxy server for addresses,with a comma (,) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 00588917..279818d8 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1384,4 +1384,7 @@ 测速时自动分批的每批数量(最大1000) + + 例外. 对于下列地址不使用代理配置文件:使用逗号(,)分隔 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 7abecd6c..2a9b21e3 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1384,4 +1384,7 @@ 測速時自動分批的每批數量(最大1000) + + 例外. 對於下列位址不使用代理設定檔:使用逗號(,)分隔 + \ No newline at end of file diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml index b837de6c..59139427 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml @@ -697,7 +697,10 @@ - + + vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - if (!Utils.IsWindows()) + if (Utils.IsWindows()) { - tabSystemproxy.IsVisible = false; + txbSettingsExceptionTip2.IsVisible = false; + } + else + { + txbSettingsExceptionTip.IsVisible = false; + panSystemProxyAdvanced.IsVisible = false; } if (Utils.IsOSX())