mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
Add system proxy exception function for linux
https://github.com/2dust/v2rayN/issues/6214
This commit is contained in:
parent
5f5d7172ee
commit
dbd4f55981
10 changed files with 73 additions and 10 deletions
|
@ -2,9 +2,9 @@
|
||||||
{
|
{
|
||||||
public class ProxySettingLinux
|
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);
|
await ExecCmd(lstCmd);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<CmdItem> GetSetCmds(string host, int port)
|
private static List<CmdItem> GetSetCmds(string host, int port, string exceptions)
|
||||||
{
|
{
|
||||||
var isKde = IsKde(out var configDir);
|
var isKde = IsKde(out var configDir);
|
||||||
List<string> lstType = ["", "http", "https", "socks", "ftp"];
|
List<string> lstType = ["", "http", "https", "socks", "ftp"];
|
||||||
|
@ -41,6 +41,10 @@
|
||||||
{
|
{
|
||||||
lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir));
|
lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir));
|
||||||
}
|
}
|
||||||
|
if (exceptions.IsNotEmpty())
|
||||||
|
{
|
||||||
|
lstCmd.AddRange(GetSetCmd4Kde("exceptions", exceptions, 0, configDir));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -48,6 +52,10 @@
|
||||||
{
|
{
|
||||||
lstCmd.AddRange(GetSetCmd4Gnome(type, host, port));
|
lstCmd.AddRange(GetSetCmd4Gnome(type, host, port));
|
||||||
}
|
}
|
||||||
|
if (exceptions.IsNotEmpty())
|
||||||
|
{
|
||||||
|
lstCmd.AddRange(GetSetCmd4Gnome("exceptions", exceptions, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return lstCmd;
|
return lstCmd;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +97,14 @@
|
||||||
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "ProxyType", "1"]
|
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
|
else
|
||||||
{
|
{
|
||||||
var type2 = type.Equals("https") ? "http" : type;
|
var type2 = type.Equals("https") ? "http" : type;
|
||||||
|
@ -114,6 +130,14 @@
|
||||||
Arguments = ["set", "org.gnome.system.proxy", "mode", "manual"]
|
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
|
else
|
||||||
{
|
{
|
||||||
lstCmd.Add(new()
|
lstCmd.Add(new()
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||||
|
var exceptions = config.SystemProxyItem.SystemProxyExceptions;
|
||||||
if (port <= 0)
|
if (port <= 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESysProxyType.ForcedChange when Utils.IsLinux():
|
case ESysProxyType.ForcedChange when Utils.IsLinux():
|
||||||
await ProxySettingLinux.SetProxy(Global.Loopback, port);
|
await ProxySettingLinux.SetProxy(Global.Loopback, port, exceptions);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESysProxyType.ForcedChange when Utils.IsOSX():
|
case ESysProxyType.ForcedChange when Utils.IsOSX():
|
||||||
|
|
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
@ -3058,6 +3058,15 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Exception. Do not use proxy server for addresses,with a comma (,) 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbSettingsExceptionTip2 {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbSettingsExceptionTip2", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Follow System Theme 的本地化字符串。
|
/// 查找类似 Follow System Theme 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1387,4 +1387,7 @@
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
||||||
<value>تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000)</value>
|
<value>تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
|
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1387,4 +1387,7 @@
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
||||||
<value>Number per time for auto batch during speedtest(max 1000)</value>
|
<value>Number per time for auto batch during speedtest(max 1000)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
|
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1387,4 +1387,7 @@
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
||||||
<value>Number per time for auto batch during speedtest(max 1000)</value>
|
<value>Number per time for auto batch during speedtest(max 1000)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
|
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1384,4 +1384,7 @@
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
||||||
<value>测速时自动分批的每批数量(最大1000)</value>
|
<value>测速时自动分批的每批数量(最大1000)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
|
<value>例外. 对于下列地址不使用代理配置文件:使用逗号(,)分隔</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1384,4 +1384,7 @@
|
||||||
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
|
||||||
<value>測速時自動分批的每批數量(最大1000)</value>
|
<value>測速時自動分批的每批數量(最大1000)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsExceptionTip2" xml:space="preserve">
|
||||||
|
<value>例外. 對於下列位址不使用代理設定檔:使用逗號(,)分隔</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -697,7 +697,10 @@
|
||||||
|
|
||||||
<TabItem Name="tabSystemproxy" Header="{x:Static resx:ResUI.TbSettingsSystemproxy}">
|
<TabItem Name="tabSystemproxy" Header="{x:Static resx:ResUI.TbSettingsSystemproxy}">
|
||||||
<DockPanel Classes="Margin8">
|
<DockPanel Classes="Margin8">
|
||||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Vertical">
|
<StackPanel
|
||||||
|
Name="panSystemProxyAdvanced"
|
||||||
|
DockPanel.Dock="Bottom"
|
||||||
|
Orientation="Vertical">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
@ -723,11 +726,17 @@
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="1"
|
Name="txbSettingsExceptionTip"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Classes="Margin8"
|
Classes="Margin8"
|
||||||
DockPanel.Dock="Top"
|
DockPanel.Dock="Top"
|
||||||
Text="{x:Static resx:ResUI.TbSettingsExceptionTip}" />
|
Text="{x:Static resx:ResUI.TbSettingsExceptionTip}" />
|
||||||
|
<TextBlock
|
||||||
|
Name="txbSettingsExceptionTip2"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Classes="Margin8"
|
||||||
|
DockPanel.Dock="Top"
|
||||||
|
Text="{x:Static resx:ResUI.TbSettingsExceptionTip2}" />
|
||||||
<TextBox
|
<TextBox
|
||||||
x:Name="txtsystemProxyExceptions"
|
x:Name="txtsystemProxyExceptions"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
|
|
|
@ -166,9 +166,14 @@ namespace v2rayN.Desktop.Views
|
||||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
this.BindCommand(ViewModel, vm => 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())
|
if (Utils.IsOSX())
|
||||||
|
|
Loading…
Reference in a new issue