From 379ff522b10ea776850afde63a3a81bbba81c4e4 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Tue, 7 Sep 2021 19:44:18 +0800 Subject: [PATCH] fix macOS Proxy --- src/Common.CoreLib/IPAddress2.cs | 7 +++++-- src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Common.CoreLib/IPAddress2.cs b/src/Common.CoreLib/IPAddress2.cs index 6f92da474..40118c697 100644 --- a/src/Common.CoreLib/IPAddress2.cs +++ b/src/Common.CoreLib/IPAddress2.cs @@ -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; diff --git a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs index 07dca947e..4d00944ae 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs @@ -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;