diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml index 63589e0cc..4282bb4ae 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml @@ -67,29 +67,35 @@ - - + + + + + + + + + + + + + + --> - + - + Text="{ReflectionBinding Source={x:Static ms:ProxySettings.ProxyMode},Path=Value, Mode=OneWay,Converter={StaticResource EnumDescriptionToNameConverter},ConverterParameter=Localiza}"/> diff --git a/src/ST.Client.ReverseProxy.Titanium/TitaniumReverseProxyServiceImpl.cs b/src/ST.Client.ReverseProxy.Titanium/TitaniumReverseProxyServiceImpl.cs index 9a57759a8..259b424e3 100644 --- a/src/ST.Client.ReverseProxy.Titanium/TitaniumReverseProxyServiceImpl.cs +++ b/src/ST.Client.ReverseProxy.Titanium/TitaniumReverseProxyServiceImpl.cs @@ -113,7 +113,7 @@ sealed class TitaniumReverseProxyServiceImpl : ReverseProxyServiceImpl, IReverse } else { - if (!OperatingSystem2.IsWindows() && !IsSystemProxy) + if (!OperatingSystem2.IsWindows() && ProxyMode == ProxyMode.Hosts) { // 非 windows 环境 hosts 加速下不能使用系统默认 DNS 解析代理,会解析到 hosts 上无限循环 ip = await DnsAnalysis.AnalysisDomainIpAsync(url, DefaultDnsServers, IsIpv6Support).FirstOrDefaultAsync(); @@ -162,7 +162,7 @@ sealed class TitaniumReverseProxyServiceImpl : ReverseProxyServiceImpl, IReverse } //host模式下不启用加速会出现无限循环问题 - if (ProxyDomains is null || TwoLevelAgentEnable || (OnlyEnableProxyScript && IsSystemProxy)) return; + if (ProxyDomains is null || TwoLevelAgentEnable || (OnlyEnableProxyScript && ProxyMode == ProxyMode.Hosts)) return; //var item = ProxyDomains.FirstOrDefault(f => f.DomainNamesArray.Any(h => e.HttpClient.Request.RequestUri.AbsoluteUri.Contains(h, StringComparison.OrdinalIgnoreCase))); @@ -368,7 +368,7 @@ sealed class TitaniumReverseProxyServiceImpl : ReverseProxyServiceImpl, IReverse }; explicitProxyEndPoint.BeforeTunnelConnectRequest += ExplicitProxyEndPoint_BeforeTunnelConnectRequest; - if (IsSystemProxy) + if (ProxyMode == ProxyMode.System) { //explicit endpoint 是客户端知道代理存在的地方 proxyServer.AddEndPoint(explicitProxyEndPoint); @@ -422,7 +422,7 @@ sealed class TitaniumReverseProxyServiceImpl : ReverseProxyServiceImpl, IReverse proxyServer.Start(); - if (IsSystemProxy) + if (ProxyMode == ProxyMode.System) { if (!DesktopBridge.IsRunningAsUwp && OperatingSystem2.IsWindows()) { @@ -552,7 +552,7 @@ sealed class TitaniumReverseProxyServiceImpl : ReverseProxyServiceImpl, IReverse proxyServer.Stop(); } - if (IsSystemProxy) + if (ProxyMode == ProxyMode.System) { if (DesktopBridge.IsRunningAsUwp || !OperatingSystem2.IsWindows()) { diff --git a/src/ST.Client.ReverseProxy.Yarp/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs b/src/ST.Client.ReverseProxy.Yarp/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs index b8a6361e3..256eb51f1 100644 --- a/src/ST.Client.ReverseProxy.Yarp/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs +++ b/src/ST.Client.ReverseProxy.Yarp/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs @@ -17,7 +17,10 @@ partial class YarpReverseProxyServiceImpl services.AddFlowAnalyze(); #if WINDOWS - services.AddPacketIntercept(); + if (ProxyMode == ProxyMode.DNSIntercept) + { + services.AddPacketIntercept(); + } #endif } diff --git a/src/ST.Client.ReverseProxy/Services/IReverseProxyService.cs b/src/ST.Client.ReverseProxy/Services/IReverseProxyService.cs index b87cdbdeb..b379d57f9 100644 --- a/src/ST.Client.ReverseProxy/Services/IReverseProxyService.cs +++ b/src/ST.Client.ReverseProxy/Services/IReverseProxyService.cs @@ -52,9 +52,9 @@ public interface IReverseProxyService : IDisposable IPAddress ProxyIp { get; set; } /// - /// 是否使用系统代理模式 + /// 代理模式 /// - bool IsSystemProxy { get; set; } + ProxyMode ProxyMode { get; set; } /// /// 启用 GOG 插件代理 diff --git a/src/ST.Client.ReverseProxy/Services/Implementation/ReverseProxyServiceImpl.cs b/src/ST.Client.ReverseProxy/Services/Implementation/ReverseProxyServiceImpl.cs index 2e1ef9f68..8484e1d26 100644 --- a/src/ST.Client.ReverseProxy/Services/Implementation/ReverseProxyServiceImpl.cs +++ b/src/ST.Client.ReverseProxy/Services/Implementation/ReverseProxyServiceImpl.cs @@ -52,8 +52,8 @@ abstract class ReverseProxyServiceImpl /// public IPAddress ProxyIp { get; set; } = IPAddress.Any; - /// - public bool IsSystemProxy { get; set; } + /// + public ProxyMode ProxyMode { get; set; } /// public bool IsProxyGOG { get; set; } diff --git a/src/ST.Client/Services/Mvvm/ProxyService.cs b/src/ST.Client/Services/Mvvm/ProxyService.cs index 8eb39bb21..a5fc90c10 100644 --- a/src/ST.Client/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client/Services/Mvvm/ProxyService.cs @@ -74,13 +74,13 @@ namespace System.Application.Services { #pragma warning disable CA1416 // 验证平台兼容性 reverseProxyService.IsOnlyWorkSteamBrowser = ProxySettings.IsOnlyWorkSteamBrowser.Value; - reverseProxyService.IsSystemProxy = ProxySettings.EnableWindowsProxy.Value; + reverseProxyService.ProxyMode = ProxySettings.ProxyModeValue; reverseProxyService.IsProxyGOG = ProxySettings.IsProxyGOG.Value; #pragma warning restore CA1416 // 验证平台兼容性 } else { - reverseProxyService.IsSystemProxy = true; + reverseProxyService.ProxyMode = ProxyMode.System; } // macOS 上目前因权限问题仅支持 0.0.0.0(IPAddress.Any) @@ -109,7 +109,7 @@ namespace System.Application.Services this.RaisePropertyChanged(nameof(EnableProxyDomains)); this.RaisePropertyChanged(nameof(EnableProxyScripts)); - if (!reverseProxyService.IsSystemProxy) + if (reverseProxyService.ProxyMode == ProxyMode.Hosts) { const ushort httpsPort = 443; var inUse = reverseProxyService.PortInUse(httpsPort); @@ -140,7 +140,7 @@ namespace System.Application.Services if (isRun) { - if (!reverseProxyService.IsSystemProxy) + if (reverseProxyService.ProxyMode == ProxyMode.Hosts) { if (reverseProxyService.ProxyDomains.Any_Nullable()) { diff --git a/src/ST.Client/Settings/ProxySettings.Avalonia.cs b/src/ST.Client/Settings/ProxySettings.Avalonia.cs index ff3cb4ace..ac4c70254 100644 --- a/src/ST.Client/Settings/ProxySettings.Avalonia.cs +++ b/src/ST.Client/Settings/ProxySettings.Avalonia.cs @@ -17,17 +17,6 @@ namespace System.Application.Settings [SupportedOSPlatform("Linux")] public static SerializableProperty IsProxyGOG => _IsProxyGOG ?? throw new PlatformNotSupportedException(); - static readonly SerializableProperty? _EnableWindowsProxy - = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; - - /// - /// 启用系统代理模式 - /// - [SupportedOSPlatform("Windows7.0")] - [SupportedOSPlatform("macOS")] - [SupportedOSPlatform("Linux")] - public static SerializableProperty EnableWindowsProxy => _EnableWindowsProxy ?? throw new PlatformNotSupportedException(); - static readonly SerializableProperty? _IsOnlyWorkSteamBrowser = IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null; diff --git a/src/ST.Client/Settings/ProxySettings.cs b/src/ST.Client/Settings/ProxySettings.cs index a96e865e7..63f1f936b 100644 --- a/src/ST.Client/Settings/ProxySettings.cs +++ b/src/ST.Client/Settings/ProxySettings.cs @@ -144,7 +144,7 @@ namespace System.Application.Settings { if (OperatingSystem2.IsWindows()) { - //yield return EProxyMode.DNSIntercept; // TODO... https://github.com/BeyondDimension/WinDivertSharp + yield return EProxyMode.DNSIntercept; // TODO... https://github.com/BeyondDimension/WinDivertSharp yield return EProxyMode.Hosts; yield return EProxyMode.System; } diff --git a/src/ST.Client/Enums/ProxyMode.cs b/src/ST/Enums/ProxyMode.cs similarity index 74% rename from src/ST.Client/Enums/ProxyMode.cs rename to src/ST/Enums/ProxyMode.cs index ebb7089ab..4216b2400 100644 --- a/src/ST.Client/Enums/ProxyMode.cs +++ b/src/ST/Enums/ProxyMode.cs @@ -1,3 +1,5 @@ +using System.ComponentModel; + namespace System.Application { /// @@ -8,26 +10,31 @@ namespace System.Application /// /// 通过注入驱动实现 DNS 拦截进行代理(Windows Only) /// + [Description("ProxyMode_DNSIntercept")] DNSIntercept, /// /// 修改 Hosts 文件进行代理(Desktop Only) /// + [Description("ProxyMode_Hosts")] Hosts, /// /// 系统代理模式(Desktop Only) /// + [Description("ProxyMode_System")] System, /// /// VPN 代理模式(虚拟网卡) /// + [Description("ProxyMode_VPN")] VPN, /// /// 仅代理模式 /// + [Description("ProxyMode_ProxyOnly")] ProxyOnly, } }