mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
minor fix 5
This commit is contained in:
@@ -66,8 +66,11 @@ internal sealed partial class PeriodicInvokeCommandOrOnActualThemeChangedBehavio
|
||||
break;
|
||||
}
|
||||
|
||||
ITaskContext taskContext = Ioc.Default.GetRequiredService<ITaskContext>();
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
TryExecuteCommand();
|
||||
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
try
|
||||
{
|
||||
Task nextTickTask = timer.WaitForNextTickAsync(periodicTimerCancellationTokenSource.Token).AsTask();
|
||||
|
||||
@@ -2357,6 +2357,9 @@
|
||||
<data name="ViewPageSettingBackdropMaterialHeader" xml:space="preserve">
|
||||
<value>背景材质</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingBackgroundImageCopyrightHeader" xml:space="preserve">
|
||||
<value>图片版权信息</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingBackgroundImageDescription" xml:space="preserve">
|
||||
<value>更改窗体的背景图片来源,重启胡桃以尽快生效</value>
|
||||
</data>
|
||||
|
||||
@@ -2,11 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Snap.Hutao.Control.Media;
|
||||
using Snap.Hutao.Core;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.UI;
|
||||
|
||||
namespace Snap.Hutao.Service.BackgroundImage;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Snap.Hutao.Web.Hutao.Wallpaper;
|
||||
|
||||
namespace Snap.Hutao.Service.BackgroundImage;
|
||||
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class BackgroundImageOptions : ObservableObject
|
||||
{
|
||||
private Wallpaper? wallpaper;
|
||||
|
||||
public Wallpaper? Wallpaper { get => wallpaper; set => SetProperty(ref wallpaper, value); }
|
||||
}
|
||||
@@ -20,6 +20,7 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
{
|
||||
private static readonly HashSet<string> AllowedFormats = [".bmp", ".gif", ".ico", ".jpg", ".jpeg", ".png", ".tiff", ".webp"];
|
||||
|
||||
private readonly BackgroundImageOptions backgroundImageOptions;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
private readonly ITaskContext taskContext;
|
||||
@@ -95,6 +96,7 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
.ToHashSet();
|
||||
}
|
||||
|
||||
backgroundImageOptions.Wallpaper = default;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -116,10 +118,17 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
{
|
||||
HutaoWallpaperClient wallpaperClient = serviceProvider.GetRequiredService<HutaoWallpaperClient>();
|
||||
Response<Wallpaper> response = await responseFactory(wallpaperClient).ConfigureAwait(false);
|
||||
if (response is { Data.Url: Uri url })
|
||||
if (response is { Data: Wallpaper wallpaper })
|
||||
{
|
||||
ValueFile file = await serviceProvider.GetRequiredService<IImageCache>().GetFileFromCacheAsync(url).ConfigureAwait(false);
|
||||
currentBackgroundPathSet = [file];
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
backgroundImageOptions.Wallpaper = wallpaper;
|
||||
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
if (wallpaper.Url is { } url)
|
||||
{
|
||||
ValueFile file = await serviceProvider.GetRequiredService<IImageCache>().GetFileFromCacheAsync(url).ConfigureAwait(false);
|
||||
currentBackgroundPathSet = [file];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cw="using:CommunityToolkit.WinUI"
|
||||
xmlns:cwb="using:CommunityToolkit.WinUI.Behaviors"
|
||||
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:mxic="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:shc="using:Snap.Hutao.Control"
|
||||
xmlns:shcb="using:Snap.Hutao.Control.Behavior"
|
||||
xmlns:shch="using:Snap.Hutao.Control.Helper"
|
||||
@@ -312,17 +314,31 @@
|
||||
SelectedItem="{Binding SelectedBackdropType, Mode=TwoWay}"/>
|
||||
</shc:SizeRestrictedContentControl>
|
||||
</cwc:SettingsCard>
|
||||
<cwc:SettingsCard
|
||||
<cwc:SettingsExpander
|
||||
Description="{shcm:ResourceString Name=ViewPageSettingBackgroundImageDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageSettingBackgroundImageHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<shc:SizeRestrictedContentControl>
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}"
|
||||
IsExpanded="{Binding BackgroundImageOptions.Wallpaper, Converter={StaticResource EmptyObjectToBoolConverter}}">
|
||||
<shc:SizeRestrictedContentControl VerticalAlignment="Center">
|
||||
<ComboBox
|
||||
DisplayMemberPath="Name"
|
||||
ItemsSource="{Binding AppOptions.BackgroundImageTypes}"
|
||||
SelectedItem="{Binding SelectedBackgroundImageType, Mode=TwoWay}"/>
|
||||
</shc:SizeRestrictedContentControl>
|
||||
</cwc:SettingsCard>
|
||||
<cwc:SettingsExpander.Items>
|
||||
<cwc:SettingsCard
|
||||
Description="{Binding BackgroundImageOptions.Wallpaper.Author}"
|
||||
Header="{shcm:ResourceString Name=ViewPageSettingBackgroundImageCopyrightHeader}"
|
||||
IsClickEnabled="True"
|
||||
Visibility="{Binding BackgroundImageOptions.Wallpaper, Converter={StaticResource EmptyObjectToVisibilityConverter}}">
|
||||
<mxi:Interaction.Behaviors>
|
||||
<mxic:EventTriggerBehavior EventName="Click">
|
||||
<cwb:NavigateToUriAction NavigateUri="{Binding BackgroundImageOptions.Wallpaper.SourceUrl}"/>
|
||||
</mxic:EventTriggerBehavior>
|
||||
</mxi:Interaction.Behaviors>
|
||||
</cwc:SettingsCard>
|
||||
</cwc:SettingsExpander.Items>
|
||||
</cwc:SettingsExpander>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
@@ -41,6 +41,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
|
||||
private readonly IFileSystemPickerInteraction fileSystemPickerInteraction;
|
||||
private readonly HutaoPassportViewModel hutaoPassportViewModel;
|
||||
private readonly BackgroundImageOptions backgroundImageOptions;
|
||||
private readonly IContentDialogFactory contentDialogFactory;
|
||||
private readonly INavigationService navigationService;
|
||||
private readonly IShellLinkInterop shellLinkInterop;
|
||||
@@ -75,6 +76,8 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
|
||||
public LaunchOptions LaunchOptions { get => launchOptions; }
|
||||
|
||||
public BackgroundImageOptions BackgroundImageOptions { get => backgroundImageOptions; }
|
||||
|
||||
public HutaoPassportViewModel Passport { get => hutaoPassportViewModel; }
|
||||
|
||||
public NameValue<BackdropType>? SelectedBackdropType
|
||||
|
||||
Reference in New Issue
Block a user