fix macOS Proxy

This commit is contained in:
Aigio Liu
2021-09-07 19:44:24 +08:00
parent 133e44ecb7
commit 379ff522b1
2 changed files with 7 additions and 3 deletions
+5 -2
View File
@@ -5,12 +5,15 @@ namespace System
{
public static class IPAddress2
{
public const string _127_0_0_1 = "127.0.0.1";
public const string localhost = "localhost";
public static bool TryParse(
[NotNullWhen(true)] string? ipString,
[NotNullWhen(true)] out IPAddress? address)
{
if (ipString == "127.0.0.1" ||
string.Equals(ipString, "localhost", StringComparison.OrdinalIgnoreCase))
if (ipString == _127_0_0_1 ||
string.Equals(ipString, localhost, StringComparison.OrdinalIgnoreCase))
{
address = IPAddress.Loopback;
return true;
@@ -168,7 +168,8 @@ namespace System.Application.Services
httpProxyService.IsWindowsProxy = ProxySettings.EnableWindowsProxy.Value;
httpProxyService.IsProxyGOG = ProxySettings.IsProxyGOG.Value;
httpProxyService.ProxyIp = IPAddress2.TryParse(ProxySettings.SystemProxyIp.Value, out var ip) ? ip : IPAddress.Any;
// macOS 上目前因权限问题仅支持 0.0.0.0(IPAddress.Any)
httpProxyService.ProxyIp = (!OperatingSystem2.IsMacOS && IPAddress2.TryParse(ProxySettings.SystemProxyIp.Value, out var ip)) ? ip : IPAddress.Any;
httpProxyService.Socks5ProxyEnable = ProxySettings.Socks5ProxyEnable.Value;
httpProxyService.Socks5ProxyPortId = ProxySettings.Socks5ProxyPortId.Value;