update static resource setting

This commit is contained in:
Lightczx
2024-04-12 16:52:54 +08:00
parent 59c03c7f3b
commit 6b031e1866
8 changed files with 100 additions and 15 deletions

View File

@@ -1382,6 +1382,9 @@
<data name="ViewGachaLogHeader" xml:space="preserve">
<value>祈愿记录</value>
</data>
<data name="ViewGuideStaticResourceDownloadSize" xml:space="preserve">
<value>预计下载大小:{0}</value>
</data>
<data name="ViewGuideStepAgreementIHaveReadText" xml:space="preserve">
<value>我已阅读并同意</value>
</data>
@@ -1440,10 +1443,10 @@
<value>图片资源包体</value>
</data>
<data name="ViewGuideStepStaticResourceSettingMinimumOff" xml:space="preserve">
<value>全部资源(节省 0% 磁盘空间占用)</value>
<value>完整包体</value>
</data>
<data name="ViewGuideStepStaticResourceSettingMinimumOn" xml:space="preserve">
<value>部分资源(节省 13.5% 磁盘空间占用)</value>
<value>精简包体</value>
</data>
<data name="ViewGuideStepStaticResourceSettingQualityHeader" xml:space="preserve">
<value>图片资源质量</value>
@@ -1638,10 +1641,10 @@
<value>下载资源文件中,请稍候</value>
</data>
<data name="ViewModelGuideStaticResourceQualityHigh" xml:space="preserve">
<value>高质量(节省 72.8% 磁盘空间占用)</value>
<value>高质量</value>
</data>
<data name="ViewModelGuideStaticResourceQualityRaw" xml:space="preserve">
<value>原图(节省 0% 磁盘空间占用)</value>
<value>原图</value>
</data>
<data name="ViewModelHutaoPassportEmailNotValidHint" xml:space="preserve">
<value>请输入正确的邮箱</value>

View File

@@ -227,6 +227,8 @@
IsOn="{Binding StaticResourceOptions.UseTrimmedArchive, Mode=TwoWay}"
OffContent="{shcm:ResourceString Name=ViewGuideStepStaticResourceSettingMinimumOff}"
OnContent="{shcm:ResourceString Name=ViewGuideStepStaticResourceSettingMinimumOn}"/>
<TextBlock Margin="0,16,0,0" Text="{Binding StaticResourceOptions.SizeInformationText, Mode=OneWay}"/>
</StackPanel>
<TextBlock

View File

@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Control.Extension;
using Snap.Hutao.ViewModel.Guide;
namespace Snap.Hutao.View.Guide;
@@ -14,6 +15,6 @@ internal sealed partial class GuideView : UserControl
public GuideView()
{
InitializeComponent();
DataContext = Ioc.Default.GetRequiredService<GuideViewModel>();
DataContext = this.ServiceProvider().GetRequiredService<GuideViewModel>();
}
}

View File

@@ -7,6 +7,8 @@ using Snap.Hutao.Core.Setting;
using Snap.Hutao.Model;
using Snap.Hutao.Service;
using Snap.Hutao.Web.Hoyolab;
using Snap.Hutao.Web.Hutao;
using Snap.Hutao.Web.Hutao.Response;
using System.Collections.ObjectModel;
using System.Globalization;
@@ -164,6 +166,19 @@ internal sealed partial class GuideViewModel : Abstraction.ViewModel
set => SetProperty(ref downloadSummaries, value);
}
protected override async ValueTask<bool> InitializeUIAsync()
{
HutaoInfrastructureClient hutaoInfrastructureClient = serviceProvider.GetRequiredService<HutaoInfrastructureClient>();
HutaoResponse<StaticResourceSizeInformation> response = await hutaoInfrastructureClient.GetStaticSizeAsync().ConfigureAwait(false);
if (response.IsOk())
{
await taskContext.SwitchToMainThreadAsync();
StaticResourceOptions.SizeInformation = response.Data;
}
return true;
}
[Command("NextOrCompleteCommand")]
private void NextOrComplete()
{

View File

@@ -1,34 +1,34 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.Common;
using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Model;
using Snap.Hutao.Web.Hutao;
namespace Snap.Hutao.ViewModel.Guide;
[Injection(InjectAs.Singleton)]
internal sealed class StaticResourceOptions
internal sealed class StaticResourceOptions : ObservableObject
{
private readonly List<NameValue<StaticResourceQuality>> imageQualities = CollectionsNameValue.FromEnum<StaticResourceQuality>(q => q.GetLocalizedDescription());
private NameValue<StaticResourceQuality>? imageQuality;
public StaticResourceOptions()
{
ImageQuality = ImageQualities.First(q => q.Value == UnsafeLocalSetting.Get(SettingKeys.StaticResourceImageQuality, StaticResourceQuality.Raw));
}
private string? sizeInformationText;
private StaticResourceSizeInformation? sizeInformation;
public List<NameValue<StaticResourceQuality>> ImageQualities { get => imageQualities; }
public NameValue<StaticResourceQuality>? ImageQuality
{
get => imageQuality;
get => imageQuality ??= ImageQualities.First(q => q.Value == UnsafeLocalSetting.Get(SettingKeys.StaticResourceImageQuality, StaticResourceQuality.Raw));
set
{
if (value is not null)
if (SetProperty(ref imageQuality, value) && value is not null)
{
imageQuality = value;
UnsafeLocalSetting.Set(SettingKeys.StaticResourceImageQuality, value.Value);
UpdateSizeInformationText();
}
}
}
@@ -36,6 +36,39 @@ internal sealed class StaticResourceOptions
public bool UseTrimmedArchive
{
get => LocalSetting.Get(SettingKeys.StaticResourceUseTrimmedArchive, false);
set => LocalSetting.Set(SettingKeys.StaticResourceUseTrimmedArchive, value);
set
{
LocalSetting.Set(SettingKeys.StaticResourceUseTrimmedArchive, value);
UpdateSizeInformationText();
}
}
public StaticResourceSizeInformation? SizeInformation
{
get => sizeInformation;
set
{
sizeInformation = value;
UpdateSizeInformationText();
}
}
public string? SizeInformationText { get => sizeInformationText; set => SetProperty(ref sizeInformationText, value); }
private void UpdateSizeInformationText()
{
if (SizeInformation is not null)
{
long result = (ImageQuality?.Value, UseTrimmedArchive) switch
{
(StaticResourceQuality.Raw, false) => SizeInformation.RawFull,
(StaticResourceQuality.Raw, true) => SizeInformation.RawMinimum,
(StaticResourceQuality.High, false) => SizeInformation.HighFull,
(StaticResourceQuality.High, true) => SizeInformation.HighMinimum,
_ => 0,
};
SizeInformationText = SH.FormatViewGuideStaticResourceDownloadSize(Converters.ToFileSizeString(result));
}
}
}

View File

@@ -17,6 +17,16 @@ internal sealed partial class HutaoInfrastructureClient
private readonly ILogger<HutaoInfrastructureClient> logger;
private readonly HttpClient httpClient;
public async ValueTask<HutaoResponse<StaticResourceSizeInformation>> GetStaticSizeAsync(CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(HutaoEndpoints.StaticSize)
.Get();
HutaoResponse<StaticResourceSizeInformation>? resp = await builder.TryCatchSendAsync<HutaoResponse<StaticResourceSizeInformation>>(httpClient, logger, token).ConfigureAwait(false);
return Web.Response.Response.DefaultIfNull(resp);
}
public async ValueTask<HutaoResponse<IPInformation>> GetIPInformationAsync(CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()

View File

@@ -0,0 +1,19 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hutao;
internal sealed partial class StaticResourceSizeInformation
{
[JsonPropertyName("raw_full")]
public long RawFull { get; set; }
[JsonPropertyName("raw_minimum")]
public long RawMinimum { get; set; }
[JsonPropertyName("tiny_full")]
public long HighFull { get; set; }
[JsonPropertyName("tiny_minimum")]
public long HighMinimum { get; set; }
}

View File

@@ -270,6 +270,8 @@ internal static class HutaoEndpoints
{
return $"{ApiSnapGenshinStaticZip}/{fileName}.zip";
}
public const string StaticSize = $"{ApiSnapGenshin}/static/size";
#endregion
#region Wallpaper