mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
real time refresh background
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (c) DGP Studio. All rights reserved.
|
||||||
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
|
namespace Snap.Hutao.Message;
|
||||||
|
|
||||||
|
internal sealed class BackgroundImageTypeChangedMessage
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<mxi:Interaction.Behaviors>
|
<mxi:Interaction.Behaviors>
|
||||||
<shcb:PeriodicInvokeCommandOrOnActualThemeChangedBehavior
|
<shcb:PeriodicInvokeCommandOrOnActualThemeChangedBehavior
|
||||||
Command="{Binding UpdateBackgroundCommand}"
|
Command="{Binding UpdateBackgroundCommand}"
|
||||||
CommandParameter="{x:Bind BackdroundImagePresenter}"
|
CommandParameter="{x:Bind BackgroundImagePresenter}"
|
||||||
Period="0:5:0"/>
|
Period="0:5:0"/>
|
||||||
</mxi:Interaction.Behaviors>
|
</mxi:Interaction.Behaviors>
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<!-- Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" -->
|
<!-- Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" -->
|
||||||
<Grid Transitions="{ThemeResource EntranceThemeTransitions}">
|
<Grid Transitions="{ThemeResource EntranceThemeTransitions}">
|
||||||
<Image
|
<Image
|
||||||
x:Name="BackdroundImagePresenter"
|
x:Name="BackgroundImagePresenter"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Opacity="0"
|
Opacity="0"
|
||||||
|
|||||||
@@ -27,10 +27,14 @@ internal sealed partial class MainView : UserControl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public MainView()
|
public MainView()
|
||||||
{
|
{
|
||||||
DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
|
IServiceProvider serviceProvider = Ioc.Default;
|
||||||
|
|
||||||
|
MainViewModel mainViewModel = serviceProvider.GetRequiredService<MainViewModel>();
|
||||||
|
|
||||||
|
DataContext = mainViewModel;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
IServiceProvider serviceProvider = Ioc.Default;
|
mainViewModel.Initialize(BackgroundImagePresenter);
|
||||||
|
|
||||||
navigationService = serviceProvider.GetRequiredService<INavigationService>();
|
navigationService = serviceProvider.GetRequiredService<INavigationService>();
|
||||||
if (navigationService is INavigationInitialization navigationInitialization)
|
if (navigationService is INavigationInitialization navigationInitialization)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (c) DGP Studio. All rights reserved.
|
||||||
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
|
namespace Snap.Hutao.ViewModel.Main;
|
||||||
|
|
||||||
|
internal interface IMainViewModelInitialization
|
||||||
|
{
|
||||||
|
void Initialize(Image backgroundImagePresenter);
|
||||||
|
}
|
||||||
@@ -1,23 +1,37 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
// Copyright (c) DGP Studio. All rights reserved.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using CommunityToolkit.WinUI.Animations;
|
using CommunityToolkit.WinUI.Animations;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media.Animation;
|
using Microsoft.UI.Xaml.Media.Animation;
|
||||||
using Snap.Hutao.Control.Animation;
|
using Snap.Hutao.Control.Animation;
|
||||||
using Snap.Hutao.Control.Theme;
|
using Snap.Hutao.Control.Theme;
|
||||||
|
using Snap.Hutao.Message;
|
||||||
using Snap.Hutao.Service.BackgroundImage;
|
using Snap.Hutao.Service.BackgroundImage;
|
||||||
|
using Snap.Hutao.ViewModel.Main;
|
||||||
|
|
||||||
namespace Snap.Hutao.ViewModel;
|
namespace Snap.Hutao.ViewModel;
|
||||||
|
|
||||||
[ConstructorGenerated]
|
[ConstructorGenerated]
|
||||||
[Injection(InjectAs.Singleton)]
|
[Injection(InjectAs.Singleton)]
|
||||||
internal sealed partial class MainViewModel : Abstraction.ViewModel
|
internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewModelInitialization, IRecipient<BackgroundImageTypeChangedMessage>
|
||||||
{
|
{
|
||||||
private readonly IBackgroundImageService backgroundImageService;
|
private readonly IBackgroundImageService backgroundImageService;
|
||||||
private readonly ITaskContext taskContext;
|
private readonly ITaskContext taskContext;
|
||||||
|
|
||||||
private BackgroundImage? previousBackgroundImage;
|
private BackgroundImage? previousBackgroundImage;
|
||||||
|
private Image backgroundImagePresenter;
|
||||||
|
|
||||||
|
public void Initialize(Image backgroundImagePresenter)
|
||||||
|
{
|
||||||
|
this.backgroundImagePresenter = backgroundImagePresenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Receive(BackgroundImageTypeChangedMessage message)
|
||||||
|
{
|
||||||
|
UpdateBackgroundAsync(backgroundImagePresenter).SafeForget();
|
||||||
|
}
|
||||||
|
|
||||||
[Command("UpdateBackgroundCommand")]
|
[Command("UpdateBackgroundCommand")]
|
||||||
private async Task UpdateBackgroundAsync(Image presenter)
|
private async Task UpdateBackgroundAsync(Image presenter)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
// Copyright (c) DGP Studio. All rights reserved.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.Windows.AppLifecycle;
|
using Microsoft.Windows.AppLifecycle;
|
||||||
using Snap.Hutao.Core;
|
using Snap.Hutao.Core;
|
||||||
@@ -54,6 +55,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
|||||||
private readonly IUserService userService;
|
private readonly IUserService userService;
|
||||||
private readonly ITaskContext taskContext;
|
private readonly ITaskContext taskContext;
|
||||||
private readonly AppOptions appOptions;
|
private readonly AppOptions appOptions;
|
||||||
|
private readonly IMessenger messenger;
|
||||||
|
|
||||||
private NameValue<BackdropType>? selectedBackdropType;
|
private NameValue<BackdropType>? selectedBackdropType;
|
||||||
private NameValue<BackgroundImageType>? selectedBackgroundImageType;
|
private NameValue<BackgroundImageType>? selectedBackgroundImageType;
|
||||||
@@ -100,6 +102,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
|||||||
if (SetProperty(ref selectedBackgroundImageType, value) && value is not null)
|
if (SetProperty(ref selectedBackgroundImageType, value) && value is not null)
|
||||||
{
|
{
|
||||||
AppOptions.BackgroundImageType = value.Value;
|
AppOptions.BackgroundImageType = value.Value;
|
||||||
|
messenger.Send(new Message.BackgroundImageTypeChangedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user