mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
@@ -23,10 +23,12 @@ internal static class ControlAnimationConstants
|
||||
/// <summary>
|
||||
/// 图像淡入
|
||||
/// </summary>
|
||||
public static readonly TimeSpan ImageFadeIn = TimeSpan.FromSeconds(0.3);
|
||||
public static readonly TimeSpan ImageScaleFadeIn = TimeSpan.FromSeconds(0.3);
|
||||
|
||||
/// <summary>
|
||||
/// 图像淡出
|
||||
/// </summary>
|
||||
public static readonly TimeSpan ImageFadeOut = TimeSpan.FromSeconds(0.2);
|
||||
public static readonly TimeSpan ImageScaleFadeOut = TimeSpan.FromSeconds(0.2);
|
||||
|
||||
public static readonly TimeSpan ImageOpacityFadeInOut = TimeSpan.FromSeconds(1);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Behaviors;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.Control.Behavior;
|
||||
|
||||
[DependencyProperty("Period", typeof(TimeSpan))]
|
||||
[DependencyProperty("Command", typeof(ICommand))]
|
||||
[DependencyProperty("CommandParameter", typeof(object))]
|
||||
internal sealed partial class PeriodicInvokeCommandOrOnActualThemeChangedBehavior : BehaviorBase<FrameworkElement>, IDisposable
|
||||
{
|
||||
private TaskCompletionSource acutalThemeChangedTaskCompletionSource = new();
|
||||
private CancellationTokenSource periodicTimerCancellationTokenSource = new();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
periodicTimerCancellationTokenSource.Dispose();
|
||||
}
|
||||
|
||||
protected override bool Initialize()
|
||||
{
|
||||
AssociatedObject.ActualThemeChanged += OnActualThemeChanged;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
{
|
||||
RunCoreAsync().SafeForget();
|
||||
}
|
||||
|
||||
protected override bool Uninitialize()
|
||||
{
|
||||
AssociatedObject.ActualThemeChanged -= OnActualThemeChanged;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnActualThemeChanged(FrameworkElement sender, object args)
|
||||
{
|
||||
acutalThemeChangedTaskCompletionSource.TrySetResult();
|
||||
periodicTimerCancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
private void TryExecuteCommand()
|
||||
{
|
||||
if (AssociatedObject is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Command is not null && Command.CanExecute(CommandParameter))
|
||||
{
|
||||
Command.Execute(CommandParameter);
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask RunCoreAsync()
|
||||
{
|
||||
using (PeriodicTimer timer = new(Period))
|
||||
{
|
||||
do
|
||||
{
|
||||
if (!IsAttached)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
TryExecuteCommand();
|
||||
|
||||
try
|
||||
{
|
||||
Task nextTickTask = timer.WaitForNextTickAsync(periodicTimerCancellationTokenSource.Token).AsTask();
|
||||
await Task.WhenAny(nextTickTask, acutalThemeChangedTaskCompletionSource.Task).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
acutalThemeChangedTaskCompletionSource = new();
|
||||
periodicTimerCancellationTokenSource = new();
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ internal abstract partial class CompositionImage : Microsoft.UI.Xaml.Controls.Co
|
||||
{
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
.Opacity(from: 0D, to: 1D, duration: ControlAnimationConstants.ImageFadeIn)
|
||||
.Opacity(from: 0D, to: 1D, duration: ControlAnimationConstants.ImageScaleFadeIn)
|
||||
.StartAsync(this, token)
|
||||
.ConfigureAwait(true);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ internal abstract partial class CompositionImage : Microsoft.UI.Xaml.Controls.Co
|
||||
{
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
.Opacity(from: 1D, to: 0D, duration: ControlAnimationConstants.ImageFadeOut)
|
||||
.Opacity(from: 1D, to: 0D, duration: ControlAnimationConstants.ImageScaleFadeOut)
|
||||
.StartAsync(this, token)
|
||||
.ConfigureAwait(true);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,16 @@ internal static class CollectionsNameValue
|
||||
return [.. Enum.GetValues<TEnum>().Select(x => new NameValue<TEnum>(x.ToString(), x))];
|
||||
}
|
||||
|
||||
public static List<NameValue<TEnum>> FromEnum<TEnum>(Func<TEnum, bool> codiction)
|
||||
public static List<NameValue<TEnum>> FromEnum<TEnum>(Func<TEnum, bool> condition)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
return [.. Enum.GetValues<TEnum>().Where(codiction).Select(x => new NameValue<TEnum>(x.ToString(), x))];
|
||||
return [.. Enum.GetValues<TEnum>().Where(condition).Select(x => new NameValue<TEnum>(x.ToString(), x))];
|
||||
}
|
||||
|
||||
public static List<NameValue<TEnum>> FromEnum<TEnum>(Func<TEnum, string> nameSelector)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
return [.. Enum.GetValues<TEnum>().Select(x => new NameValue<TEnum>(nameSelector(x), x))];
|
||||
}
|
||||
|
||||
public static List<NameValue<TSource>> From<TSource>(IEnumerable<TSource> sources, Func<TSource, string> nameSelector)
|
||||
|
||||
@@ -767,6 +767,21 @@
|
||||
<data name="ServiceAvatarInfoSummaryShowcaseRefreshTimeFormat" xml:space="preserve">
|
||||
<value>角色橱窗:{0:MM-dd HH:mm}</value>
|
||||
</data>
|
||||
<data name="ServiceBackgroundImageTypeBing" xml:space="preserve">
|
||||
<value>必应每日一图</value>
|
||||
</data>
|
||||
<data name="ServiceBackgroundImageTypeDaily" xml:space="preserve">
|
||||
<value>胡桃每日一图</value>
|
||||
</data>
|
||||
<data name="ServiceBackgroundImageTypeLauncher" xml:space="preserve">
|
||||
<value>官方启动器壁纸</value>
|
||||
</data>
|
||||
<data name="ServiceBackgroundImageTypeLocalFolder" xml:space="preserve">
|
||||
<value>本地随机图片</value>
|
||||
</data>
|
||||
<data name="ServiceBackgroundImageTypeNone" xml:space="preserve">
|
||||
<value>无背景图片</value>
|
||||
</data>
|
||||
<data name="ServiceCultivationProjectCurrentUserdataCourrpted" xml:space="preserve">
|
||||
<value>保存养成计划状态失败</value>
|
||||
</data>
|
||||
@@ -2339,6 +2354,12 @@
|
||||
<data name="ViewPageSettingBackdropMaterialHeader" xml:space="preserve">
|
||||
<value>背景材质</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingBackgroundImageDescription" xml:space="preserve">
|
||||
<value>更改窗体的背景图片来源,重启胡桃以尽快生效</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingBackgroundImageHeader" xml:space="preserve">
|
||||
<value>背景图片</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingCacheFolderDescription" xml:space="preserve">
|
||||
<value>图片缓存 在此处存放</value>
|
||||
</data>
|
||||
|
||||
@@ -34,6 +34,8 @@ internal sealed partial class AppOptions : DbStoreOptions
|
||||
set => SetOption(ref backdropType, SettingEntry.SystemBackdropType, value, EnumToStringOrEmpty);
|
||||
}
|
||||
|
||||
public List<NameValue<BackgroundImageType>> BackgroundImageTypes { get; } = CollectionsNameValue.FromEnum<BackgroundImageType>(type => type.GetLocalizedDescription());
|
||||
|
||||
public BackgroundImageType BackgroundImageType
|
||||
{
|
||||
get => GetOption(ref backgroundImageType, SettingEntry.BackgroundImageType, EnumParse<BackgroundImageType>, BackgroundImageType.HutaoOfficialLauncher).Value;
|
||||
|
||||
@@ -5,9 +5,7 @@ using Snap.Hutao.Control.Media;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.Caching;
|
||||
using Snap.Hutao.Core.IO;
|
||||
using Snap.Hutao.Service.Game.Scheme;
|
||||
using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
|
||||
using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content;
|
||||
using Snap.Hutao.Web.Hutao.Wallpaper;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.IO;
|
||||
using Windows.Graphics.Imaging;
|
||||
@@ -23,8 +21,9 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly AppOptions appOptions;
|
||||
|
||||
private HashSet<string> backgroundPathSet;
|
||||
private HashSet<string> currentBackgroundPathSet;
|
||||
|
||||
public async ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync(BackgroundImage? previous)
|
||||
{
|
||||
@@ -35,7 +34,7 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
return new(false, default!);
|
||||
}
|
||||
|
||||
string path = System.Random.Shared.GetItems(backgroundSet.ToArray(), 1)[0];
|
||||
string path = System.Random.Shared.GetItems([..backgroundSet], 1)[0];
|
||||
backgroundSet.Remove(path);
|
||||
|
||||
if (string.Equals(path, previous?.Path, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -65,32 +64,47 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
|
||||
private async ValueTask<HashSet<string>> SkipOrInitBackgroundAsync()
|
||||
{
|
||||
if (backgroundPathSet is not { Count: > 0 })
|
||||
switch (appOptions.BackgroundImageType)
|
||||
{
|
||||
string backgroundFolder = runtimeOptions.GetDataFolderBackgroundFolder();
|
||||
Directory.CreateDirectory(backgroundFolder);
|
||||
backgroundPathSet = Directory
|
||||
.GetFiles(backgroundFolder, "*.*", SearchOption.AllDirectories)
|
||||
.Where(path => AllowedFormats.Contains(Path.GetExtension(path)))
|
||||
.ToHashSet();
|
||||
|
||||
// No image found
|
||||
if (backgroundPathSet.Count <= 0)
|
||||
{
|
||||
ResourceClient resourceClient = serviceProvider.GetRequiredService<ResourceClient>();
|
||||
string launguageCode = serviceProvider.GetRequiredService<CultureOptions>().LanguageCode;
|
||||
LaunchScheme scheme = launguageCode is "zh-cn"
|
||||
? KnownLaunchSchemes.Get().First(scheme => !scheme.IsOversea && scheme.IsNotCompatOnly)
|
||||
: KnownLaunchSchemes.Get().First(scheme => scheme.IsOversea && scheme.IsNotCompatOnly);
|
||||
Response<GameContent> response = await resourceClient.GetContentAsync(scheme, launguageCode).ConfigureAwait(false);
|
||||
if (response is { Data.Advertisement.Background: string url })
|
||||
case BackgroundImageType.LocalFolder:
|
||||
{
|
||||
ValueFile file = await serviceProvider.GetRequiredService<IImageCache>().GetFileFromCacheAsync(url.ToUri()).ConfigureAwait(false);
|
||||
backgroundPathSet = [file];
|
||||
if (currentBackgroundPathSet is not { Count: > 0 })
|
||||
{
|
||||
string backgroundFolder = runtimeOptions.GetDataFolderBackgroundFolder();
|
||||
Directory.CreateDirectory(backgroundFolder);
|
||||
|
||||
currentBackgroundPathSet = Directory
|
||||
.GetFiles(backgroundFolder, "*.*", SearchOption.AllDirectories)
|
||||
.Where(path => AllowedFormats.Contains(Path.GetExtension(path)))
|
||||
.ToHashSet();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case BackgroundImageType.HutaoBing:
|
||||
await SetCurrentBackgroundPathSetAsync(client => client.GetBingWallpaperAsync()).ConfigureAwait(false);
|
||||
break;
|
||||
case BackgroundImageType.HutaoDaily:
|
||||
await SetCurrentBackgroundPathSetAsync(client => client.GetTodayWallpaperAsync()).ConfigureAwait(false);
|
||||
break;
|
||||
case BackgroundImageType.HutaoOfficialLauncher:
|
||||
await SetCurrentBackgroundPathSetAsync(client => client.GetLauncherWallpaperAsync()).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return backgroundPathSet;
|
||||
currentBackgroundPathSet ??= [];
|
||||
return currentBackgroundPathSet;
|
||||
|
||||
async Task SetCurrentBackgroundPathSetAsync(Func<HutaoWallpaperClient, ValueTask<Response<Wallpaper>>> responseFactory)
|
||||
{
|
||||
HutaoWallpaperClient wallpaperClient = serviceProvider.GetRequiredService<HutaoWallpaperClient>();
|
||||
Response<Wallpaper> response = await responseFactory(wallpaperClient).ConfigureAwait(false);
|
||||
if (response is { Data.Url: Uri url })
|
||||
{
|
||||
ValueFile file = await serviceProvider.GetRequiredService<IImageCache>().GetFileFromCacheAsync(url).ConfigureAwait(false);
|
||||
currentBackgroundPathSet = [file];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,21 @@
|
||||
|
||||
namespace Snap.Hutao.Service.BackgroundImage;
|
||||
|
||||
[Localization]
|
||||
internal enum BackgroundImageType
|
||||
{
|
||||
[LocalizationKey(nameof(SH.ServiceBackgroundImageTypeNone))]
|
||||
None,
|
||||
|
||||
[LocalizationKey(nameof(SH.ServiceBackgroundImageTypeLocalFolder))]
|
||||
LocalFolder,
|
||||
|
||||
[LocalizationKey(nameof(SH.ServiceBackgroundImageTypeBing))]
|
||||
HutaoBing,
|
||||
|
||||
[LocalizationKey(nameof(SH.ServiceBackgroundImageTypeDaily))]
|
||||
HutaoDaily,
|
||||
|
||||
[LocalizationKey(nameof(SH.ServiceBackgroundImageTypeLauncher))]
|
||||
HutaoOfficialLauncher,
|
||||
}
|
||||
@@ -4,12 +4,24 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
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:shcb="using:Snap.Hutao.Control.Behavior"
|
||||
xmlns:shch="using:Snap.Hutao.Control.Helper"
|
||||
xmlns:shcm="using:Snap.Hutao.Control.Markup"
|
||||
xmlns:shv="using:Snap.Hutao.View"
|
||||
xmlns:shvh="using:Snap.Hutao.View.Helper"
|
||||
xmlns:shvm="using:Snap.Hutao.ViewModel"
|
||||
xmlns:shvp="using:Snap.Hutao.View.Page"
|
||||
d:DataContext="{d:DesignInstance Type=shvm:MainViewModel}"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<mxi:Interaction.Behaviors>
|
||||
<shcb:PeriodicInvokeCommandOrOnActualThemeChangedBehavior
|
||||
Command="{Binding UpdateBackgroundCommand}"
|
||||
CommandParameter="{x:Bind BackdroundImagePresenter}"
|
||||
Period="0:5:0"/>
|
||||
</mxi:Interaction.Behaviors>
|
||||
|
||||
<UserControl.Resources>
|
||||
<Thickness x:Key="NavigationViewContentMargin">0,44,0,0</Thickness>
|
||||
<Thickness x:Key="NavigationViewContentGridBorderThickness">0,1,0,0</Thickness>
|
||||
|
||||
@@ -5,10 +5,12 @@ using CommunityToolkit.WinUI.Animations;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Snap.Hutao.Control.Animation;
|
||||
using Snap.Hutao.Control.Theme;
|
||||
using Snap.Hutao.Service.BackgroundImage;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Snap.Hutao.View.Page;
|
||||
using Snap.Hutao.ViewModel;
|
||||
|
||||
namespace Snap.Hutao.View;
|
||||
|
||||
@@ -19,80 +21,23 @@ namespace Snap.Hutao.View;
|
||||
internal sealed partial class MainView : UserControl
|
||||
{
|
||||
private readonly INavigationService navigationService;
|
||||
private readonly IBackgroundImageService backgroundImageService;
|
||||
private TaskCompletionSource acutalThemeChangedTaskCompletionSource = new();
|
||||
private CancellationTokenSource periodicTimerCancellationTokenSource = new();
|
||||
private BackgroundImage? previousBackgroundImage;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的主视图
|
||||
/// </summary>
|
||||
public MainView()
|
||||
{
|
||||
DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
|
||||
InitializeComponent();
|
||||
|
||||
ActualThemeChanged += OnActualThemeChanged;
|
||||
|
||||
IServiceProvider serviceProvider = Ioc.Default;
|
||||
|
||||
backgroundImageService = serviceProvider.GetRequiredService<IBackgroundImageService>();
|
||||
RunBackgroundImageLoopAsync(serviceProvider.GetRequiredService<ITaskContext>()).SafeForget();
|
||||
|
||||
navigationService = serviceProvider.GetRequiredService<INavigationService>();
|
||||
navigationService
|
||||
.As<INavigationInitialization>()?
|
||||
.Initialize(NavView, ContentFrame);
|
||||
if (navigationService is INavigationInitialization navigationInitialization)
|
||||
{
|
||||
navigationInitialization.Initialize(NavView, ContentFrame);
|
||||
}
|
||||
|
||||
navigationService.Navigate<AnnouncementPage>(INavigationAwaiter.Default, true);
|
||||
}
|
||||
|
||||
private async ValueTask RunBackgroundImageLoopAsync(ITaskContext taskContext)
|
||||
{
|
||||
using (PeriodicTimer timer = new(TimeSpan.FromMinutes(5)))
|
||||
{
|
||||
do
|
||||
{
|
||||
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
||||
|
||||
if (isOk)
|
||||
{
|
||||
previousBackgroundImage = backgroundImage;
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
.Opacity(to: 0D, duration: TimeSpan.FromMilliseconds(1000), easingType: EasingType.Sine, easingMode: EasingMode.EaseIn)
|
||||
.StartAsync(BackdroundImagePresenter)
|
||||
.ConfigureAwait(true);
|
||||
|
||||
BackdroundImagePresenter.Source = backgroundImage.ImageSource;
|
||||
double targetOpacity = ThemeHelper.IsDarkMode(ActualTheme) ? 1 - backgroundImage.Luminance : backgroundImage.Luminance;
|
||||
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
.Opacity(to: targetOpacity, duration: TimeSpan.FromMilliseconds(1000), easingType: EasingType.Sine, easingMode: EasingMode.EaseOut)
|
||||
.StartAsync(BackdroundImagePresenter)
|
||||
.ConfigureAwait(true);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAny(timer.WaitForNextTickAsync(periodicTimerCancellationTokenSource.Token).AsTask(), acutalThemeChangedTaskCompletionSource.Task).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
acutalThemeChangedTaskCompletionSource = new();
|
||||
periodicTimerCancellationTokenSource = new();
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnActualThemeChanged(FrameworkElement frameworkElement, object args)
|
||||
{
|
||||
acutalThemeChangedTaskCompletionSource.TrySetResult();
|
||||
periodicTimerCancellationTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
@@ -312,6 +312,17 @@
|
||||
SelectedItem="{Binding SelectedBackdropType, Mode=TwoWay}"/>
|
||||
</shc:SizeRestrictedContentControl>
|
||||
</cwc:SettingsCard>
|
||||
<cwc:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageSettingBackgroundImageDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageSettingBackgroundImageHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<shc:SizeRestrictedContentControl>
|
||||
<ComboBox
|
||||
DisplayMemberPath="Name"
|
||||
ItemsSource="{Binding AppOptions.BackgroundImageTypes}"
|
||||
SelectedItem="{Binding SelectedBackgroundImageType, Mode=TwoWay}"/>
|
||||
</shc:SizeRestrictedContentControl>
|
||||
</cwc:SettingsCard>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
56
src/Snap.Hutao/Snap.Hutao/ViewModel/MainViewModel.cs
Normal file
56
src/Snap.Hutao/Snap.Hutao/ViewModel/MainViewModel.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Animations;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Snap.Hutao.Control.Animation;
|
||||
using Snap.Hutao.Control.Theme;
|
||||
using Snap.Hutao.Service.BackgroundImage;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class MainViewModel : Abstraction.ViewModel
|
||||
{
|
||||
private readonly IBackgroundImageService backgroundImageService;
|
||||
private readonly ITaskContext taskContext;
|
||||
|
||||
private BackgroundImage? previousBackgroundImage;
|
||||
|
||||
[Command("UpdateBackgroundCommand")]
|
||||
private async Task UpdateBackgroundAsync(Image presenter)
|
||||
{
|
||||
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
||||
|
||||
if (isOk)
|
||||
{
|
||||
previousBackgroundImage = backgroundImage;
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
.Opacity(
|
||||
to: 0D,
|
||||
duration: ControlAnimationConstants.ImageOpacityFadeInOut,
|
||||
easingType: EasingType.Quartic,
|
||||
easingMode: EasingMode.EaseInOut)
|
||||
.StartAsync(presenter)
|
||||
.ConfigureAwait(true);
|
||||
|
||||
presenter.Source = backgroundImage.ImageSource;
|
||||
double targetOpacity = ThemeHelper.IsDarkMode(presenter.ActualTheme) ? 1 - backgroundImage.Luminance : backgroundImage.Luminance;
|
||||
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
.Opacity(
|
||||
to: targetOpacity,
|
||||
duration: ControlAnimationConstants.ImageOpacityFadeInOut,
|
||||
easingType: EasingType.Quartic,
|
||||
easingMode: EasingMode.EaseInOut)
|
||||
.StartAsync(presenter)
|
||||
.ConfigureAwait(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Factory.Picker;
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Service;
|
||||
using Snap.Hutao.Service.BackgroundImage;
|
||||
using Snap.Hutao.Service.GachaLog.QueryProvider;
|
||||
using Snap.Hutao.Service.Game;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
@@ -54,6 +55,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
private readonly AppOptions appOptions;
|
||||
|
||||
private NameValue<BackdropType>? selectedBackdropType;
|
||||
private NameValue<BackgroundImageType>? selectedBackgroundImageType;
|
||||
private NameValue<CultureInfo>? selectedCulture;
|
||||
private NameValue<Region>? selectedRegion;
|
||||
private FolderViewModel? cacheFolderView;
|
||||
@@ -87,6 +89,18 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public NameValue<BackgroundImageType>? SelectedBackgroundImageType
|
||||
{
|
||||
get => selectedBackgroundImageType ??= AppOptions.BackgroundImageTypes.Single(t => t.Value == AppOptions.BackgroundImageType);
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref selectedBackgroundImageType, value) && value is not null)
|
||||
{
|
||||
AppOptions.BackgroundImageType = value.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NameValue<CultureInfo>? SelectedCulture
|
||||
{
|
||||
get => selectedCulture ??= CultureOptions.GetCurrentCultureForSelectionOrDefault();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Snap.Hutao.Web.Hutao.Wallpaper;
|
||||
internal sealed class Wallpaper
|
||||
{
|
||||
[JsonPropertyName("url")]
|
||||
public string Url { get; set; } = default!;
|
||||
public Uri Url { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("source_url")]
|
||||
public string SourceUrl { get; set; } = default!;
|
||||
|
||||
Reference in New Issue
Block a user