代理模式UI改进

This commit is contained in:
RMBGAME
2022-06-26 15:05:28 +08:00
parent a89ddccd32
commit 76e1d32bdd
9 changed files with 50 additions and 51 deletions
@@ -67,29 +67,35 @@
</ui:CommandBarElementContainer>
<ui:CommandBarSeparator/>
<!--<ui:CommandBarElementContainer Margin="8 0"
HorizontalContentAlignment="Center">
<ComboBox VerticalAlignment="Center">
<ComboBoxItem Content="{ReflectionBinding Path=Res.ProxyMode_Hosts,Mode=OneWay,Source={x:Static resx:R.Current}}">
</ComboBoxItem>
<ComboBoxItem Content="{ReflectionBinding Path=Res.ProxyMode_System,Mode=OneWay,Source={x:Static resx:R.Current}}">
</ComboBoxItem>
</ComboBox>
</ui:CommandBarElementContainer>-->
<ui:CommandBarElementContainer Margin="8 0"
HorizontalContentAlignment="Center">
<RadioButton Content="{ReflectionBinding Path=Res.ProxyMode_Hosts,Mode=OneWay,Source={x:Static resx:R.Current}}" ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_HostsTip,Mode=OneWay,Source={x:Static resx:R.Current}}" IsChecked="{Binding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=!Value, Mode=TwoWay}"></RadioButton>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{ReflectionBinding Path=Res.CommunityFix_ProxyModeTip,Mode=OneWay,Source={x:Static resx:R.Current}}"
VerticalAlignment="Center"/>
<ComboBox VerticalAlignment="Center"
Items="{ReflectionBinding Source={x:Static ms:ProxySettings.ProxyModes},Path=., Mode=OneWay}"
SelectedItem="{ReflectionBinding Source={x:Static ms:ProxySettings.ProxyMode},Path=Value, Mode=TwoWay}">
<!--<ComboBoxItem Content="{ReflectionBinding Path=Res.ProxyMode_Hosts,Mode=OneWay,Source={x:Static resx:R.Current}}"
ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_HostsTip,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<ComboBoxItem Content="{ReflectionBinding Path=Res.ProxyMode_System,Mode=OneWay,Source={x:Static resx:R.Current}}"
ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_SystemTip,Mode=OneWay,Source={x:Static resx:R.Current}}"/>-->
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{ReflectionBinding Converter={StaticResource EnumDescriptionToNameConverter},ConverterParameter=Localiza}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</ui:CommandBarElementContainer>
<!--<ui:CommandBarElementContainer Margin="8 0"
HorizontalContentAlignment="Center">
<RadioButton Content="{ReflectionBinding Path=Res.ProxyMode_Hosts,Mode=OneWay,Source={x:Static resx:R.Current}}" ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_HostsTip,Mode=OneWay,Source={x:Static resx:R.Current}}"
IsChecked="{Binding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=!Value, Mode=TwoWay}"></RadioButton>
</ui:CommandBarElementContainer>
<ui:CommandBarElementContainer Margin="8 0"
HorizontalContentAlignment="Center">
<RadioButton Content="{ReflectionBinding Path=Res.ProxyMode_System,Mode=OneWay,Source={x:Static resx:R.Current}}" ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_SystemTip,Mode=OneWay,Source={x:Static resx:R.Current}}" IsChecked="{Binding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=Value, Mode=TwoWay}"></RadioButton>
</ui:CommandBarElementContainer>
<!--<ui:CommandBarToggleButton IsChecked="{Binding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=!Value, Mode=TwoWay}"
Label="{ReflectionBinding Path=Res.ProxyMode_Hosts,Mode=OneWay,Source={x:Static resx:R.Current}}"
ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_HostsTip,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<ui:CommandBarToggleButton IsChecked="{Binding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=Value, Mode=TwoWay}"
Label="{ReflectionBinding Path=Res.ProxyMode_System,Mode=OneWay,Source={x:Static resx:R.Current}}"
ToolTip.Tip="{ReflectionBinding Path=Res.ProxyMode_SystemTip,Mode=OneWay,Source={x:Static resx:R.Current}}"/>-->
</ui:CommandBarElementContainer>-->
<ui:CommandBarSeparator/>
<ui:CommandBarButton
@@ -273,16 +279,10 @@
VerticalAlignment="Center"></TextBlock>
</StackPanel>
<WrapPanel HorizontalAlignment="Center">
<TextBlock Text="{ReflectionBinding Path=Res.CommunityFix_ProxyModeTip,Mode=OneWay,Source={x:Static resx:R.Current}}" FontSize="14"/>
<TextBlock Text="{ReflectionBinding Path=Res.CommunityFix_ProxyModeTip,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<TextBlock
Text="{ReflectionBinding Path=Res.ProxyMode_System,Mode=OneWay,Source={x:Static resx:R.Current}}"
FontSize="14"
IsVisible="{ReflectionBinding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=Value}}"/>
<TextBlock
Text="{ReflectionBinding Path=Res.ProxyMode_Hosts,Mode=OneWay,Source={x:Static resx:R.Current}}"
FontSize="14"
IsVisible="{ReflectionBinding Source={x:Static ms:ProxySettings.EnableWindowsProxy},Path=!Value}}"/>
Text="{ReflectionBinding Source={x:Static ms:ProxySettings.ProxyMode},Path=Value, Mode=OneWay,Converter={StaticResource EnumDescriptionToNameConverter},ConverterParameter=Localiza}"/>
</WrapPanel>
</StackPanel>
<DockPanel Grid.Row="1" HorizontalAlignment="Stretch" Margin="0 20">
@@ -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())
{
@@ -17,7 +17,10 @@ partial class YarpReverseProxyServiceImpl
services.AddFlowAnalyze();
#if WINDOWS
services.AddPacketIntercept();
if (ProxyMode == ProxyMode.DNSIntercept)
{
services.AddPacketIntercept();
}
#endif
}
@@ -52,9 +52,9 @@ public interface IReverseProxyService : IDisposable
IPAddress ProxyIp { get; set; }
/// <summary>
/// 是否使用系统代理模式
/// 代理模式
/// </summary>
bool IsSystemProxy { get; set; }
ProxyMode ProxyMode { get; set; }
/// <summary>
/// 启用 GOG 插件代理
@@ -52,8 +52,8 @@ abstract class ReverseProxyServiceImpl
/// <inheritdoc cref="IReverseProxyService.ProxyIp"/>
public IPAddress ProxyIp { get; set; } = IPAddress.Any;
/// <inheritdoc cref="IReverseProxyService.IsSystemProxy"/>
public bool IsSystemProxy { get; set; }
/// <inheritdoc cref="IReverseProxyService.ProxyMode"/>
public ProxyMode ProxyMode { get; set; }
/// <inheritdoc cref="IReverseProxyService.IsProxyGOG"/>
public bool IsProxyGOG { get; set; }
+4 -4
View File
@@ -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())
{
@@ -17,17 +17,6 @@ namespace System.Application.Settings
[SupportedOSPlatform("Linux")]
public static SerializableProperty<bool> IsProxyGOG => _IsProxyGOG ?? throw new PlatformNotSupportedException();
static readonly SerializableProperty<bool>? _EnableWindowsProxy
= IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null;
/// <summary>
/// 启用系统代理模式
/// </summary>
[SupportedOSPlatform("Windows7.0")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Linux")]
public static SerializableProperty<bool> EnableWindowsProxy => _EnableWindowsProxy ?? throw new PlatformNotSupportedException();
static readonly SerializableProperty<bool>? _IsOnlyWorkSteamBrowser
= IApplication.IsDesktopPlatform ? GetProperty(defaultValue: false, autoSave: true) : null;
+1 -1
View File
@@ -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;
}
@@ -1,3 +1,5 @@
using System.ComponentModel;
namespace System.Application
{
/// <summary>
@@ -8,26 +10,31 @@ namespace System.Application
/// <summary>
/// 通过注入驱动实现 DNS 拦截进行代理(Windows Only)
/// </summary>
[Description("ProxyMode_DNSIntercept")]
DNSIntercept,
/// <summary>
/// 修改 Hosts 文件进行代理(Desktop Only)
/// </summary>
[Description("ProxyMode_Hosts")]
Hosts,
/// <summary>
/// 系统代理模式(Desktop Only)
/// </summary>
[Description("ProxyMode_System")]
System,
/// <summary>
/// VPN 代理模式(虚拟网卡)
/// </summary>
[Description("ProxyMode_VPN")]
VPN,
/// <summary>
/// 仅代理模式
/// </summary>
[Description("ProxyMode_ProxyOnly")]
ProxyOnly,
}
}