mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Compare commits
1 Commits
feat/real_
...
activity-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a572631e9 |
@@ -5,6 +5,7 @@ using Microsoft.UI.Xaml;
|
|||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
using Microsoft.UI.Xaml.Shapes;
|
using Microsoft.UI.Xaml.Shapes;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Snap.Hutao.Control.Brush;
|
namespace Snap.Hutao.Control.Brush;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
using CommunityToolkit.WinUI.Collections;
|
using CommunityToolkit.WinUI.Collections;
|
||||||
using CommunityToolkit.WinUI.Helpers;
|
using CommunityToolkit.WinUI.Helpers;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
using Snap.Hutao.Core.ExceptionService;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
@@ -207,11 +208,13 @@ internal sealed class AdvancedCollectionView<T> : IAdvancedCollectionView<T>, IN
|
|||||||
|
|
||||||
public void Add(T item)
|
public void Add(T item)
|
||||||
{
|
{
|
||||||
|
ThrowHelper.NotSupportedIf(IsReadOnly, "Collection is read-only.");
|
||||||
source.Add(item);
|
source.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
|
ThrowHelper.NotSupportedIf(IsReadOnly, "Collection is read-only.");
|
||||||
source.Clear();
|
source.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +230,7 @@ internal sealed class AdvancedCollectionView<T> : IAdvancedCollectionView<T>, IN
|
|||||||
|
|
||||||
public bool Remove(T item)
|
public bool Remove(T item)
|
||||||
{
|
{
|
||||||
|
ThrowHelper.NotSupportedIf(IsReadOnly, "Collection is read-only.");
|
||||||
source.Remove(item);
|
source.Remove(item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -239,6 +243,7 @@ internal sealed class AdvancedCollectionView<T> : IAdvancedCollectionView<T>, IN
|
|||||||
|
|
||||||
public void Insert(int index, T item)
|
public void Insert(int index, T item)
|
||||||
{
|
{
|
||||||
|
ThrowHelper.NotSupportedIf(IsReadOnly, "Collection is read-only.");
|
||||||
source.Insert(index, item);
|
source.Insert(index, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
|
||||||
// Licensed under the MIT license.
|
|
||||||
|
|
||||||
namespace Snap.Hutao.Control;
|
|
||||||
|
|
||||||
internal interface IXamlElementAccessor;
|
|
||||||
@@ -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 Snap.Hutao.Core.DependencyInjection.Abstraction;
|
||||||
using Snap.Hutao.Core.IO;
|
using Snap.Hutao.Core.IO;
|
||||||
|
|
||||||
namespace Snap.Hutao.Core.Caching;
|
namespace Snap.Hutao.Core.Caching;
|
||||||
@@ -9,7 +10,7 @@ namespace Snap.Hutao.Core.Caching;
|
|||||||
/// 为图像缓存提供抽象
|
/// 为图像缓存提供抽象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HighQuality]
|
[HighQuality]
|
||||||
internal interface IImageCache
|
internal interface IImageCache : ICastService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the file path containing cached item for given Uri
|
/// Gets the file path containing cached item for given Uri
|
||||||
|
|||||||
@@ -7,6 +7,4 @@ internal enum HutaoExceptionKind
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
ServiceTypeCastFailed,
|
ServiceTypeCastFailed,
|
||||||
FileSystemCreateFileInsufficientPermissions,
|
|
||||||
PrivateNamedPipeContentHashIncorrect,
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ internal readonly struct TempFile : IDisposable
|
|||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException ex)
|
catch (UnauthorizedAccessException ex)
|
||||||
{
|
{
|
||||||
HutaoException.Throw(HutaoExceptionKind.FileSystemCreateFileInsufficientPermissions, SH.CoreIOTempFileCreateFail, ex);
|
ThrowHelper.RuntimeEnvironment(SH.CoreIOTempFileCreateFail, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delete)
|
if (delete)
|
||||||
|
|||||||
@@ -148,15 +148,17 @@ internal sealed partial class Activation : IActivation
|
|||||||
|
|
||||||
await taskContext.SwitchToBackgroundAsync();
|
await taskContext.SwitchToBackgroundAsync();
|
||||||
|
|
||||||
if (serviceProvider.GetRequiredService<IMetadataService>() is IMetadataServiceInitialization metadataServiceInitialization)
|
serviceProvider
|
||||||
{
|
.GetRequiredService<IMetadataService>()
|
||||||
metadataServiceInitialization.InitializeInternalAsync().SafeForget();
|
.As<IMetadataServiceInitialization>()?
|
||||||
}
|
.InitializeInternalAsync()
|
||||||
|
.SafeForget();
|
||||||
|
|
||||||
if (serviceProvider.GetRequiredService<IHutaoUserService>() is IHutaoUserServiceInitialization hutaoUserServiceInitialization)
|
serviceProvider
|
||||||
{
|
.GetRequiredService<IHutaoUserService>()
|
||||||
hutaoUserServiceInitialization.InitializeInternalAsync().SafeForget();
|
.As<IHutaoUserServiceInitialization>()?
|
||||||
}
|
.InitializeInternalAsync()
|
||||||
|
.SafeForget();
|
||||||
|
|
||||||
serviceProvider
|
serviceProvider
|
||||||
.GetRequiredService<IDiscordService>()
|
.GetRequiredService<IDiscordService>()
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
|
|||||||
{
|
{
|
||||||
byte[] content = new byte[header->ContentLength];
|
byte[] content = new byte[header->ContentLength];
|
||||||
serverStream.ReadAtLeast(content, header->ContentLength, false);
|
serverStream.ReadAtLeast(content, header->ContentLength, false);
|
||||||
HutaoException.ThrowIf(XxHash64.HashToUInt64(content) != header->Checksum, HutaoExceptionKind.PrivateNamedPipeContentHashIncorrect, "PipePacket Content Hash incorrect");
|
ThrowHelper.InvalidDataIf(XxHash64.HashToUInt64(content) != header->Checksum, "PipePacket Content Hash incorrect");
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,20 @@ internal static class DateTimeOffsetExtension
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value switch
|
try
|
||||||
{
|
{
|
||||||
>= -62135596800 and <= 253402300799 => DateTimeOffset.FromUnixTimeSeconds(value),
|
return DateTimeOffset.FromUnixTimeSeconds(value);
|
||||||
>= -62135596800000 and <= 253402300799999 => DateTimeOffset.FromUnixTimeMilliseconds(value),
|
}
|
||||||
_ => defaultValue,
|
catch (ArgumentOutOfRangeException)
|
||||||
};
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeMilliseconds(value);
|
||||||
|
}
|
||||||
|
catch (ArgumentOutOfRangeException)
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,6 +46,34 @@ internal static partial class EnumerableExtension
|
|||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string JoinToString<T>(this IEnumerable<T> source, char separator, Action<StringBuilder, T> selector)
|
||||||
|
{
|
||||||
|
StringBuilder resultBuilder = new();
|
||||||
|
|
||||||
|
IEnumerator<T> enumerator = source.GetEnumerator();
|
||||||
|
if (!enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
T first = enumerator.Current;
|
||||||
|
selector(resultBuilder, first);
|
||||||
|
|
||||||
|
if (!enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
return resultBuilder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
resultBuilder.Append(separator);
|
||||||
|
selector(resultBuilder, enumerator.Current);
|
||||||
|
}
|
||||||
|
while (enumerator.MoveNext());
|
||||||
|
|
||||||
|
return resultBuilder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public static string JoinToString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, char separator, Action<StringBuilder, TKey, TValue> selector)
|
public static string JoinToString<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, char separator, Action<StringBuilder, TKey, TValue> selector)
|
||||||
{
|
{
|
||||||
StringBuilder resultBuilder = new();
|
StringBuilder resultBuilder = new();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMax
|
|||||||
public MainWindow(IServiceProvider serviceProvider)
|
public MainWindow(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), true);
|
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), true, false);
|
||||||
this.InitializeController(serviceProvider);
|
this.InitializeController(serviceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
|
||||||
// Licensed under the MIT license.
|
|
||||||
|
|
||||||
namespace Snap.Hutao.Message;
|
|
||||||
|
|
||||||
internal sealed class BackgroundImageTypeChangedMessage;
|
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
// 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 Snap.Hutao.Core.DependencyInjection.Abstraction;
|
||||||
|
|
||||||
namespace Snap.Hutao.Service.Hutao;
|
namespace Snap.Hutao.Service.Hutao;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 胡桃用户服务
|
/// 胡桃用户服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal interface IHutaoUserService
|
internal interface IHutaoUserService : ICastService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Snap.Hutao.Service.Metadata;
|
|||||||
/// 元数据服务
|
/// 元数据服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HighQuality]
|
[HighQuality]
|
||||||
internal interface IMetadataService
|
internal interface IMetadataService : ICastService
|
||||||
{
|
{
|
||||||
IMemoryCache MemoryCache { get; }
|
IMemoryCache MemoryCache { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
|
||||||
// Licensed under the MIT license.
|
|
||||||
|
|
||||||
namespace Snap.Hutao.Service.Navigation;
|
|
||||||
|
|
||||||
internal interface INavigationCurrent
|
|
||||||
{
|
|
||||||
Type? Current { get; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
// 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 Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
namespace Snap.Hutao.Service.Navigation;
|
namespace Snap.Hutao.Service.Navigation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -8,5 +10,10 @@ namespace Snap.Hutao.Service.Navigation;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal interface INavigationInitialization
|
internal interface INavigationInitialization
|
||||||
{
|
{
|
||||||
void Initialize(INavigationViewAccessor accessor);
|
/// <summary>
|
||||||
|
/// 使用指定的对象进行初始化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="navigationView">管理的 <see cref="NavigationView"/></param>
|
||||||
|
/// <param name="frame">管理的 <see cref="Frame"/></param>
|
||||||
|
void Initialize(NavigationView navigationView, Frame frame);
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace Snap.Hutao.Service.Navigation;
|
|||||||
/// 导航服务
|
/// 导航服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HighQuality]
|
[HighQuality]
|
||||||
internal interface INavigationService : INavigationCurrent
|
internal interface INavigationService : ICastService, INavigationCurrent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 导航到指定类型的页面
|
/// 导航到指定类型的页面
|
||||||
@@ -47,4 +47,9 @@ internal interface INavigationService : INavigationCurrent
|
|||||||
/// 尽可能尝试返回
|
/// 尽可能尝试返回
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void GoBack();
|
void GoBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal interface INavigationCurrent
|
||||||
|
{
|
||||||
|
Type? Current { get; }
|
||||||
}
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
|
||||||
// Licensed under the MIT license.
|
|
||||||
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
|
||||||
using Snap.Hutao.Control;
|
|
||||||
|
|
||||||
namespace Snap.Hutao.Service.Navigation;
|
|
||||||
|
|
||||||
internal interface INavigationViewAccessor : IXamlElementAccessor
|
|
||||||
{
|
|
||||||
NavigationView NavigationView { get; }
|
|
||||||
|
|
||||||
Frame Frame { get; }
|
|
||||||
}
|
|
||||||
@@ -147,10 +147,10 @@ internal sealed class NavigationService : INavigationService, INavigationInitial
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Initialize(INavigationViewAccessor accessor)
|
public void Initialize(NavigationView navigationView, Frame frame)
|
||||||
{
|
{
|
||||||
NavigationView = accessor.NavigationView;
|
NavigationView = navigationView;
|
||||||
frame = accessor.Frame;
|
this.frame = frame;
|
||||||
|
|
||||||
NavigationView.IsPaneOpen = LocalSetting.Get(SettingKeys.IsNavPaneOpen, true);
|
NavigationView.IsPaneOpen = LocalSetting.Get(SettingKeys.IsNavPaneOpen, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<mxi:Interaction.Behaviors>
|
<mxi:Interaction.Behaviors>
|
||||||
<shcb:PeriodicInvokeCommandOrOnActualThemeChangedBehavior
|
<shcb:PeriodicInvokeCommandOrOnActualThemeChangedBehavior
|
||||||
Command="{Binding UpdateBackgroundCommand}"
|
Command="{Binding UpdateBackgroundCommand}"
|
||||||
CommandParameter="{x:Bind BackgroundImagePresenter}"
|
CommandParameter="{x:Bind BackdroundImagePresenter}"
|
||||||
Period="0:5:0"/>
|
Period="0:5:0"/>
|
||||||
</mxi:Interaction.Behaviors>
|
</mxi:Interaction.Behaviors>
|
||||||
|
|
||||||
@@ -28,10 +28,9 @@
|
|||||||
<x:Double x:Key="NavigationViewItemOnLeftIconBoxHeight">24</x:Double>
|
<x:Double x:Key="NavigationViewItemOnLeftIconBoxHeight">24</x:Double>
|
||||||
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="Transparent"/>
|
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="Transparent"/>
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<!-- Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" -->
|
<Grid Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" Transitions="{ThemeResource EntranceThemeTransitions}">
|
||||||
<Grid Transitions="{ThemeResource EntranceThemeTransitions}">
|
|
||||||
<Image
|
<Image
|
||||||
x:Name="BackgroundImagePresenter"
|
x:Name="BackdroundImagePresenter"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Opacity="0"
|
Opacity="0"
|
||||||
|
|||||||
@@ -27,44 +27,17 @@ internal sealed partial class MainView : UserControl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public MainView()
|
public MainView()
|
||||||
{
|
{
|
||||||
IServiceProvider serviceProvider = Ioc.Default;
|
DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
|
||||||
|
|
||||||
MainViewModel mainViewModel = serviceProvider.GetRequiredService<MainViewModel>();
|
|
||||||
|
|
||||||
DataContext = mainViewModel;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
mainViewModel.Initialize(new BackgroundImagePresenterAccessor(BackgroundImagePresenter));
|
IServiceProvider serviceProvider = Ioc.Default;
|
||||||
|
|
||||||
navigationService = serviceProvider.GetRequiredService<INavigationService>();
|
navigationService = serviceProvider.GetRequiredService<INavigationService>();
|
||||||
if (navigationService is INavigationInitialization navigationInitialization)
|
if (navigationService is INavigationInitialization navigationInitialization)
|
||||||
{
|
{
|
||||||
navigationInitialization.Initialize(new NavigationViewAccessor(NavView, ContentFrame));
|
navigationInitialization.Initialize(NavView, ContentFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
navigationService.Navigate<AnnouncementPage>(INavigationAwaiter.Default, true);
|
navigationService.Navigate<AnnouncementPage>(INavigationAwaiter.Default, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NavigationViewAccessor : INavigationViewAccessor
|
|
||||||
{
|
|
||||||
public NavigationViewAccessor(NavigationView navigationView, Frame frame)
|
|
||||||
{
|
|
||||||
NavigationView = navigationView;
|
|
||||||
Frame = frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigationView NavigationView { get; private set; }
|
|
||||||
|
|
||||||
public Frame Frame { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class BackgroundImagePresenterAccessor : IBackgroundImagePresenterAccessor
|
|
||||||
{
|
|
||||||
public BackgroundImagePresenterAccessor(Image backgroundImagePresenter)
|
|
||||||
{
|
|
||||||
BackgroundImagePresenter = backgroundImagePresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image BackgroundImagePresenter { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
|
||||||
// Licensed under the MIT license.
|
|
||||||
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
|
||||||
using Snap.Hutao.Control;
|
|
||||||
|
|
||||||
namespace Snap.Hutao.ViewModel;
|
|
||||||
|
|
||||||
internal interface IBackgroundImagePresenterAccessor : IXamlElementAccessor
|
|
||||||
{
|
|
||||||
Image BackgroundImagePresenter { get; }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
|
||||||
// Licensed under the MIT license.
|
|
||||||
|
|
||||||
namespace Snap.Hutao.ViewModel;
|
|
||||||
|
|
||||||
internal interface IMainViewModelInitialization
|
|
||||||
{
|
|
||||||
void Initialize(IBackgroundImagePresenterAccessor accessor);
|
|
||||||
}
|
|
||||||
@@ -1,45 +1,27 @@
|
|||||||
// 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;
|
||||||
|
|
||||||
namespace Snap.Hutao.ViewModel;
|
namespace Snap.Hutao.ViewModel;
|
||||||
|
|
||||||
[ConstructorGenerated]
|
[ConstructorGenerated]
|
||||||
[Injection(InjectAs.Singleton)]
|
[Injection(InjectAs.Singleton)]
|
||||||
internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewModelInitialization, IRecipient<BackgroundImageTypeChangedMessage>
|
internal sealed partial class MainViewModel : Abstraction.ViewModel
|
||||||
{
|
{
|
||||||
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(IBackgroundImagePresenterAccessor accessor)
|
|
||||||
{
|
|
||||||
backgroundImagePresenter = accessor.BackgroundImagePresenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Receive(BackgroundImageTypeChangedMessage message)
|
|
||||||
{
|
|
||||||
UpdateBackgroundAsync().SafeForget();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command("UpdateBackgroundCommand")]
|
[Command("UpdateBackgroundCommand")]
|
||||||
private async Task UpdateBackgroundAsync()
|
private async Task UpdateBackgroundAsync(Image presenter)
|
||||||
{
|
{
|
||||||
if (backgroundImagePresenter is null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
||||||
|
|
||||||
if (isOk)
|
if (isOk)
|
||||||
@@ -54,11 +36,11 @@ internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewMo
|
|||||||
duration: ControlAnimationConstants.ImageOpacityFadeInOut,
|
duration: ControlAnimationConstants.ImageOpacityFadeInOut,
|
||||||
easingType: EasingType.Quartic,
|
easingType: EasingType.Quartic,
|
||||||
easingMode: EasingMode.EaseInOut)
|
easingMode: EasingMode.EaseInOut)
|
||||||
.StartAsync(backgroundImagePresenter)
|
.StartAsync(presenter)
|
||||||
.ConfigureAwait(true);
|
.ConfigureAwait(true);
|
||||||
|
|
||||||
backgroundImagePresenter.Source = backgroundImage.ImageSource;
|
presenter.Source = backgroundImage.ImageSource;
|
||||||
double targetOpacity = ThemeHelper.IsDarkMode(backgroundImagePresenter.ActualTheme) ? 1 - backgroundImage.Luminance : backgroundImage.Luminance;
|
double targetOpacity = ThemeHelper.IsDarkMode(presenter.ActualTheme) ? 1 - backgroundImage.Luminance : backgroundImage.Luminance;
|
||||||
|
|
||||||
await AnimationBuilder
|
await AnimationBuilder
|
||||||
.Create()
|
.Create()
|
||||||
@@ -67,7 +49,7 @@ internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewMo
|
|||||||
duration: ControlAnimationConstants.ImageOpacityFadeInOut,
|
duration: ControlAnimationConstants.ImageOpacityFadeInOut,
|
||||||
easingType: EasingType.Quartic,
|
easingType: EasingType.Quartic,
|
||||||
easingMode: EasingMode.EaseInOut)
|
easingMode: EasingMode.EaseInOut)
|
||||||
.StartAsync(backgroundImagePresenter)
|
.StartAsync(presenter)
|
||||||
.ConfigureAwait(true);
|
.ConfigureAwait(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// 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;
|
||||||
@@ -55,7 +54,6 @@ 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;
|
||||||
@@ -102,7 +100,6 @@ 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