code style

This commit is contained in:
Lightczx
2023-12-06 13:53:16 +08:00
parent 4dd6765e35
commit 045c127fb2
19 changed files with 100 additions and 71 deletions

View File

@@ -31,7 +31,7 @@ internal sealed partial class ExceptionRecorder
private void OnAppUnhandledException(object? sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
ValueTask<string?> task = serviceProvider
.GetRequiredService<Web.Hutao.Log.HomaLogUploadClient>()
.GetRequiredService<Web.Hutao.Log.HutaoLogUploadClient>()
.UploadLogAsync(e.Exception);
if (!task.IsCompleted)

View File

@@ -19,7 +19,7 @@ internal sealed partial class HutaoSpiralAbyssService : IHutaoSpiralAbyssService
private readonly TimeSpan cacheExpireTime = TimeSpan.FromHours(4);
private readonly IObjectCacheDbService objectCacheDbService;
private readonly HomaSpiralAbyssClient homaClient;
private readonly HutaoSpiralAbyssClient homaClient;
private readonly JsonSerializerOptions options;
private readonly IMemoryCache memoryCache;

View File

@@ -19,7 +19,6 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
private readonly TaskCompletionSource initializedTaskCompletionSource = new();
private string? userName = SH.ViewServiceHutaoUserLoginOrRegisterHint;
private string? token;
private IPInfo ipInfo = new();
private bool isLoggedIn;
private bool isHutaoCloudServiceAllowed;
private bool isLicensedDeveloper;
@@ -37,11 +36,6 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
/// </summary>
public string? ActualUserName { get => IsLoggedIn ? UserName : null; }
/// <summary>
/// 设备当前IP
/// </summary>
public IPInfo IPInfo { get => ipInfo; set => ipInfo = value; }
/// <summary>
/// 是否已登录
/// </summary>
@@ -69,7 +63,7 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
/// <inheritdoc/>
public HutaoUserOptions Value { get => this; }
public async ValueTask<bool> PostLoginSucceedAsync(HomaPassportClient passportClient, ITaskContext taskContext, string username, string password, string? token)
public async ValueTask<bool> PostLoginSucceedAsync(HutaoPassportClient passportClient, ITaskContext taskContext, string username, string password, string? token)
{
LocalSetting.Set(SettingKeys.PassportUserName, username);
LocalSetting.Set(SettingKeys.PassportPassword, password);
@@ -137,11 +131,6 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
return token;
}
public async ValueTask GetIPInfoAsync(HomaPassportClient passportClient)
{
IPInfo = await passportClient.GetIPInfoAsync().ConfigureAwait(false);
}
private void ClearUserInfo()
{
IsLicensedDeveloper = false;

View File

@@ -15,7 +15,7 @@ internal sealed partial class HutaoUserService : IHutaoUserService, IHutaoUserSe
{
private readonly TaskCompletionSource initializeCompletionSource = new();
private readonly HomaPassportClient passportClient;
private readonly HutaoPassportClient passportClient;
private readonly ITaskContext taskContext;
private readonly HutaoUserOptions options;
@@ -33,7 +33,6 @@ internal sealed partial class HutaoUserService : IHutaoUserService, IHutaoUserSe
{
string userName = LocalSetting.Get(SettingKeys.PassportUserName, string.Empty);
string password = LocalSetting.Get(SettingKeys.PassportPassword, string.Empty);
await options.GetIPInfoAsync(passportClient).ConfigureAwait(false);
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
{

View File

@@ -13,7 +13,7 @@ namespace Snap.Hutao.View.Dialog;
[DependencyProperty("VerifyCode", typeof(string))]
internal sealed partial class HutaoPassportRegisterDialog : ContentDialog
{
private readonly HomaPassportClient homaPassportClient;
private readonly HutaoPassportClient homaPassportClient;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
@@ -22,7 +22,7 @@ internal sealed partial class HutaoPassportRegisterDialog : ContentDialog
InitializeComponent();
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
homaPassportClient = serviceProvider.GetRequiredService<HomaPassportClient>();
homaPassportClient = serviceProvider.GetRequiredService<HutaoPassportClient>();
infoBarService = serviceProvider.GetRequiredService<IInfoBarService>();
}

View File

@@ -13,7 +13,7 @@ namespace Snap.Hutao.View.Dialog;
[DependencyProperty("VerifyCode", typeof(string))]
internal sealed partial class HutaoPassportResetPasswordDialog : ContentDialog
{
private readonly HomaPassportClient homaPassportClient;
private readonly HutaoPassportClient homaPassportClient;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
@@ -22,7 +22,7 @@ internal sealed partial class HutaoPassportResetPasswordDialog : ContentDialog
InitializeComponent();
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
homaPassportClient = serviceProvider.GetRequiredService<HomaPassportClient>();
homaPassportClient = serviceProvider.GetRequiredService<HutaoPassportClient>();
infoBarService = serviceProvider.GetRequiredService<IInfoBarService>();
}

View File

@@ -13,7 +13,7 @@ namespace Snap.Hutao.View.Dialog;
[DependencyProperty("VerifyCode", typeof(string))]
internal sealed partial class HutaoPassportUnregisterDialog : ContentDialog
{
private readonly HomaPassportClient homaPassportClient;
private readonly HutaoPassportClient homaPassportClient;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
@@ -22,7 +22,7 @@ internal sealed partial class HutaoPassportUnregisterDialog : ContentDialog
InitializeComponent();
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
homaPassportClient = serviceProvider.GetRequiredService<HomaPassportClient>();
homaPassportClient = serviceProvider.GetRequiredService<HutaoPassportClient>();
infoBarService = serviceProvider.GetRequiredService<IInfoBarService>();
}

View File

@@ -6,7 +6,9 @@
xmlns:cwc="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
xmlns:shc="using:Snap.Hutao.Control"
xmlns:shcb="using:Snap.Hutao.Control.Behavior"
xmlns:shch="using:Snap.Hutao.Control.Helper"
xmlns:shcm="using:Snap.Hutao.Control.Markup"
xmlns:shvc="using:Snap.Hutao.View.Control"
@@ -14,6 +16,11 @@
d:DataContext="{d:DesignInstance shvs:SettingViewModel}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<mxi:Interaction.Behaviors>
<shcb:InvokeCommandOnLoadedBehavior Command="{Binding OpenUICommand}"/>
</mxi:Interaction.Behaviors>
<ScrollViewer shch:ScrollViewerHelper.LeftPanelMaxWidth="800" Style="{StaticResource TwoPanelScrollViewerStyle}">
<shch:ScrollViewerHelper.RightPanel>
<StackPanel Width="360" Margin="0,16,16,16">
@@ -103,7 +110,7 @@
Description="{Binding HutaoOptions.DeviceId}"
Header="{shcm:ResourceString Name=ViewPageSettingDeviceIdHeader}"
IsClickEnabled="True"/>
<cwc:SettingsCard Description="{Binding UserOptions.IPInfo}" Header="{shcm:ResourceString Name=ViewPageSettingDeviceIpHeader}"/>
<cwc:SettingsCard Description="{Binding IPInformation}" Header="{shcm:ResourceString Name=ViewPageSettingDeviceIpHeader}"/>
<cwc:SettingsCard Description="{Binding HutaoOptions.WebView2Version}" Header="{shcm:ResourceString Name=ViewPageSettingWebview2Header}"/>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>

View File

@@ -19,7 +19,7 @@ namespace Snap.Hutao.ViewModel.Setting;
internal sealed partial class HutaoPassportViewModel : Abstraction.ViewModel
{
private readonly IContentDialogFactory contentDialogFactory;
private readonly HomaPassportClient homaPassportClient;
private readonly HutaoPassportClient homaPassportClient;
private readonly HutaoUserOptions hutaoUserOptions;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;

View File

@@ -23,6 +23,7 @@ using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.User;
using Snap.Hutao.View.Dialog;
using Snap.Hutao.ViewModel.Guide;
using Snap.Hutao.Web.Hutao;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
@@ -41,6 +42,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
private readonly HomeCardOptions homeCardOptions = new();
private readonly IFileSystemPickerInteraction fileSystemPickerInteraction;
private readonly HutaoInfrastructureClient hutaoInfrastructureClient;
private readonly HutaoPassportViewModel hutaoPassportViewModel;
private readonly IContentDialogFactory contentDialogFactory;
private readonly IGameLocatorFactory gameLocatorFactory;
@@ -57,6 +59,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
private NameValue<BackdropType>? selectedBackdropType;
private NameValue<CultureInfo>? selectedCulture;
private IPInformation? ipInformation;
/// <summary>
/// 应用程序设置
@@ -98,6 +101,18 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
}
}
public IPInformation? IPInformation { get => ipInformation; private set => SetProperty(ref ipInformation, value); }
protected override async ValueTask<bool> InitializeUIAsync()
{
IPInformation? information = await hutaoInfrastructureClient.GetIPInformationAsync().ConfigureAwait(false);
await taskContext.SwitchToMainThreadAsync();
IPInformation = information;
return true;
}
[Command("ResetStaticResourceCommand")]
private static void ResetStaticResource()
{

View File

@@ -24,7 +24,7 @@ namespace Snap.Hutao.ViewModel.SpiralAbyss;
internal sealed partial class SpiralAbyssRecordViewModel : Abstraction.ViewModel, IRecipient<UserChangedMessage>
{
private readonly ISpiralAbyssRecordService spiralAbyssRecordService;
private readonly HomaSpiralAbyssClient spiralAbyssClient;
private readonly HutaoSpiralAbyssClient spiralAbyssClient;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
private readonly IUserService userService;

View File

@@ -0,0 +1,31 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
using Snap.Hutao.Service.Hutao;
using Snap.Hutao.Web.Request.Builder;
using Snap.Hutao.Web.Request.Builder.Abstraction;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
namespace Snap.Hutao.Web.Hutao;
[HttpClient(HttpClientConfiguration.Default)]
[ConstructorGenerated(ResolveHttpClient = true)]
internal sealed partial class HutaoInfrastructureClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly ILogger<HutaoInfrastructureClient> logger;
private readonly HttpClient httpClient;
public async ValueTask<IPInformation> GetIPInformationAsync(CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(HutaoEndpoints.Ip)
.Get();
IPInformation? resp = await builder.TryCatchSendAsync<IPInformation>(httpClient, logger, token).ConfigureAwait(false);
return resp ?? IPInformation.Default;
}
}

View File

@@ -17,7 +17,7 @@ namespace Snap.Hutao.Web.Hutao;
[HighQuality]
[HttpClient(HttpClientConfiguration.Default)]
[ConstructorGenerated(ResolveHttpClient = true)]
internal sealed partial class HomaPassportClient
internal sealed partial class HutaoPassportClient
{
/// <summary>
/// 通行证请求公钥
@@ -35,7 +35,7 @@ internal sealed partial class HomaPassportClient
""";
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly ILogger<HomaPassportClient> logger;
private readonly ILogger<HutaoPassportClient> logger;
private readonly HutaoUserOptions hutaoUserOptions;
private readonly HttpClient httpClient;
@@ -193,17 +193,6 @@ internal sealed partial class HomaPassportClient
return HutaoResponse.DefaultIfNull(resp);
}
public async ValueTask<IPInfo> GetIPInfoAsync(CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(HutaoEndpoints.Ip)
.Get();
IPInfo? resp = await builder.TryCatchSendAsync<IPInfo>(httpClient, logger, token).ConfigureAwait(false);
return resp ?? new();
}
private static string Encrypt(string text)
{
byte[] plaintextBytes = Encoding.UTF8.GetBytes(text);
@@ -214,4 +203,4 @@ internal sealed partial class HomaPassportClient
return Convert.ToBase64String(encryptedBytes);
}
}
}
}

View File

@@ -6,7 +6,7 @@ using Snap.Hutao.Web.Request.Builder;
namespace Snap.Hutao.Web.Hutao;
internal static class HomaPassportHttpRequestMessageBuilderExtension
internal static class HutaoPassportHttpRequestMessageBuilderExtension
{
public static async ValueTask TrySetTokenAsync(this HttpRequestMessageBuilder builder, HutaoUserOptions hutaoUserOptions)
{

View File

@@ -1,24 +0,0 @@
namespace Snap.Hutao.Web.Hutao;
internal sealed class IPInfo
{
public IPInfo()
{
}
[JsonConstructor]
public IPInfo(string ip, string division)
{
Ip = ip;
Division = division;
}
public string Ip { get; set; } = "Unknown";
public string Division { get; set; } = "Unknown";
public override string ToString()
{
return SH.FormatViewPageSettingDeviceIpDescription(Ip, Division);
}
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hutao;
internal sealed class IPInformation
{
public static IPInformation Default { get; } = new()
{
Ip = "Unknown",
Division = "Unknown"
};
[JsonPropertyName("ip")]
public string Ip { get; set; } = default!;
[JsonPropertyName("division")]
public string Division { get; set; } = default!;
public override string ToString()
{
return SH.FormatViewPageSettingDeviceIpDescription(Ip, Division);
}
}

View File

@@ -16,10 +16,10 @@ namespace Snap.Hutao.Web.Hutao.Log;
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class HomaLogUploadClient
internal sealed partial class HutaoLogUploadClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly ILogger<HomaLogUploadClient> logger;
private readonly ILogger<HutaoLogUploadClient> logger;
private readonly RuntimeOptions runtimeOptions;
private readonly HttpClient httpClient;

View File

@@ -22,10 +22,10 @@ namespace Snap.Hutao.Web.Hutao.SpiralAbyss;
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class HomaSpiralAbyssClient
internal sealed partial class HutaoSpiralAbyssClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly ILogger<HomaSpiralAbyssClient> logger;
private readonly ILogger<HutaoSpiralAbyssClient> logger;
private readonly IServiceProvider serviceProvider;
private readonly HttpClient httpClient;

View File

@@ -11,7 +11,6 @@ namespace Snap.Hutao.Web;
/// </summary>
[HighQuality]
[SuppressMessage("", "SA1201")]
[SuppressMessage("", "SA1203")]
[SuppressMessage("", "SA1124")]
internal static class HutaoEndpoints
{
@@ -23,8 +22,6 @@ internal static class HutaoEndpoints
public const string AnnouncementUpload = $"{HomaSnapGenshinApi}/Service/Announcement/Upload";
public const string Ip = $"{ApiSnapGenshin}/ip";
public static string GachaLogCompensation(int days)
{
return $"{HomaSnapGenshinApi}/Service/GachaLog/Compensation?days={days}";
@@ -251,6 +248,8 @@ internal static class HutaoEndpoints
}
#endregion
public const string Ip = $"{ApiSnapGenshin}/ip";
public static string Website(string path)
{
return $"{HomaSnapGenshinApi}/{path}";