Compare commits

...

1 Commits

Author SHA1 Message Date
qhy040404
2f84739ccd add current proxy to feedback page 2024-01-10 00:00:25 +08:00
5 changed files with 47 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Win32.Registry;
using System.Net;
using System.Reflection;
@@ -8,7 +9,7 @@ using System.Reflection;
namespace Snap.Hutao.Core.IO.Http.DynamicProxy;
[Injection(InjectAs.Singleton)]
internal sealed partial class DynamicHttpProxy : IWebProxy, IDisposable
internal sealed partial class DynamicHttpProxy : ObservableObject, IWebProxy, IDisposable
{
private const string ProxySettingPath = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections";
@@ -32,7 +33,7 @@ internal sealed partial class DynamicHttpProxy : IWebProxy, IDisposable
{
UpdateProxy();
watcher = new(ProxySettingPath, UpdateProxy);
watcher = new(ProxySettingPath, OnProxyChanged);
watcher.Start();
}
@@ -43,6 +44,17 @@ internal sealed partial class DynamicHttpProxy : IWebProxy, IDisposable
set => InnerProxy.Credentials = value;
}
public string CurrentProxy
{
get
{
Uri? proxyUri = GetProxy("https://hut.ao".ToUri());
return proxyUri is null
? SH.ViewPageFeedbackCurrentProxyNoProxyDescription
: proxyUri.AbsoluteUri;
}
}
private IWebProxy InnerProxy
{
get => innerProxy;
@@ -60,15 +72,6 @@ internal sealed partial class DynamicHttpProxy : IWebProxy, IDisposable
}
}
[MemberNotNull(nameof(innerProxy))]
public void UpdateProxy()
{
IWebProxy? proxy = ConstructSystemProxyMethod.Invoke(default, default) as IWebProxy;
ArgumentNullException.ThrowIfNull(proxy);
InnerProxy = proxy;
}
public Uri? GetProxy(Uri destination)
{
return InnerProxy.GetProxy(destination);
@@ -84,4 +87,20 @@ internal sealed partial class DynamicHttpProxy : IWebProxy, IDisposable
(innerProxy as IDisposable)?.Dispose();
watcher.Dispose();
}
public void OnProxyChanged()
{
UpdateProxy();
Ioc.Default.GetRequiredService<ITaskContext>().InvokeOnMainThread(() => OnPropertyChanged(nameof(CurrentProxy)));
}
[MemberNotNull(nameof(innerProxy))]
private void UpdateProxy()
{
IWebProxy? proxy = ConstructSystemProxyMethod.Invoke(default, default) as IWebProxy;
ArgumentNullException.ThrowIfNull(proxy);
InnerProxy = proxy;
}
}

View File

@@ -1862,6 +1862,12 @@
<data name="ViewPageFeedbackCommonLinksHeader" xml:space="preserve">
<value>Useful Links</value>
</data>
<data name="ViewPageFeedbackCurrentProxyHeader" xml:space="preserve">
<value>Current Proxy</value>
</data>
<data name="ViewPageFeedbackCurrentProxyNoProxyDescription" xml:space="preserve">
<value>No Proxy</value>
</data>
<data name="ViewPageFeedbackEngageWithUsDescription" xml:space="preserve">
<value>Keep in touch with us</value>
</data>

View File

@@ -1862,6 +1862,12 @@
<data name="ViewPageFeedbackCommonLinksHeader" xml:space="preserve">
<value>常用链接</value>
</data>
<data name="ViewPageFeedbackCurrentProxyHeader" xml:space="preserve">
<value>当前代理</value>
</data>
<data name="ViewPageFeedbackCurrentProxyNoProxyDescription" xml:space="preserve">
<value>无代理</value>
</data>
<data name="ViewPageFeedbackEngageWithUsDescription" xml:space="preserve">
<value>与我们密切联系</value>
</data>

View File

@@ -45,6 +45,7 @@
Header="{shcm:ResourceString Name=ViewPageSettingDeviceIdHeader}"
IsClickEnabled="True"/>
<cwc:SettingsCard Description="{Binding IPInformation}" Header="{shcm:ResourceString Name=ViewPageSettingDeviceIpHeader}"/>
<cwc:SettingsCard Description="{Binding DynamicHttpProxy.CurrentProxy}" Header="{shcm:ResourceString Name=ViewPageFeedbackCurrentProxyHeader}"/>
<cwc:SettingsCard Description="{Binding RuntimeOptions.WebView2Version}" Header="{shcm:ResourceString Name=ViewPageSettingWebview2Header}"/>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>

View File

@@ -3,6 +3,7 @@
using Snap.Hutao.Core;
using Snap.Hutao.Core.IO.DataTransfer;
using Snap.Hutao.Core.IO.Http.DynamicProxy;
using Snap.Hutao.Service;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Web.Hutao;
@@ -20,6 +21,7 @@ internal sealed partial class FeedbackViewModel : Abstraction.ViewModel
private readonly HutaoInfrastructureClient hutaoInfrastructureClient;
private readonly HutaoDocumentationClient hutaoDocumentationClient;
private readonly IClipboardProvider clipboardProvider;
private readonly DynamicHttpProxy dynamicHttpProxy;
private readonly IInfoBarService infoBarService;
private readonly CultureOptions cultureOptions;
private readonly RuntimeOptions runtimeOptions;
@@ -31,6 +33,8 @@ internal sealed partial class FeedbackViewModel : Abstraction.ViewModel
public RuntimeOptions RuntimeOptions { get => runtimeOptions; }
public DynamicHttpProxy DynamicHttpProxy { get => dynamicHttpProxy; }
public string? SearchText { get => searchText; set => SetProperty(ref searchText, value); }
public List<AlgoliaHit>? SearchResults { get => searchResults; set => SetProperty(ref searchResults, value); }