mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Compare commits
39 Commits
1.10.0
...
ShellNotif
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d6e1dad01 | ||
|
|
d52aa0d6b2 | ||
|
|
3ee729eacf | ||
|
|
d3acbcde24 | ||
|
|
38e152befd | ||
|
|
0f767f7e77 | ||
|
|
dafd3128c2 | ||
|
|
0556373bcf | ||
|
|
e8d3a065e6 | ||
|
|
be223909d3 | ||
|
|
7da778699b | ||
|
|
5bfc790ea2 | ||
|
|
fc13b85739 | ||
|
|
df999dbf51 | ||
|
|
688562c1dd | ||
|
|
051a115f84 | ||
|
|
b3d75f9fa5 | ||
|
|
0b90bdaa42 | ||
|
|
77067d27d0 | ||
|
|
e04542606e | ||
|
|
5be958ff64 | ||
|
|
a57933388d | ||
|
|
86c6c9574b | ||
|
|
47e451df2f | ||
|
|
c8592c798b | ||
|
|
5fad960b20 | ||
|
|
44ba0a90a6 | ||
|
|
883c1ca95f | ||
|
|
1a29908e5d | ||
|
|
3e9edd2f62 | ||
|
|
f9c18d2555 | ||
|
|
b5afca256a | ||
|
|
a0e79344b1 | ||
|
|
3b8eba3bb1 | ||
|
|
08a3db7dc9 | ||
|
|
c02e7b0db3 | ||
|
|
a51ede5048 | ||
|
|
1f31c946cc | ||
|
|
7dee4a0ea5 |
@@ -6,6 +6,7 @@
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<XamlControlsResources/>
|
||||
<ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.SettingsControls/SettingsCard/SettingsCard.xaml"/>
|
||||
<ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.TokenizingTextBox/TokenizingTextBox.xaml"/>
|
||||
<ResourceDictionary Source="ms-appx:///Control/Loading.xaml"/>
|
||||
<ResourceDictionary Source="ms-appx:///Control/Image/CachedImage.xaml"/>
|
||||
|
||||
@@ -8,7 +8,9 @@ using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
using Snap.Hutao.Core.Logging;
|
||||
using Snap.Hutao.Core.Shell;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing.HotKey;
|
||||
using Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Snap.Hutao;
|
||||
@@ -39,7 +41,7 @@ public sealed partial class App : Application
|
||||
""";
|
||||
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IActivation activation;
|
||||
private readonly IAppActivation activation;
|
||||
private readonly ILogger<App> logger;
|
||||
|
||||
/// <summary>
|
||||
@@ -50,13 +52,21 @@ public sealed partial class App : Application
|
||||
{
|
||||
// Load app resource
|
||||
InitializeComponent();
|
||||
activation = serviceProvider.GetRequiredService<IActivation>();
|
||||
activation = serviceProvider.GetRequiredService<IAppActivation>();
|
||||
logger = serviceProvider.GetRequiredService<ILogger<App>>();
|
||||
serviceProvider.GetRequiredService<ExceptionRecorder>().Record(this);
|
||||
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public bool IsExiting { get; private set; }
|
||||
|
||||
public new void Exit()
|
||||
{
|
||||
IsExiting = true;
|
||||
base.Exit();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
@@ -73,11 +83,9 @@ public sealed partial class App : Application
|
||||
logger.LogColorizedInformation((ConsoleBanner, ConsoleColor.DarkYellow));
|
||||
LogDiagnosticInformation();
|
||||
|
||||
// manually invoke
|
||||
// Manually invoke
|
||||
activation.Activate(HutaoActivationArguments.FromAppActivationArguments(activatedEventArgs));
|
||||
activation.Initialize();
|
||||
|
||||
serviceProvider.GetRequiredService<IJumpListInterop>().ConfigureAsync().SafeForget();
|
||||
activation.PostInitialization();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -17,8 +17,13 @@
|
||||
<x:String x:Key="UI_Icon_Intee_Explore_1">https://api.snapgenshin.com/static/raw/Bg/UI_Icon_Intee_Explore_1.png</x:String>
|
||||
<x:String x:Key="UI_ImgSign_ItemIcon">https://api.snapgenshin.com/static/raw/Bg/UI_ImgSign_ItemIcon.png</x:String>
|
||||
<x:String x:Key="UI_ItemIcon_None">https://api.snapgenshin.com/static/raw/Bg/UI_ItemIcon_None.png</x:String>
|
||||
<x:String x:Key="UI_MarkQuest_Events_Proce">https://api.snapgenshin.com/static/raw/Bg/UI_MarkQuest_Events_Proce.png</x:String>
|
||||
<x:String x:Key="UI_MarkTower">https://api.snapgenshin.com/static/raw/Bg/UI_MarkTower.png</x:String>
|
||||
|
||||
<!-- Mark -->
|
||||
<x:String x:Key="UI_MarkQuest_Events_Proce">https://api.snapgenshin.com/static/raw/Mark/UI_MarkQuest_Events_Proce.png</x:String>
|
||||
<x:String x:Key="UI_MarkQuest_Events_Start">https://api.snapgenshin.com/static/raw/Mark/UI_MarkQuest_Events_Start.png</x:String>
|
||||
<x:String x:Key="UI_MarkQuest_Main_Proce">https://api.snapgenshin.com/static/raw/Mark/UI_MarkQuest_Main_Proce.png</x:String>
|
||||
<x:String x:Key="UI_MarkQuest_Main_Start">https://api.snapgenshin.com/static/raw/Mark/UI_MarkQuest_Main_Start.png</x:String>
|
||||
<x:String x:Key="UI_MarkTower">https://api.snapgenshin.com/static/raw/Mark/UI_MarkTower.png</x:String>
|
||||
|
||||
<!-- ItemIcon -->
|
||||
<x:String x:Key="UI_ItemIcon_201">https://api.snapgenshin.com/static/raw/ItemIcon/UI_ItemIcon_201.png</x:String>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Snap.Hutao.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 支持Md5转换
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal static class Convert
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取字符串的MD5计算结果
|
||||
/// </summary>
|
||||
/// <param name="source">源字符串</param>
|
||||
/// <returns>计算的结果</returns>
|
||||
public static string ToMd5HexString(string source)
|
||||
{
|
||||
byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(source));
|
||||
return System.Convert.ToHexString(hash);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.DependencyInjection.Abstraction;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 对象扩展
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal static class CastServiceExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// <see langword="as"/> 的链式调用扩展
|
||||
/// </summary>
|
||||
/// <typeparam name="T">目标转换类型</typeparam>
|
||||
/// <param name="service">对象</param>
|
||||
/// <returns>转换类型后的对象</returns>
|
||||
[Obsolete("Not useful anymore")]
|
||||
public static T? As<T>(this ICastService service)
|
||||
where T : class
|
||||
{
|
||||
return service as T;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ internal sealed class HutaoException : Exception
|
||||
throw new InvalidCastException(message, innerException);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
public static InvalidOperationException InvalidOperation(string message, Exception? innerException = default)
|
||||
{
|
||||
throw new InvalidOperationException(message, innerException);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
public static NotSupportedException NotSupported(string? message = default, Exception? innerException = default)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Snap.Hutao.Win32.UI.Shell;
|
||||
using System.IO;
|
||||
@@ -63,13 +62,13 @@ internal static class FileOperation
|
||||
result = true;
|
||||
}
|
||||
|
||||
pDestShellItem->Release();
|
||||
IUnknownMarshal.Release(pDestShellItem);
|
||||
}
|
||||
|
||||
pSourceShellItem->Release();
|
||||
IUnknownMarshal.Release(pSourceShellItem);
|
||||
}
|
||||
|
||||
pFileOperation->Release();
|
||||
IUnknownMarshal.Release(pFileOperation);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -90,10 +89,10 @@ internal static class FileOperation
|
||||
result = true;
|
||||
}
|
||||
|
||||
pShellItem->Release();
|
||||
IUnknownMarshal.Release(pShellItem);
|
||||
}
|
||||
|
||||
pFileOperation->Release();
|
||||
IUnknownMarshal.Release(pFileOperation);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -8,12 +8,17 @@ namespace Snap.Hutao.Core.IO.Hashing;
|
||||
|
||||
internal static class Hash
|
||||
{
|
||||
public static string SHA1HexString(string input)
|
||||
public static unsafe string SHA1HexString(string input)
|
||||
{
|
||||
return HashCore(System.Convert.ToHexString, SHA1.HashData, Encoding.UTF8.GetBytes, input);
|
||||
return HashCore(Convert.ToHexString, SHA1.HashData, Encoding.UTF8.GetBytes, input);
|
||||
}
|
||||
|
||||
private static TResult HashCore<TInput, TResult>(Func<byte[], TResult> resultConverter, Func<byte[], byte[]> hashMethod, Func<TInput, byte[]> bytesConverter, TInput input)
|
||||
public static unsafe string MD5HexString(string input)
|
||||
{
|
||||
return HashCore(Convert.ToHexString, System.Security.Cryptography.MD5.HashData, Encoding.UTF8.GetBytes, input);
|
||||
}
|
||||
|
||||
private static unsafe TResult HashCore<TInput, TResult>(Func<byte[], TResult> resultConverter, Func<byte[], byte[]> hashMethod, Func<TInput, byte[]> bytesConverter, TInput input)
|
||||
{
|
||||
return resultConverter(hashMethod(bytesConverter(input)));
|
||||
}
|
||||
|
||||
@@ -34,6 +34,6 @@ internal static class MD5
|
||||
public static async ValueTask<string> HashAsync(Stream stream, CancellationToken token = default)
|
||||
{
|
||||
byte[] bytes = await System.Security.Cryptography.MD5.HashDataAsync(stream, token).ConfigureAwait(false);
|
||||
return System.Convert.ToHexString(bytes);
|
||||
return Convert.ToHexString(bytes);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,6 @@ internal static class SHA256
|
||||
public static async ValueTask<string> HashAsync(Stream stream, CancellationToken token = default)
|
||||
{
|
||||
byte[] bytes = await System.Security.Cryptography.SHA256.HashDataAsync(stream, token).ConfigureAwait(false);
|
||||
return System.Convert.ToHexString(bytes);
|
||||
return Convert.ToHexString(bytes);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
using CommunityToolkit.WinUI.Notifications;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing.HotKey;
|
||||
using Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
using Snap.Hutao.Service.DailyNote;
|
||||
using Snap.Hutao.Service.Discord;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
@@ -20,9 +23,9 @@ namespace Snap.Hutao.Core.LifeCycle;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton, typeof(IActivation))]
|
||||
[Injection(InjectAs.Singleton, typeof(IAppActivation))]
|
||||
[SuppressMessage("", "CA1001")]
|
||||
internal sealed partial class Activation : IActivation
|
||||
internal sealed partial class AppActivation : IAppActivation, IAppActivationActionHandlersAccess, IDisposable
|
||||
{
|
||||
public const string Action = nameof(Action);
|
||||
public const string Uid = nameof(Uid);
|
||||
@@ -35,13 +38,15 @@ internal sealed partial class Activation : IActivation
|
||||
private const string UrlActionRefresh = "/REFRESH";
|
||||
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly ICurrentWindowReference currentWindowReference;
|
||||
private readonly ICurrentXamlWindowReference currentWindowReference;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly SemaphoreSlim activateSemaphore = new(1);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Activate(HutaoActivationArguments args)
|
||||
{
|
||||
// Before activate, we try to redirect to the opened process in App,
|
||||
// And we check if it's a toast activation.
|
||||
if (ToastNotificationManagerCompat.WasCurrentProcessToastActivated())
|
||||
{
|
||||
return;
|
||||
@@ -51,10 +56,52 @@ internal sealed partial class Activation : IActivation
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Initialize()
|
||||
public void PostInitialization()
|
||||
{
|
||||
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
|
||||
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
|
||||
|
||||
serviceProvider.GetRequiredService<HotKeyOptions>().RegisterAll();
|
||||
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true))
|
||||
{
|
||||
serviceProvider.GetRequiredService<App>().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
|
||||
_ = serviceProvider.GetRequiredService<NotifyIconController>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
activateSemaphore.Dispose();
|
||||
}
|
||||
|
||||
public async ValueTask HandleLaunchGameActionAsync(string? uid = null)
|
||||
{
|
||||
serviceProvider
|
||||
.GetRequiredService<IMemoryCache>()
|
||||
.Set(ViewModel.Game.LaunchGameViewModel.DesiredUid, uid);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
if (currentWindowReference.Window is null)
|
||||
{
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentWindowReference.Window is MainWindow)
|
||||
{
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a non-Main Window, just exit current process anyway
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
|
||||
private void NotificationActivate(ToastNotificationActivatedEventArgsCompat args)
|
||||
@@ -94,12 +141,6 @@ internal sealed partial class Activation : IActivation
|
||||
ArgumentNullException.ThrowIfNull(args.LaunchActivatedArguments);
|
||||
switch (args.LaunchActivatedArguments)
|
||||
{
|
||||
case LaunchGame:
|
||||
{
|
||||
await HandleLaunchGameActionAsync().ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
await HandleNormalLaunchActionAsync().ConfigureAwait(false);
|
||||
@@ -112,10 +153,9 @@ internal sealed partial class Activation : IActivation
|
||||
private async ValueTask HandleNormalLaunchActionAsync()
|
||||
{
|
||||
// Increase launch times
|
||||
LocalSetting.Update(SettingKeys.LaunchTimes, 0, x => x + 1);
|
||||
LocalSetting.Update(SettingKeys.LaunchTimes, 0, x => unchecked(x + 1));
|
||||
|
||||
// If it's the first time launch, we show the guide window anyway.
|
||||
// Otherwise, we check if there's any unfulfilled resource category present.
|
||||
// If the guide is completed, we check if there's any unfulfilled resource category present.
|
||||
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) >= GuideState.StaticResourceBegin)
|
||||
{
|
||||
if (StaticResource.IsAnyUnfulfilledCategoryPresent())
|
||||
@@ -124,10 +164,11 @@ internal sealed partial class Activation : IActivation
|
||||
}
|
||||
}
|
||||
|
||||
// If it's the first time launch, show the guide window anyway.
|
||||
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
|
||||
{
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
serviceProvider.GetRequiredService<GuideWindow>();
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<GuideWindow>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -144,7 +185,7 @@ internal sealed partial class Activation : IActivation
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
serviceProvider.GetRequiredService<MainWindow>();
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<MainWindow>();
|
||||
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
|
||||
@@ -158,10 +199,7 @@ internal sealed partial class Activation : IActivation
|
||||
hutaoUserServiceInitialization.InitializeInternalAsync().SafeForget();
|
||||
}
|
||||
|
||||
serviceProvider
|
||||
.GetRequiredService<IDiscordService>()
|
||||
.SetNormalActivityAsync()
|
||||
.SafeForget();
|
||||
serviceProvider.GetRequiredService<IDiscordService>().SetNormalActivityAsync().SafeForget();
|
||||
}
|
||||
|
||||
private async ValueTask HandleUrlActivationAsync(Uri uri, bool isRedirectTo)
|
||||
@@ -244,34 +282,4 @@ internal sealed partial class Activation : IActivation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async ValueTask HandleLaunchGameActionAsync(string? uid = null)
|
||||
{
|
||||
serviceProvider
|
||||
.GetRequiredService<IMemoryCache>()
|
||||
.Set(ViewModel.Game.LaunchGameViewModel.DesiredUid, uid);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
if (currentWindowReference.Window is null)
|
||||
{
|
||||
serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentWindowReference.Window is MainWindow)
|
||||
{
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a non-Main Window, just exit current process anyway
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using WinRT.Interop;
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
internal static class CurrentWindowReferenceExtension
|
||||
{
|
||||
public static XamlRoot GetXamlRoot(this ICurrentWindowReference reference)
|
||||
{
|
||||
return reference.Window.Content.XamlRoot;
|
||||
}
|
||||
|
||||
public static HWND GetWindowHandle(this ICurrentWindowReference reference)
|
||||
{
|
||||
return reference.Window is IWindowOptionsSource optionsSource
|
||||
? optionsSource.WindowOptions.Hwnd
|
||||
: WindowNative.GetWindowHandle(reference.Window);
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,19 @@ using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
[Injection(InjectAs.Singleton, typeof(ICurrentWindowReference))]
|
||||
internal sealed class CurrentWindowReference : ICurrentWindowReference
|
||||
[Injection(InjectAs.Singleton, typeof(ICurrentXamlWindowReference))]
|
||||
internal sealed class CurrentXamlWindowReference : ICurrentXamlWindowReference
|
||||
{
|
||||
private readonly WeakReference<Window> reference = new(default!);
|
||||
|
||||
[SuppressMessage("", "SH007")]
|
||||
public Window Window
|
||||
public Window? Window
|
||||
{
|
||||
get
|
||||
{
|
||||
reference.TryGetTarget(out Window? window);
|
||||
return window!;
|
||||
}
|
||||
set => reference.SetTarget(value);
|
||||
set => reference.SetTarget(value!);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using WinRT.Interop;
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
internal static class CurrentXamlWindowReferenceExtension
|
||||
{
|
||||
public static XamlRoot GetXamlRoot(this ICurrentXamlWindowReference reference)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reference.Window);
|
||||
return reference.Window.Content.XamlRoot;
|
||||
}
|
||||
|
||||
public static HWND GetWindowHandle(this ICurrentXamlWindowReference reference)
|
||||
{
|
||||
return WindowExtension.GetWindowHandle(reference.Window);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
/// <summary>
|
||||
/// 激活
|
||||
/// </summary>
|
||||
internal interface IActivation
|
||||
{
|
||||
void Activate(HutaoActivationArguments args);
|
||||
|
||||
void Initialize();
|
||||
}
|
||||
16
src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/IAppActivation.cs
Normal file
16
src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/IAppActivation.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
internal interface IAppActivation
|
||||
{
|
||||
void Activate(HutaoActivationArguments args);
|
||||
|
||||
void PostInitialization();
|
||||
}
|
||||
|
||||
internal interface IAppActivationActionHandlersAccess
|
||||
{
|
||||
ValueTask HandleLaunchGameActionAsync(string? uid = null);
|
||||
}
|
||||
@@ -5,10 +5,10 @@ using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle;
|
||||
|
||||
internal interface ICurrentWindowReference
|
||||
internal interface ICurrentXamlWindowReference
|
||||
{
|
||||
/// <summary>
|
||||
/// Only set in WindowController
|
||||
/// </summary>
|
||||
public Window Window { get; set; }
|
||||
public Window? Window { get; set; }
|
||||
}
|
||||
@@ -16,6 +16,6 @@ internal sealed partial class PrivateNamedPipeMessageDispatcher
|
||||
return;
|
||||
}
|
||||
|
||||
serviceProvider.GetRequiredService<IActivation>().Activate(args);
|
||||
serviceProvider.GetRequiredService<IAppActivation>().Activate(args);
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,18 @@ namespace Snap.Hutao.Core.Logging;
|
||||
|
||||
internal sealed class ConsoleWindowLifeTime : IDisposable
|
||||
{
|
||||
public const bool DebugModeEnabled =
|
||||
#if IS_ALPHA_BUILD
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
|
||||
private readonly bool consoleWindowAllocated;
|
||||
|
||||
public ConsoleWindowLifeTime()
|
||||
{
|
||||
if (LocalSetting.Get(SettingKeys.IsAllocConsoleDebugModeEnabled, false))
|
||||
if (LocalSetting.Get(SettingKeys.IsAllocConsoleDebugModeEnabled, DebugModeEnabled))
|
||||
{
|
||||
consoleWindowAllocated = AllocConsole();
|
||||
if (consoleWindowAllocated)
|
||||
|
||||
27
src/Snap.Hutao/Snap.Hutao/Core/ReadOnlySpan2D.cs
Normal file
27
src/Snap.Hutao/Snap.Hutao/Core/ReadOnlySpan2D.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Core;
|
||||
|
||||
internal readonly ref struct ReadOnlySpan2D<T>
|
||||
where T : unmanaged
|
||||
{
|
||||
private readonly ref T reference;
|
||||
private readonly int length;
|
||||
private readonly int columns;
|
||||
|
||||
public unsafe ReadOnlySpan2D(void* pointer, int length, int columns)
|
||||
{
|
||||
reference = ref *(T*)pointer;
|
||||
this.length = length;
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<T> this[int row]
|
||||
{
|
||||
get => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref reference, row * columns), columns);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Win32;
|
||||
using Snap.Hutao.Core.IO.Hashing;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using System.IO;
|
||||
using System.Security.Principal;
|
||||
@@ -50,7 +51,7 @@ internal sealed class RuntimeOptions
|
||||
{
|
||||
string userName = Environment.UserName;
|
||||
object? machineGuid = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\", "MachineGuid", userName);
|
||||
return Convert.ToMd5HexString($"{userName}{machineGuid}");
|
||||
return Hash.MD5HexString($"{userName}{machineGuid}");
|
||||
});
|
||||
|
||||
private readonly LazySlim<(string Version, bool Supported)> lazyWebViewEnvironment = new(() =>
|
||||
|
||||
@@ -12,8 +12,13 @@ internal static class SettingKeys
|
||||
{
|
||||
#region MainWindow
|
||||
public const string WindowRect = "WindowRect";
|
||||
public const string GuideWindowRect = "GuideWindowRect";
|
||||
public const string IsNavPaneOpen = "IsNavPaneOpen";
|
||||
public const string IsInfoBarToggleChecked = "IsInfoBarToggleChecked";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Infrastructure
|
||||
public const string ExcludedAnnouncementIds = "ExcludedAnnouncementIds";
|
||||
#endregion
|
||||
|
||||
@@ -25,6 +30,7 @@ internal static class SettingKeys
|
||||
public const string StaticResourceImageArchive = "StaticResourceImageArchive";
|
||||
public const string HotKeyMouseClickRepeatForever = "HotKeyMouseClickRepeatForever";
|
||||
public const string IsAllocConsoleDebugModeEnabled = "IsAllocConsoleDebugModeEnabled2";
|
||||
public const string IsNotifyIconEnabled = "IsNotifyIconEnabled";
|
||||
#endregion
|
||||
|
||||
#region Passport
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// 跳转列表交互
|
||||
/// </summary>
|
||||
internal interface IJumpListInterop
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步配置跳转列表
|
||||
/// </summary>
|
||||
/// <returns>任务</returns>
|
||||
ValueTask ConfigureAsync();
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Windows.UI.StartScreen;
|
||||
|
||||
namespace Snap.Hutao.Core.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// 跳转列表交互
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Transient, typeof(IJumpListInterop))]
|
||||
internal sealed class JumpListInterop : IJumpListInterop
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步配置跳转列表
|
||||
/// </summary>
|
||||
/// <returns>任务</returns>
|
||||
public async ValueTask ConfigureAsync()
|
||||
{
|
||||
if (JumpList.IsSupported())
|
||||
{
|
||||
JumpList list = await JumpList.LoadCurrentAsync();
|
||||
|
||||
list.Items.Clear();
|
||||
|
||||
JumpListItem launchGameItem = JumpListItem.CreateWithArguments(Activation.LaunchGame, SH.CoreJumpListHelperLaunchGameItemDisplayName);
|
||||
launchGameItem.Logo = "ms-appx:///Resource/Navigation/LaunchGame.png".ToUri();
|
||||
|
||||
list.Items.Add(launchGameItem);
|
||||
|
||||
await list.SaveAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
|
||||
pShellLink->SetShowCmd(SHOW_WINDOW_CMD.SW_NORMAL);
|
||||
pShellLink->SetIconLocation(targetLogoPath, 0);
|
||||
|
||||
if (SUCCEEDED(pShellLink->QueryInterface(in IPersistFile.IID, out IPersistFile* pPersistFile)))
|
||||
if (SUCCEEDED(IUnknownMarshal.QueryInterface(pShellLink, in IPersistFile.IID, out IPersistFile* pPersistFile)))
|
||||
{
|
||||
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
string target = Path.Combine(desktop, $"{SH.FormatAppNameAndVersion(runtimeOptions.Version)}.lnk");
|
||||
@@ -64,10 +64,10 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
|
||||
result = true;
|
||||
}
|
||||
|
||||
pPersistFile->Release();
|
||||
IUnknownMarshal.Release(pPersistFile);
|
||||
}
|
||||
|
||||
pShellLink->Release();
|
||||
uint value = IUnknownMarshal.Release(pShellLink);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.Backdrop;
|
||||
|
||||
internal interface IWindowNeedEraseBackground;
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Composition;
|
||||
using Microsoft.UI.Composition.SystemBackdrops;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.Backdrop;
|
||||
|
||||
// https://github.com/microsoft/microsoft-ui-xaml/blob/winui3/release/1.5-stable/controls/dev/Materials/DesktopAcrylicBackdrop/DesktopAcrylicBackdrop.cpp
|
||||
internal sealed class InputActiveDesktopAcrylicBackdrop : SystemBackdrop
|
||||
{
|
||||
private readonly ConcurrentDictionary<ICompositionSupportsSystemBackdrop, DesktopAcrylicController> controllers = [];
|
||||
|
||||
protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
|
||||
{
|
||||
base.OnTargetConnected(target, xamlRoot);
|
||||
|
||||
DesktopAcrylicController newController = new();
|
||||
SystemBackdropConfiguration configuration = GetDefaultSystemBackdropConfiguration(target, xamlRoot);
|
||||
|
||||
configuration.IsInputActive = true;
|
||||
|
||||
newController.AddSystemBackdropTarget(target);
|
||||
newController.SetSystemBackdropConfiguration(configuration);
|
||||
controllers.TryAdd(target, newController);
|
||||
}
|
||||
|
||||
protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop target)
|
||||
{
|
||||
base.OnTargetDisconnected(target);
|
||||
|
||||
if (controllers.TryRemove(target, out DesktopAcrylicController? controller))
|
||||
{
|
||||
controller.RemoveSystemBackdropTarget(target);
|
||||
controller.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Composition;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Hosting;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using System.Runtime.CompilerServices;
|
||||
using WinRT;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.Backdrop;
|
||||
|
||||
internal sealed class SystemBackdropDesktopWindowXamlSourceAccess : SystemBackdrop
|
||||
{
|
||||
private readonly SystemBackdrop? innerBackdrop;
|
||||
|
||||
public SystemBackdropDesktopWindowXamlSourceAccess(SystemBackdrop? systemBackdrop)
|
||||
{
|
||||
innerBackdrop = systemBackdrop;
|
||||
}
|
||||
|
||||
public DesktopWindowXamlSource? DesktopWindowXamlSource
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
|
||||
{
|
||||
DesktopWindowXamlSource = DesktopWindowXamlSource.FromAbi(target.As<IInspectable>().ThisPtr);
|
||||
if (innerBackdrop is not null)
|
||||
{
|
||||
ProtectedOnTargetConnected(innerBackdrop, target, xamlRoot);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop target)
|
||||
{
|
||||
DesktopWindowXamlSource = null;
|
||||
if (innerBackdrop is not null)
|
||||
{
|
||||
ProtectedOnTargetDisconnected(innerBackdrop, target);
|
||||
}
|
||||
}
|
||||
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(OnTargetConnected))]
|
||||
private static extern void ProtectedOnTargetConnected(SystemBackdrop systemBackdrop, ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot);
|
||||
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(OnTargetDisconnected))]
|
||||
private static extern void ProtectedOnTargetDisconnected(SystemBackdrop systemBackdrop, ICompositionSupportsSystemBackdrop target);
|
||||
}
|
||||
@@ -9,9 +9,9 @@ using Windows.UI;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.Backdrop;
|
||||
|
||||
internal sealed class TransparentBackdrop : SystemBackdrop, IDisposable, IBackdropNeedEraseBackground
|
||||
internal sealed class TransparentBackdrop : SystemBackdrop, IBackdropNeedEraseBackground
|
||||
{
|
||||
private readonly object compositorLock = new();
|
||||
private object? compositorLock;
|
||||
|
||||
private Color tintColor;
|
||||
private Windows.UI.Composition.CompositionColorBrush? brush;
|
||||
@@ -31,27 +31,14 @@ internal sealed class TransparentBackdrop : SystemBackdrop, IDisposable, IBackdr
|
||||
{
|
||||
get
|
||||
{
|
||||
if (compositor is null)
|
||||
return LazyInitializer.EnsureInitialized(ref compositor, ref compositorLock, () =>
|
||||
{
|
||||
lock (compositorLock)
|
||||
{
|
||||
if (compositor is null)
|
||||
{
|
||||
DispatcherQueue.EnsureSystemDispatcherQueue();
|
||||
compositor = new Windows.UI.Composition.Compositor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return compositor;
|
||||
DispatcherQueue.EnsureSystemDispatcherQueue();
|
||||
return new Windows.UI.Composition.Compositor();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
compositor?.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot)
|
||||
{
|
||||
brush ??= Compositor.CreateColorBrush(tintColor);
|
||||
@@ -61,5 +48,13 @@ internal sealed class TransparentBackdrop : SystemBackdrop, IDisposable, IBackdr
|
||||
protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
|
||||
{
|
||||
disconnectedTarget.SystemBackdrop = null;
|
||||
|
||||
if (compositorLock is not null)
|
||||
{
|
||||
lock (compositorLock)
|
||||
{
|
||||
compositor?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,10 @@ namespace Snap.Hutao.Core.Windowing.HotKey;
|
||||
[SuppressMessage("", "SA1124")]
|
||||
internal sealed class HotKeyCombination : ObservableObject
|
||||
{
|
||||
private readonly ICurrentWindowReference currentWindowReference;
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
|
||||
private readonly HWND hwnd;
|
||||
private readonly string settingKey;
|
||||
private readonly int hotKeyId;
|
||||
private readonly HotKeyParameter defaultHotKeyParameter;
|
||||
@@ -36,12 +36,12 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
private VirtualKey key;
|
||||
private bool isEnabled;
|
||||
|
||||
public HotKeyCombination(IServiceProvider serviceProvider, string settingKey, int hotKeyId, HOT_KEY_MODIFIERS defaultModifiers, VirtualKey defaultKey)
|
||||
public HotKeyCombination(IServiceProvider serviceProvider, HWND hwnd, string settingKey, int hotKeyId, HOT_KEY_MODIFIERS defaultModifiers, VirtualKey defaultKey)
|
||||
{
|
||||
currentWindowReference = serviceProvider.GetRequiredService<ICurrentWindowReference>();
|
||||
infoBarService = serviceProvider.GetRequiredService<IInfoBarService>();
|
||||
runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
|
||||
|
||||
this.hwnd = hwnd;
|
||||
this.settingKey = settingKey;
|
||||
this.hotKeyId = hotKeyId;
|
||||
defaultHotKeyParameter = new(defaultModifiers, defaultKey);
|
||||
@@ -53,7 +53,7 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
|
||||
HotKeyParameter actual = LocalSettingGetHotKeyParameter();
|
||||
modifiers = actual.Modifiers;
|
||||
InitializeModifiersComposeFields();
|
||||
InitializeModifiersCompositionFields();
|
||||
key = actual.Key;
|
||||
|
||||
keyNameValue = VirtualKeys.GetList().Single(v => v.Value == key);
|
||||
@@ -164,8 +164,8 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
|
||||
_ = (value, registered) switch
|
||||
{
|
||||
(true, false) => RegisterForCurrentWindow(),
|
||||
(false, true) => UnregisterForCurrentWindow(),
|
||||
(true, false) => Register(),
|
||||
(false, true) => Unregister(),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
@@ -174,7 +174,7 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
|
||||
public string DisplayName { get => ToString(); }
|
||||
|
||||
public bool RegisterForCurrentWindow()
|
||||
public bool Register()
|
||||
{
|
||||
if (!runtimeOptions.IsElevated || !IsEnabled)
|
||||
{
|
||||
@@ -186,7 +186,6 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
return true;
|
||||
}
|
||||
|
||||
HWND hwnd = currentWindowReference.GetWindowHandle();
|
||||
BOOL result = RegisterHotKey(hwnd, hotKeyId, Modifiers, (uint)Key);
|
||||
registered = result;
|
||||
|
||||
@@ -198,7 +197,7 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool UnregisterForCurrentWindow()
|
||||
public bool Unregister()
|
||||
{
|
||||
if (!runtimeOptions.IsElevated)
|
||||
{
|
||||
@@ -210,7 +209,6 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
return true;
|
||||
}
|
||||
|
||||
HWND hwnd = currentWindowReference.GetWindowHandle();
|
||||
BOOL result = UnregisterHotKey(hwnd, hotKeyId);
|
||||
registered = !result;
|
||||
return result;
|
||||
@@ -272,7 +270,7 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
Modifiers = modifiers;
|
||||
}
|
||||
|
||||
private void InitializeModifiersComposeFields()
|
||||
private void InitializeModifiersCompositionFields()
|
||||
{
|
||||
if (Modifiers.HasFlag(HOT_KEY_MODIFIERS.MOD_WIN))
|
||||
{
|
||||
@@ -309,7 +307,7 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
HotKeyParameter current = new(Modifiers, Key);
|
||||
LocalSetting.Set(settingKey, *(int*)¤t);
|
||||
|
||||
UnregisterForCurrentWindow();
|
||||
RegisterForCurrentWindow();
|
||||
Unregister();
|
||||
Register();
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.HotKey;
|
||||
|
||||
[SuppressMessage("", "CA1001")]
|
||||
[Injection(InjectAs.Singleton, typeof(IHotKeyController))]
|
||||
[ConstructorGenerated]
|
||||
internal sealed partial class HotKeyController : IHotKeyController
|
||||
{
|
||||
private static readonly WaitCallback RunMouseClickRepeatForever = MouseClickRepeatForever;
|
||||
|
||||
private readonly object syncRoot = new();
|
||||
|
||||
private readonly HotKeyOptions hotKeyOptions;
|
||||
|
||||
private volatile CancellationTokenSource? cancellationTokenSource;
|
||||
|
||||
public void RegisterAll()
|
||||
{
|
||||
hotKeyOptions.MouseClickRepeatForeverKeyCombination.RegisterForCurrentWindow();
|
||||
}
|
||||
|
||||
public void UnregisterAll()
|
||||
{
|
||||
hotKeyOptions.MouseClickRepeatForeverKeyCombination.UnregisterForCurrentWindow();
|
||||
}
|
||||
|
||||
public void OnHotKeyPressed(in HotKeyParameter parameter)
|
||||
{
|
||||
if (parameter.Equals(hotKeyOptions.MouseClickRepeatForeverKeyCombination))
|
||||
{
|
||||
ToggleMouseClickRepeatForever();
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe INPUT CreateInputForMouseEvent(MOUSE_EVENT_FLAGS flags)
|
||||
{
|
||||
INPUT input = default;
|
||||
input.type = INPUT_TYPE.INPUT_MOUSE;
|
||||
input.Anonymous.mi.dwFlags = flags;
|
||||
return input;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH007")]
|
||||
private static unsafe void MouseClickRepeatForever(object? state)
|
||||
{
|
||||
CancellationToken token = (CancellationToken)state!;
|
||||
|
||||
// We want to use this thread for a long time
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
INPUT[] inputs =
|
||||
[
|
||||
CreateInputForMouseEvent(MOUSE_EVENT_FLAGS.MOUSEEVENTF_LEFTDOWN),
|
||||
CreateInputForMouseEvent(MOUSE_EVENT_FLAGS.MOUSEEVENTF_LEFTUP),
|
||||
];
|
||||
|
||||
if (SendInput(inputs.AsSpan(), sizeof(INPUT)) is 0)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError());
|
||||
}
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(System.Random.Shared.Next(100, 150));
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleMouseClickRepeatForever()
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (hotKeyOptions.IsMouseClickRepeatForeverOn)
|
||||
{
|
||||
// Turn off
|
||||
cancellationTokenSource?.Cancel();
|
||||
cancellationTokenSource = default;
|
||||
hotKeyOptions.IsMouseClickRepeatForeverOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Turn on
|
||||
cancellationTokenSource = new();
|
||||
ThreadPool.QueueUserWorkItem(RunMouseClickRepeatForever, cancellationTokenSource.Token);
|
||||
hotKeyOptions.IsMouseClickRepeatForeverOn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.HotKey;
|
||||
|
||||
internal sealed class HotKeyMessageWindow : IDisposable
|
||||
{
|
||||
private const string WindowClassName = "SnapHutaoHotKeyMessageWindowClass";
|
||||
|
||||
private static readonly ConcurrentDictionary<HWND, HotKeyMessageWindow> WindowTable = [];
|
||||
|
||||
private bool isDisposed;
|
||||
|
||||
public unsafe HotKeyMessageWindow()
|
||||
{
|
||||
ushort atom;
|
||||
fixed (char* className = WindowClassName)
|
||||
{
|
||||
WNDCLASSW wc = new()
|
||||
{
|
||||
lpfnWndProc = WNDPROC.Create(&OnWindowProcedure),
|
||||
lpszClassName = className,
|
||||
};
|
||||
|
||||
atom = RegisterClassW(&wc);
|
||||
}
|
||||
|
||||
ArgumentOutOfRangeException.ThrowIfEqual<ushort>(atom, 0);
|
||||
|
||||
HWND = CreateWindowExW(0, WindowClassName, WindowClassName, 0, 0, 0, 0, 0, default, default, default, default);
|
||||
|
||||
if (HWND == default)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError());
|
||||
}
|
||||
|
||||
WindowTable.TryAdd(HWND, this);
|
||||
}
|
||||
|
||||
~HotKeyMessageWindow()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public Action<HotKeyParameter>? HotKeyPressed { get; set; }
|
||||
|
||||
public HWND HWND { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isDisposed = true;
|
||||
|
||||
DestroyWindow(HWND);
|
||||
WindowTable.TryRemove(HWND, out _);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||
private static unsafe LRESULT OnWindowProcedure(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (!WindowTable.TryGetValue(hwnd, out HotKeyMessageWindow? window))
|
||||
{
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_HOTKEY:
|
||||
window.HotKeyPressed?.Invoke(*(HotKeyParameter*)&lParam);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,35 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Win32.UI.Input.KeyboardAndMouse;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.System;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.HotKey;
|
||||
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class HotKeyOptions : ObservableObject
|
||||
internal sealed partial class HotKeyOptions : ObservableObject, IDisposable
|
||||
{
|
||||
private static readonly WaitCallback RunMouseClickRepeatForever = MouseClickRepeatForever;
|
||||
|
||||
private readonly object syncRoot = new();
|
||||
private readonly HotKeyMessageWindow hotKeyMessageWindow;
|
||||
|
||||
private volatile CancellationTokenSource? cancellationTokenSource;
|
||||
|
||||
private bool isDisposed;
|
||||
private bool isMouseClickRepeatForeverOn;
|
||||
private HotKeyCombination mouseClickRepeatForeverKeyCombination;
|
||||
|
||||
public HotKeyOptions(IServiceProvider serviceProvider)
|
||||
{
|
||||
mouseClickRepeatForeverKeyCombination = new(serviceProvider, SettingKeys.HotKeyMouseClickRepeatForever, 100000, default, VirtualKey.F8);
|
||||
hotKeyMessageWindow = new()
|
||||
{
|
||||
HotKeyPressed = OnHotKeyPressed,
|
||||
};
|
||||
|
||||
mouseClickRepeatForeverKeyCombination = new(serviceProvider, hotKeyMessageWindow.HWND, SettingKeys.HotKeyMouseClickRepeatForever, 100000, default, VirtualKey.F8);
|
||||
}
|
||||
|
||||
public List<NameValue<VirtualKey>> VirtualKeys { get; } = HotKey.VirtualKeys.GetList();
|
||||
@@ -32,4 +48,96 @@ internal sealed partial class HotKeyOptions : ObservableObject
|
||||
get => mouseClickRepeatForeverKeyCombination;
|
||||
set => SetProperty(ref mouseClickRepeatForeverKeyCombination, value);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isDisposed = true;
|
||||
|
||||
UnregisterAll();
|
||||
hotKeyMessageWindow.Dispose();
|
||||
cancellationTokenSource?.Dispose();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public void RegisterAll()
|
||||
{
|
||||
MouseClickRepeatForeverKeyCombination.Register();
|
||||
}
|
||||
|
||||
private static unsafe INPUT CreateInputForMouseEvent(MOUSE_EVENT_FLAGS flags)
|
||||
{
|
||||
INPUT input = default;
|
||||
input.type = INPUT_TYPE.INPUT_MOUSE;
|
||||
input.Anonymous.mi.dwFlags = flags;
|
||||
return input;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH007")]
|
||||
private static unsafe void MouseClickRepeatForever(object? state)
|
||||
{
|
||||
CancellationToken token = (CancellationToken)state!;
|
||||
|
||||
// We want to use this thread for a long time
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
INPUT[] inputs =
|
||||
[
|
||||
CreateInputForMouseEvent(MOUSE_EVENT_FLAGS.MOUSEEVENTF_LEFTDOWN),
|
||||
CreateInputForMouseEvent(MOUSE_EVENT_FLAGS.MOUSEEVENTF_LEFTUP),
|
||||
];
|
||||
|
||||
if (SendInput(inputs.AsSpan(), sizeof(INPUT)) is 0)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError());
|
||||
}
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(System.Random.Shared.Next(100, 150));
|
||||
}
|
||||
}
|
||||
|
||||
private void UnregisterAll()
|
||||
{
|
||||
MouseClickRepeatForeverKeyCombination.Unregister();
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
private void OnHotKeyPressed(HotKeyParameter parameter)
|
||||
{
|
||||
if (parameter.Equals(MouseClickRepeatForeverKeyCombination))
|
||||
{
|
||||
ToggleMouseClickRepeatForever();
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleMouseClickRepeatForever()
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (IsMouseClickRepeatForeverOn)
|
||||
{
|
||||
// Turn off
|
||||
cancellationTokenSource?.Cancel();
|
||||
cancellationTokenSource = default;
|
||||
IsMouseClickRepeatForeverOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Turn on
|
||||
cancellationTokenSource = new();
|
||||
ThreadPool.QueueUserWorkItem(RunMouseClickRepeatForever, cancellationTokenSource.Token);
|
||||
IsMouseClickRepeatForeverOn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.HotKey;
|
||||
|
||||
internal interface IHotKeyController
|
||||
{
|
||||
void OnHotKeyPressed(in HotKeyParameter parameter);
|
||||
|
||||
void RegisterAll();
|
||||
|
||||
void UnregisterAll();
|
||||
}
|
||||
@@ -6,10 +6,10 @@ namespace Snap.Hutao.Core.Windowing;
|
||||
/// <summary>
|
||||
/// 为扩展窗体提供必要的选项
|
||||
/// </summary>
|
||||
internal interface IWindowOptionsSource
|
||||
internal interface IXamlWindowOptionsSource
|
||||
{
|
||||
/// <summary>
|
||||
/// 窗体选项
|
||||
/// </summary>
|
||||
WindowOptions WindowOptions { get; }
|
||||
XamlWindowOptions WindowOptions { get; }
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<Flyout
|
||||
x:Class="Snap.Hutao.Core.Windowing.NotifyIcon.NotifyIconContextMenu"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
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:shcm="using:Snap.Hutao.Control.Markup"
|
||||
xmlns:shcwb="using:Snap.Hutao.Core.Windowing.Backdrop"
|
||||
xmlns:shv="using:Snap.Hutao.ViewModel"
|
||||
ShouldConstrainToRootBounds="False"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Flyout.SystemBackdrop>
|
||||
<shcwb:InputActiveDesktopAcrylicBackdrop/>
|
||||
</Flyout.SystemBackdrop>
|
||||
|
||||
<Flyout.FlyoutPresenterStyle>
|
||||
<Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
</Flyout.FlyoutPresenterStyle>
|
||||
|
||||
<Grid
|
||||
x:Name="Root"
|
||||
d:DataContext="{d:DesignInstance shv:NotifyIconViewModel}"
|
||||
Background="Transparent">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="8" Text="{Binding Title}"/>
|
||||
<Grid Grid.Row="1" Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}">
|
||||
<StackPanel
|
||||
Margin="4,0"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal"
|
||||
Spacing="2">
|
||||
<AppBarButton Command="{Binding ShowWindowCommand}" Label="{shcm:ResourceString Name=CoreWindowingNotifyIconViewLabel}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Height="20"
|
||||
Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
<AppBarButton Command="{Binding LaunchGameCommand}" Label="{shcm:ResourceString Name=CoreWindowingNotifyIconLaunchGameLabel}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Height="20"
|
||||
Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
<AppBarButton Command="{Binding ExitCommand}" Label="{shcm:ResourceString Name=CoreWindowingNotifyIconExitLabel}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Height="20"
|
||||
Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Flyout>
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.ViewModel;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
internal sealed partial class NotifyIconContextMenu : Flyout
|
||||
{
|
||||
public NotifyIconContextMenu(IServiceProvider serviceProvider)
|
||||
{
|
||||
AllowFocusOnInteraction = false;
|
||||
InitializeComponent();
|
||||
Root.DataContext = serviceProvider.GetRequiredService<NotifyIconViewModel>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Storage;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed class NotifyIconController : IDisposable
|
||||
{
|
||||
private readonly LazySlim<NotifyIconContextMenu> lazyMenu;
|
||||
private readonly NotifyIconXamlHostWindow xamlHostWindow;
|
||||
private readonly NotifyIconMessageWindow messageWindow;
|
||||
private readonly System.Drawing.Icon icon;
|
||||
|
||||
public NotifyIconController(IServiceProvider serviceProvider)
|
||||
{
|
||||
lazyMenu = new(() => new(serviceProvider));
|
||||
|
||||
StorageFile iconFile = StorageFile.GetFileFromApplicationUriAsync("ms-appx:///Assets/Logo.ico".ToUri()).AsTask().GetAwaiter().GetResult();
|
||||
icon = new(iconFile.Path);
|
||||
|
||||
xamlHostWindow = new();
|
||||
|
||||
messageWindow = new()
|
||||
{
|
||||
TaskbarCreated = OnRecreateNotifyIconRequested,
|
||||
ContextMenuRequested = OnContextMenuRequested,
|
||||
};
|
||||
|
||||
CreateNotifyIcon();
|
||||
}
|
||||
|
||||
private static ref readonly Guid Id
|
||||
{
|
||||
get
|
||||
{
|
||||
// MD5 for "Snap.Hutao"
|
||||
ReadOnlySpan<byte> data = [0xEE, 0x01, 0x5C, 0xCB, 0xF3, 0x97, 0xC6, 0x93, 0xE8, 0x77, 0xCE, 0x09, 0x54, 0x90, 0xEE, 0xAC];
|
||||
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
messageWindow.Dispose();
|
||||
NotifyIconMethods.Delete(Id);
|
||||
icon.Dispose();
|
||||
|
||||
xamlHostWindow.Dispose();
|
||||
}
|
||||
|
||||
private void OnRecreateNotifyIconRequested(NotifyIconMessageWindow window)
|
||||
{
|
||||
NotifyIconMethods.Delete(Id);
|
||||
if (!NotifyIconMethods.Add(Id, window.HWND, "Snap Hutao", NotifyIconMessageWindow.WM_NOTIFYICON_CALLBACK, (HICON)icon.Handle))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to recreate NotifyIcon");
|
||||
}
|
||||
|
||||
if (!NotifyIconMethods.SetVersion(Id, NOTIFYICON_VERSION_4))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to set NotifyIcon version");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateNotifyIcon()
|
||||
{
|
||||
NotifyIconMethods.Delete(Id);
|
||||
if (!NotifyIconMethods.Add(Id, messageWindow.HWND, "Snap Hutao", NotifyIconMessageWindow.WM_NOTIFYICON_CALLBACK, (HICON)icon.Handle))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to create NotifyIcon");
|
||||
}
|
||||
|
||||
if (!NotifyIconMethods.SetVersion(Id, NOTIFYICON_VERSION_4))
|
||||
{
|
||||
HutaoException.InvalidOperation("Failed to set NotifyIcon version");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnContextMenuRequested(NotifyIconMessageWindow window, PointUInt16 point)
|
||||
{
|
||||
RECT iconRect = NotifyIconMethods.GetRect(Id, window.HWND);
|
||||
xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), iconRect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
[SuppressMessage("", "SA1310")]
|
||||
internal sealed class NotifyIconMessageWindow : IDisposable
|
||||
{
|
||||
public const uint WM_NOTIFYICON_CALLBACK = 0x444U;
|
||||
private const string WindowClassName = "SnapHutaoNotifyIconMessageWindowClass";
|
||||
|
||||
private static readonly ConcurrentDictionary<HWND, NotifyIconMessageWindow> WindowTable = [];
|
||||
|
||||
[SuppressMessage("", "SA1306")]
|
||||
private readonly uint WM_TASKBARCREATED;
|
||||
|
||||
private bool isDisposed;
|
||||
|
||||
public unsafe NotifyIconMessageWindow()
|
||||
{
|
||||
ushort atom;
|
||||
fixed (char* className = WindowClassName)
|
||||
{
|
||||
WNDCLASSW wc = new()
|
||||
{
|
||||
lpfnWndProc = WNDPROC.Create(&OnWindowProcedure),
|
||||
lpszClassName = className,
|
||||
};
|
||||
|
||||
atom = RegisterClassW(&wc);
|
||||
}
|
||||
|
||||
ArgumentOutOfRangeException.ThrowIfEqual<ushort>(atom, 0);
|
||||
|
||||
// https://learn.microsoft.com/zh,cn/windows/win32/shell/taskbar#taskbar,creation,notification
|
||||
WM_TASKBARCREATED = RegisterWindowMessageW("TaskbarCreated");
|
||||
|
||||
HWND = CreateWindowExW(0, WindowClassName, WindowClassName, 0, 0, 0, 0, 0, default, default, default, default);
|
||||
|
||||
if (HWND == default)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError());
|
||||
}
|
||||
|
||||
WindowTable.TryAdd(HWND, this);
|
||||
}
|
||||
|
||||
~NotifyIconMessageWindow()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public Action<NotifyIconMessageWindow>? TaskbarCreated { get; set; }
|
||||
|
||||
public Action<NotifyIconMessageWindow, PointUInt16>? ContextMenuRequested { get; set; }
|
||||
|
||||
public HWND HWND { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isDisposed = true;
|
||||
|
||||
DestroyWindow(HWND);
|
||||
WindowTable.TryRemove(HWND, out _);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||
private static unsafe LRESULT OnWindowProcedure(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (!WindowTable.TryGetValue(hwnd, out NotifyIconMessageWindow? window))
|
||||
{
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
if (uMsg == window.WM_TASKBARCREATED)
|
||||
{
|
||||
// TODO: Re-add the notify icon.
|
||||
window.TaskbarCreated?.Invoke(window);
|
||||
}
|
||||
|
||||
// https://learn.microsoft.com/zh-cn/windows/win32/api/shellapi/ns-shellapi-notifyicondataw
|
||||
if (uMsg is WM_NOTIFYICON_CALLBACK)
|
||||
{
|
||||
LPARAM2 lParam2 = *(LPARAM2*)&lParam;
|
||||
PointUInt16 wParam2 = *(PointUInt16*)&wParam;
|
||||
|
||||
switch (lParam2.Low)
|
||||
{
|
||||
case WM_CONTEXTMENU:
|
||||
window.ContextMenuRequested?.Invoke(window, wParam2);
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
// X: wParam2.X Y: wParam2.Y Low: WM_MOUSEMOVE
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONUP:
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_RBUTTONUP:
|
||||
break;
|
||||
case NIN_SELECT:
|
||||
// X: wParam2.X Y: wParam2.Y Low: NIN_SELECT
|
||||
break;
|
||||
case NIN_POPUPOPEN:
|
||||
// X: wParam2.X Y: 0? Low: NIN_POPUPOPEN
|
||||
break;
|
||||
case NIN_POPUPCLOSE:
|
||||
// X: wParam2.X Y: 0? Low: NIN_POPUPCLOSE
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_ACTIVATEAPP:
|
||||
break;
|
||||
case WM_DWMNCRENDERINGCHANGED:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
private readonly struct LPARAM2
|
||||
{
|
||||
public readonly uint Low;
|
||||
public readonly uint High;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.Shell;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Snap.Hutao.Win32.Shell32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
internal sealed class NotifyIconMethods
|
||||
{
|
||||
public static BOOL Add(ref readonly NOTIFYICONDATAW data)
|
||||
{
|
||||
return Shell_NotifyIconW(NOTIFY_ICON_MESSAGE.NIM_ADD, in data);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe BOOL Add(Guid id, HWND hWnd, string tip, uint uCallbackMessage, HICON hIcon)
|
||||
{
|
||||
NOTIFYICONDATAW data = default;
|
||||
data.cbSize = (uint)sizeof(NOTIFYICONDATAW);
|
||||
data.uFlags = NOTIFY_ICON_DATA_FLAGS.NIF_MESSAGE | NOTIFY_ICON_DATA_FLAGS.NIF_ICON | NOTIFY_ICON_DATA_FLAGS.NIF_TIP | NOTIFY_ICON_DATA_FLAGS.NIF_GUID;
|
||||
data.guidItem = id;
|
||||
data.hWnd = hWnd;
|
||||
tip.AsSpan().CopyTo(new(data.szTip, 128));
|
||||
data.uCallbackMessage = uCallbackMessage;
|
||||
data.hIcon = hIcon;
|
||||
data.dwState = NOTIFY_ICON_STATE.NIS_HIDDEN;
|
||||
data.dwStateMask = NOTIFY_ICON_STATE.NIS_HIDDEN;
|
||||
|
||||
return Add(in data);
|
||||
}
|
||||
|
||||
public static BOOL Modify(ref readonly NOTIFYICONDATAW data)
|
||||
{
|
||||
return Shell_NotifyIconW(NOTIFY_ICON_MESSAGE.NIM_MODIFY, in data);
|
||||
}
|
||||
|
||||
public static BOOL Delete(ref readonly NOTIFYICONDATAW data)
|
||||
{
|
||||
return Shell_NotifyIconW(NOTIFY_ICON_MESSAGE.NIM_DELETE, in data);
|
||||
}
|
||||
|
||||
public static unsafe BOOL Delete(Guid id)
|
||||
{
|
||||
NOTIFYICONDATAW data = default;
|
||||
data.cbSize = (uint)sizeof(NOTIFYICONDATAW);
|
||||
data.uFlags = NOTIFY_ICON_DATA_FLAGS.NIF_GUID;
|
||||
data.guidItem = id;
|
||||
|
||||
return Delete(in data);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe RECT GetRect(Guid id, HWND hWND)
|
||||
{
|
||||
NOTIFYICONIDENTIFIER identifier = new()
|
||||
{
|
||||
cbSize = (uint)sizeof(NOTIFYICONIDENTIFIER),
|
||||
hWnd = hWND,
|
||||
guidItem = id,
|
||||
};
|
||||
|
||||
Marshal.ThrowExceptionForHR(Shell_NotifyIconGetRect(ref identifier, out RECT rect));
|
||||
return rect;
|
||||
}
|
||||
|
||||
public static BOOL SetFocus(ref readonly NOTIFYICONDATAW data)
|
||||
{
|
||||
return Shell_NotifyIconW(NOTIFY_ICON_MESSAGE.NIM_SETFOCUS, in data);
|
||||
}
|
||||
|
||||
public static BOOL SetVersion(ref readonly NOTIFYICONDATAW data)
|
||||
{
|
||||
return Shell_NotifyIconW(NOTIFY_ICON_MESSAGE.NIM_SETVERSION, in data);
|
||||
}
|
||||
|
||||
public static unsafe BOOL SetVersion(Guid id, uint version)
|
||||
{
|
||||
NOTIFYICONDATAW data = default;
|
||||
data.cbSize = (uint)sizeof(NOTIFYICONDATAW);
|
||||
data.uFlags = NOTIFY_ICON_DATA_FLAGS.NIF_GUID;
|
||||
data.guidItem = id;
|
||||
data.Anonymous.uVersion = version;
|
||||
|
||||
return SetVersion(in data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Snap.Hutao.Core.Windowing.Backdrop;
|
||||
using Snap.Hutao.Win32;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using Windows.Foundation;
|
||||
using WinRT.Interop;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
internal sealed class NotifyIconXamlHostWindow : Window, IDisposable, IWindowNeedEraseBackground
|
||||
{
|
||||
private readonly XamlWindowSubclass subclass;
|
||||
|
||||
public NotifyIconXamlHostWindow()
|
||||
{
|
||||
Content = new Border();
|
||||
|
||||
this.SetLayeredWindow();
|
||||
|
||||
AppWindow.Title = "SnapHutaoNotifyIconXamlHost";
|
||||
AppWindow.IsShownInSwitchers = false;
|
||||
if (AppWindow.Presenter is OverlappedPresenter presenter)
|
||||
{
|
||||
presenter.IsMaximizable = false;
|
||||
presenter.IsMinimizable = false;
|
||||
presenter.IsResizable = false;
|
||||
presenter.IsAlwaysOnTop = true;
|
||||
presenter.SetBorderAndTitleBar(false, false);
|
||||
}
|
||||
|
||||
XamlWindowOptions options = new(this, default!, default);
|
||||
subclass = new(this, options);
|
||||
subclass.Initialize();
|
||||
|
||||
Activate();
|
||||
}
|
||||
|
||||
public void ShowFlyoutAt(FlyoutBase flyout, Point point, RECT icon)
|
||||
{
|
||||
icon.left -= 8;
|
||||
icon.top -= 8;
|
||||
icon.right += 8;
|
||||
icon.bottom += 8;
|
||||
|
||||
HWND hwnd = WindowNative.GetWindowHandle(this);
|
||||
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_NORMAL);
|
||||
SetForegroundWindow(hwnd);
|
||||
|
||||
AppWindow.MoveAndResize(StructMarshal.RectInt32(icon));
|
||||
flyout.ShowAt(Content, new()
|
||||
{
|
||||
Placement = FlyoutPlacementMode.Auto,
|
||||
ShowMode = FlyoutShowMode.Transient,
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
subclass.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
|
||||
internal readonly struct PointUInt16
|
||||
{
|
||||
public readonly ushort X;
|
||||
public readonly ushort Y;
|
||||
}
|
||||
@@ -2,30 +2,67 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Hosting;
|
||||
using Snap.Hutao.Core.Windowing.Backdrop;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Runtime.CompilerServices;
|
||||
using WinRT.Interop;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
internal static class WindowExtension
|
||||
{
|
||||
private static readonly ConditionalWeakTable<Window, WindowController> WindowControllers = [];
|
||||
private static readonly ConditionalWeakTable<Window, XamlWindowController> WindowControllers = [];
|
||||
|
||||
public static void InitializeController<TWindow>(this TWindow window, IServiceProvider serviceProvider)
|
||||
where TWindow : Window, IWindowOptionsSource
|
||||
where TWindow : Window, IXamlWindowOptionsSource
|
||||
{
|
||||
WindowController windowController = new(window, window.WindowOptions, serviceProvider);
|
||||
XamlWindowController windowController = new(window, window.WindowOptions, serviceProvider);
|
||||
WindowControllers.Add(window, windowController);
|
||||
}
|
||||
|
||||
public static bool IsControllerInitialized<TWindow>(this TWindow window)
|
||||
where TWindow : Window
|
||||
{
|
||||
return WindowControllers.TryGetValue(window, out _);
|
||||
}
|
||||
|
||||
public static void SetLayeredWindow(this Window window)
|
||||
{
|
||||
HWND hwnd = (HWND)WindowNative.GetWindowHandle(window);
|
||||
nint style = GetWindowLongPtrW(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE);
|
||||
style |= (nint)WINDOW_EX_STYLE.WS_EX_LAYERED;
|
||||
SetWindowLongPtrW(hwnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, style);
|
||||
SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LAYERED_WINDOW_ATTRIBUTES_FLAGS.LWA_COLORKEY | LAYERED_WINDOW_ATTRIBUTES_FLAGS.LWA_ALPHA);
|
||||
}
|
||||
|
||||
public static void Show(this Window window)
|
||||
{
|
||||
ShowWindow(GetWindowHandle(window), SHOW_WINDOW_CMD.SW_NORMAL);
|
||||
}
|
||||
|
||||
public static void Hide(this Window window)
|
||||
{
|
||||
ShowWindow(GetWindowHandle(window), SHOW_WINDOW_CMD.SW_HIDE);
|
||||
}
|
||||
|
||||
public static DesktopWindowXamlSource? GetDesktopWindowXamlSource(this Window window)
|
||||
{
|
||||
if (window.SystemBackdrop is SystemBackdropDesktopWindowXamlSourceAccess access)
|
||||
{
|
||||
return access.DesktopWindowXamlSource;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static HWND GetWindowHandle(this Window? window)
|
||||
{
|
||||
return window is IXamlWindowOptionsSource optionsSource
|
||||
? optionsSource.WindowOptions.Hwnd
|
||||
: WindowNative.GetWindowHandle(window);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ using Snap.Hutao.Win32;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Dwm;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Collections.Frozen;
|
||||
using System.IO;
|
||||
using Windows.Graphics;
|
||||
using Windows.UI;
|
||||
@@ -23,23 +22,21 @@ using static Snap.Hutao.Win32.User32;
|
||||
namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
[SuppressMessage("", "CA1001")]
|
||||
internal sealed class WindowController
|
||||
internal sealed class XamlWindowController
|
||||
{
|
||||
private readonly Window window;
|
||||
private readonly WindowOptions options;
|
||||
private readonly XamlWindowOptions options;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly WindowSubclass subclass;
|
||||
private readonly WindowNonRudeHWND windowNonRudeHWND;
|
||||
private readonly XamlWindowSubclass subclass;
|
||||
private readonly XamlWindowNonRudeHWND windowNonRudeHWND;
|
||||
|
||||
public WindowController(Window window, in WindowOptions options, IServiceProvider serviceProvider)
|
||||
public XamlWindowController(Window window, in XamlWindowOptions options, IServiceProvider serviceProvider)
|
||||
{
|
||||
this.window = window;
|
||||
this.options = options;
|
||||
this.serviceProvider = serviceProvider;
|
||||
|
||||
// Window reference must be set before Window Subclass created
|
||||
serviceProvider.GetRequiredService<ICurrentWindowReference>().Window = window;
|
||||
subclass = new(window, options, serviceProvider);
|
||||
subclass = new(window, options);
|
||||
windowNonRudeHWND = new(options.Hwnd);
|
||||
|
||||
InitializeCore();
|
||||
@@ -90,9 +87,9 @@ internal sealed class WindowController
|
||||
SizeInt32 scaledSize = options.InitSize.Scale(scale);
|
||||
RectInt32 rect = StructMarshal.RectInt32(scaledSize);
|
||||
|
||||
if (options.PersistSize)
|
||||
if (!string.IsNullOrEmpty(options.PersistRectKey))
|
||||
{
|
||||
RectInt32 persistedRect = (CompactRect)LocalSetting.Get(SettingKeys.WindowRect, (CompactRect)rect);
|
||||
RectInt32 persistedRect = (CompactRect)LocalSetting.Get(options.PersistRectKey, (CompactRect)rect);
|
||||
if (persistedRect.Size() >= options.InitSize.Size())
|
||||
{
|
||||
rect = persistedRect.Scale(scale);
|
||||
@@ -105,7 +102,7 @@ internal sealed class WindowController
|
||||
|
||||
private void SaveOrSkipWindowSize()
|
||||
{
|
||||
if (!options.PersistSize)
|
||||
if (string.IsNullOrEmpty(options.PersistRectKey))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -117,7 +114,7 @@ internal sealed class WindowController
|
||||
if (!windowPlacement.ShowCmd.HasFlag(SHOW_WINDOW_CMD.SW_SHOWMAXIMIZED))
|
||||
{
|
||||
double scale = 1.0 / options.GetRasterizationScale();
|
||||
LocalSetting.Set(SettingKeys.WindowRect, (CompactRect)window.AppWindow.GetRect().Scale(scale));
|
||||
LocalSetting.Set(options.PersistRectKey, (CompactRect)window.AppWindow.GetRect().Scale(scale));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,9 +135,25 @@ internal sealed class WindowController
|
||||
|
||||
private void OnWindowClosed(object sender, WindowEventArgs args)
|
||||
{
|
||||
SaveOrSkipWindowSize();
|
||||
subclass?.Dispose();
|
||||
windowNonRudeHWND?.Dispose();
|
||||
if (LocalSetting.Get(SettingKeys.IsNotifyIconEnabled, true) && !serviceProvider.GetRequiredService<App>().IsExiting)
|
||||
{
|
||||
args.Handled = true;
|
||||
window.Hide();
|
||||
|
||||
ICurrentXamlWindowReference currentXamlWindowReference = serviceProvider.GetRequiredService<ICurrentXamlWindowReference>();
|
||||
if (currentXamlWindowReference.Window == window)
|
||||
{
|
||||
currentXamlWindowReference.Window = default!;
|
||||
}
|
||||
|
||||
GC.Collect(GC.MaxGeneration);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveOrSkipWindowSize();
|
||||
subclass?.Dispose();
|
||||
windowNonRudeHWND?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void ExtendsContentIntoTitleBar()
|
||||
@@ -157,7 +170,7 @@ internal sealed class WindowController
|
||||
|
||||
private bool UpdateSystemBackdrop(BackdropType backdropType)
|
||||
{
|
||||
window.SystemBackdrop = backdropType switch
|
||||
SystemBackdrop? actualBackdop = backdropType switch
|
||||
{
|
||||
BackdropType.Transparent => new Backdrop.TransparentBackdrop(),
|
||||
BackdropType.MicaAlt => new MicaBackdrop() { Kind = MicaKind.BaseAlt },
|
||||
@@ -166,6 +179,8 @@ internal sealed class WindowController
|
||||
_ => null,
|
||||
};
|
||||
|
||||
window.SystemBackdrop = new Backdrop.SystemBackdropDesktopWindowXamlSourceAccess(actualBackdop);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
internal sealed class WindowNonRudeHWND : IDisposable
|
||||
internal sealed class XamlWindowNonRudeHWND : IDisposable
|
||||
{
|
||||
// https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist2-markfullscreenwindow#remarks
|
||||
private const string NonRudeHWND = "NonRudeHWND";
|
||||
private readonly HWND hwnd;
|
||||
|
||||
public WindowNonRudeHWND(HWND hwnd)
|
||||
public XamlWindowNonRudeHWND(HWND hwnd)
|
||||
{
|
||||
this.hwnd = hwnd;
|
||||
SetPropW(hwnd, NonRudeHWND, BOOL.TRUE);
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Input;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Windows.Graphics;
|
||||
@@ -14,7 +13,7 @@ namespace Snap.Hutao.Core.Windowing;
|
||||
/// <summary>
|
||||
/// Window 选项
|
||||
/// </summary>
|
||||
internal readonly struct WindowOptions
|
||||
internal readonly struct XamlWindowOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 窗体句柄
|
||||
@@ -39,15 +38,18 @@ internal readonly struct WindowOptions
|
||||
/// <summary>
|
||||
/// 是否持久化尺寸
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public readonly bool PersistSize;
|
||||
|
||||
public WindowOptions(Window window, FrameworkElement titleBar, SizeInt32 initSize, bool persistSize = false)
|
||||
public readonly string? PersistRectKey;
|
||||
|
||||
public XamlWindowOptions(Window window, FrameworkElement titleBar, SizeInt32 initSize, string? persistSize = default)
|
||||
{
|
||||
Hwnd = WindowNative.GetWindowHandle(window);
|
||||
InputNonClientPointerSource = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id);
|
||||
TitleBar = titleBar;
|
||||
InitSize = initSize;
|
||||
PersistSize = persistSize;
|
||||
PersistRectKey = persistSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -3,73 +3,65 @@
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Windowing.Backdrop;
|
||||
using Snap.Hutao.Core.Windowing.HotKey;
|
||||
using Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
using Snap.Hutao.Win32;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.Shell;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Snap.Hutao.Win32.ComCtl32;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
/// <summary>
|
||||
/// 窗体子类管理器
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed class WindowSubclass : IDisposable
|
||||
internal sealed class XamlWindowSubclass : IDisposable
|
||||
{
|
||||
private const int WindowSubclassId = 101;
|
||||
|
||||
private readonly Window window;
|
||||
private readonly WindowOptions options;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IHotKeyController hotKeyController;
|
||||
private readonly XamlWindowOptions options;
|
||||
|
||||
// We have to explicitly hold a reference to SUBCLASSPROC
|
||||
private SUBCLASSPROC windowProc = default!;
|
||||
private UnmanagedAccess<XamlWindowSubclass> unmanagedAccess = default!;
|
||||
|
||||
public WindowSubclass(Window window, in WindowOptions options, IServiceProvider serviceProvider)
|
||||
public XamlWindowSubclass(Window window, in XamlWindowOptions options)
|
||||
{
|
||||
this.window = window;
|
||||
this.options = options;
|
||||
this.serviceProvider = serviceProvider;
|
||||
|
||||
hotKeyController = serviceProvider.GetRequiredService<IHotKeyController>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试设置窗体子类
|
||||
/// </summary>
|
||||
/// <returns>是否设置成功</returns>
|
||||
public bool Initialize()
|
||||
public unsafe bool Initialize()
|
||||
{
|
||||
windowProc = OnSubclassProcedure;
|
||||
bool windowHooked = SetWindowSubclass(options.Hwnd, windowProc, WindowSubclassId, 0);
|
||||
hotKeyController.RegisterAll();
|
||||
|
||||
return windowHooked;
|
||||
windowProc = SUBCLASSPROC.Create(&OnSubclassProcedure);
|
||||
unmanagedAccess = UnmanagedAccess.Create(this);
|
||||
return SetWindowSubclass(options.Hwnd, windowProc, WindowSubclassId, unmanagedAccess);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
hotKeyController.UnregisterAll();
|
||||
|
||||
RemoveWindowSubclass(options.Hwnd, windowProc, WindowSubclassId);
|
||||
windowProc = default!;
|
||||
unmanagedAccess.Dispose();
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
private unsafe LRESULT OnSubclassProcedure(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam, nuint uIdSubclass, nuint dwRefData)
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||
private static unsafe LRESULT OnSubclassProcedure(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam, nuint uIdSubclass, nuint dwRefData)
|
||||
{
|
||||
XamlWindowSubclass? state = UnmanagedAccess.Get<XamlWindowSubclass>(dwRefData);
|
||||
ArgumentNullException.ThrowIfNull(state);
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_GETMINMAXINFO:
|
||||
{
|
||||
if (window is IMinMaxInfoHandler handler)
|
||||
if (state.window is IMinMaxInfoHandler handler)
|
||||
{
|
||||
handler.HandleMinMaxInfo(ref *(MINMAXINFO*)lParam, options.GetRasterizationScale());
|
||||
handler.HandleMinMaxInfo(ref *(MINMAXINFO*)lParam, state.options.GetRasterizationScale());
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -81,15 +73,9 @@ internal sealed class WindowSubclass : IDisposable
|
||||
return default;
|
||||
}
|
||||
|
||||
case WM_HOTKEY:
|
||||
{
|
||||
hotKeyController.OnHotKeyPressed(*(HotKeyParameter*)&lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
{
|
||||
if (window.SystemBackdrop is IBackdropNeedEraseBackground)
|
||||
if (state.window is IWindowNeedEraseBackground || state.window.SystemBackdrop is IBackdropNeedEraseBackground)
|
||||
{
|
||||
return (LRESULT)(int)BOOL.TRUE;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Factory.ContentDialog;
|
||||
[Injection(InjectAs.Singleton, typeof(IContentDialogFactory))]
|
||||
internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
{
|
||||
private readonly ICurrentWindowReference currentWindowReference;
|
||||
private readonly ICurrentXamlWindowReference currentWindowReference;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly AppOptions appOptions;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Snap.Hutao.Factory.Picker;
|
||||
[Injection(InjectAs.Transient, typeof(IFileSystemPickerInteraction))]
|
||||
internal sealed partial class FileSystemPickerInteraction : IFileSystemPickerInteraction
|
||||
{
|
||||
private readonly ICurrentWindowReference currentWindowReference;
|
||||
private readonly ICurrentXamlWindowReference currentWindowReference;
|
||||
|
||||
public unsafe ValueResult<bool, ValueFile> PickFile(string? title, string? defaultFileName, (string Name, string Type)[]? filters)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
@@ -11,7 +12,7 @@ namespace Snap.Hutao;
|
||||
/// 指引窗口
|
||||
/// </summary>
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class GuideWindow : Window, IWindowOptionsSource, IMinMaxInfoHandler
|
||||
internal sealed partial class GuideWindow : Window, IXamlWindowOptionsSource, IMinMaxInfoHandler
|
||||
{
|
||||
private const int MinWidth = 1000;
|
||||
private const int MinHeight = 650;
|
||||
@@ -19,16 +20,16 @@ internal sealed partial class GuideWindow : Window, IWindowOptionsSource, IMinMa
|
||||
private const int MaxWidth = 1200;
|
||||
private const int MaxHeight = 800;
|
||||
|
||||
private readonly WindowOptions windowOptions;
|
||||
private readonly XamlWindowOptions windowOptions;
|
||||
|
||||
public GuideWindow(IServiceProvider serviceProvider)
|
||||
{
|
||||
InitializeComponent();
|
||||
windowOptions = new(this, DragableGrid, new(MinWidth, MinHeight));
|
||||
windowOptions = new(this, DragableGrid, new(MinWidth, MinHeight), SettingKeys.GuideWindowRect);
|
||||
this.InitializeController(serviceProvider);
|
||||
}
|
||||
|
||||
WindowOptions IWindowOptionsSource.WindowOptions { get => windowOptions; }
|
||||
XamlWindowOptions IXamlWindowOptionsSource.WindowOptions { get => windowOptions; }
|
||||
|
||||
public unsafe void HandleMinMaxInfo(ref MINMAXINFO info, double scalingFactor)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ internal sealed partial class IdentifyMonitorWindow : Window
|
||||
{
|
||||
List<IdentifyMonitorWindow> windows = [];
|
||||
|
||||
// TODO: the order here is not sync with unity.
|
||||
IReadOnlyList<DisplayArea> displayAreas = DisplayArea.FindAll();
|
||||
for (int i = 0; i < displayAreas.Count; i++)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,18 @@
|
||||
"Equatable": true,
|
||||
"EqualityOperators": true
|
||||
},
|
||||
{
|
||||
"Name": "ChapterId",
|
||||
"Documentation": "章节 Id",
|
||||
"Equatable": true,
|
||||
"EqualityOperators": true
|
||||
},
|
||||
{
|
||||
"Name": "ChapterGroupId",
|
||||
"Documentation": "章节分组 Id",
|
||||
"Equatable": true,
|
||||
"EqualityOperators": true
|
||||
},
|
||||
{
|
||||
"Name": "EquipAffixId",
|
||||
"Documentation": "装备属性 Id",
|
||||
@@ -113,6 +125,12 @@
|
||||
"Equatable": true,
|
||||
"EqualityOperators": true
|
||||
},
|
||||
{
|
||||
"Name": "QuestId",
|
||||
"Documentation": "任务 Id",
|
||||
"Equatable": true,
|
||||
"EqualityOperators": true
|
||||
},
|
||||
{
|
||||
"Name": "ReliquaryLevel",
|
||||
"Documentation": "圣遗物等级 1 - 21",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.ViewModel.Game;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
@@ -14,7 +15,7 @@ namespace Snap.Hutao;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOptionsSource, IMinMaxInfoHandler
|
||||
internal sealed partial class LaunchGameWindow : Window, IDisposable, IXamlWindowOptionsSource, IMinMaxInfoHandler
|
||||
{
|
||||
private const int MinWidth = 240;
|
||||
private const int MinHeight = 240;
|
||||
@@ -22,7 +23,7 @@ internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOpt
|
||||
private const int MaxWidth = 320;
|
||||
private const int MaxHeight = 320;
|
||||
|
||||
private readonly WindowOptions windowOptions;
|
||||
private readonly XamlWindowOptions windowOptions;
|
||||
private readonly IServiceScope scope;
|
||||
|
||||
/// <summary>
|
||||
@@ -40,7 +41,7 @@ internal sealed partial class LaunchGameWindow : Window, IDisposable, IWindowOpt
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public WindowOptions WindowOptions { get => windowOptions; }
|
||||
public XamlWindowOptions WindowOptions { get => windowOptions; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Content;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
@@ -12,13 +14,12 @@ namespace Snap.Hutao;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
[SuppressMessage("", "CA1001")]
|
||||
internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMaxInfoHandler
|
||||
internal sealed partial class MainWindow : Window, IXamlWindowOptionsSource, IMinMaxInfoHandler
|
||||
{
|
||||
private const int MinWidth = 1000;
|
||||
private const int MinHeight = 600;
|
||||
|
||||
private readonly WindowOptions windowOptions;
|
||||
private readonly XamlWindowOptions windowOptions;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的主窗体
|
||||
@@ -27,12 +28,18 @@ internal sealed partial class MainWindow : Window, IWindowOptionsSource, IMinMax
|
||||
public MainWindow(IServiceProvider serviceProvider)
|
||||
{
|
||||
InitializeComponent();
|
||||
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), true);
|
||||
windowOptions = new(this, TitleBarView.DragArea, new(1200, 741), SettingKeys.WindowRect);
|
||||
this.InitializeController(serviceProvider);
|
||||
|
||||
if (this.GetDesktopWindowXamlSource() is { } desktopWindowXamlSource)
|
||||
{
|
||||
DesktopChildSiteBridge desktopChildSiteBridge = desktopWindowXamlSource.SiteBridge;
|
||||
desktopChildSiteBridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public WindowOptions WindowOptions { get => windowOptions; }
|
||||
public XamlWindowOptions WindowOptions { get => windowOptions; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public unsafe void HandleMinMaxInfo(ref MINMAXINFO pInfo, double scalingFactor)
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Snap.Hutao.Core.Abstraction;
|
||||
using Snap.Hutao.Model.Entity.Abstraction;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.DailyNote;
|
||||
using Snap.Hutao.ViewModel.User;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.Binding;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote;
|
||||
@@ -53,6 +55,9 @@ internal sealed class DailyNoteEntry : ObservableObject, IMappingFrom<DailyNoteE
|
||||
/// </summary>
|
||||
public DailyNote? DailyNote { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public DailyNoteArchonQuestView ArchonQuestView { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 刷新时间
|
||||
/// </summary>
|
||||
@@ -128,4 +133,4 @@ internal sealed class DailyNoteEntry : ObservableObject, IMappingFrom<DailyNoteE
|
||||
other.ExpeditionNotifySuppressed = ExpeditionNotifySuppressed;
|
||||
other.OnPropertyChanged(nameof(ExpeditionNotifySuppressed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,42 @@
|
||||
|
||||
namespace Snap.Hutao.Model.Intrinsic;
|
||||
|
||||
internal enum QuestType
|
||||
internal enum QuestType : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Archon Quest 魔神任务
|
||||
/// </summary>
|
||||
AQ,
|
||||
|
||||
/// <summary>
|
||||
/// Fractions Quest 帮派任务
|
||||
/// </summary>
|
||||
FQ,
|
||||
|
||||
/// <summary>
|
||||
/// Legend Quest 传说任务
|
||||
/// </summary>
|
||||
LQ,
|
||||
|
||||
/// <summary>
|
||||
/// Event Quest 活动任务
|
||||
/// </summary>
|
||||
EQ,
|
||||
|
||||
/// <summary>
|
||||
/// Daily Quest 日常任务
|
||||
/// </summary>
|
||||
DQ,
|
||||
|
||||
/// <summary>
|
||||
/// Indescribable Quest 不可描述的任务?
|
||||
/// </summary>
|
||||
IQ,
|
||||
|
||||
VQ,
|
||||
|
||||
/// <summary>
|
||||
/// World Quest 世界任务
|
||||
/// </summary>
|
||||
WQ,
|
||||
}
|
||||
34
src/Snap.Hutao/Snap.Hutao/Model/Metadata/Chapter.cs
Normal file
34
src/Snap.Hutao/Snap.Hutao/Model/Metadata/Chapter.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata;
|
||||
|
||||
internal sealed class Chapter
|
||||
{
|
||||
public ChapterId Id { get; set; }
|
||||
|
||||
public ChapterGroupId GroupId { get; set; }
|
||||
|
||||
public QuestId BeginQuestId { get; set; }
|
||||
|
||||
public QuestId EndQuestId { get; set; }
|
||||
|
||||
public uint NeedPlayerLevel { get; set; }
|
||||
|
||||
public string Number { get; set; } = default!;
|
||||
|
||||
public string Title { get; set; } = default!;
|
||||
|
||||
public string Icon { get; set; } = default!;
|
||||
|
||||
public string ImageTitle { get; set; } = default!;
|
||||
|
||||
public string SerialNumberIcon { get; set; } = default!;
|
||||
|
||||
public City CityId { get; set; }
|
||||
|
||||
public QuestType QuestType { get; set; }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace Snap.Hutao.Model.Metadata;
|
||||
// CityTaskOpenExcelConfig
|
||||
internal enum City : uint
|
||||
{
|
||||
None = 0,
|
||||
Mondstadt = 1,
|
||||
Liyue = 2,
|
||||
Inazuma = 3,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using Snap.Hutao.Control;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using System.Collections.Frozen;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Converter;
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ internal sealed class Material : DisplayItem
|
||||
/// <returns>是否为物品栏物品</returns>
|
||||
public bool IsInventoryItem()
|
||||
{
|
||||
// TODO: Add a pre-filtered metadata set to check if it's an inventory item
|
||||
|
||||
// 原质
|
||||
if (Id == 112001U)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<Identity
|
||||
Name="60568DGPStudio.SnapHutao"
|
||||
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
|
||||
Version="1.10.0.0" />
|
||||
Version="1.10.1.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>Snap Hutao</DisplayName>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<Identity
|
||||
Name="60568DGPStudio.SnapHutaoDev"
|
||||
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
|
||||
Version="1.10.0.0" />
|
||||
Version="1.10.1.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>Snap Hutao Dev</DisplayName>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using WinRT;
|
||||
|
||||
@@ -192,6 +192,15 @@
|
||||
<data name="CoreWindowHotkeyCombinationRegisterFailed" xml:space="preserve">
|
||||
<value>[{0}] 热键 [{1}] 注册失败</value>
|
||||
</data>
|
||||
<data name="CoreWindowingNotifyIconExitLabel" xml:space="preserve">
|
||||
<value>退出</value>
|
||||
</data>
|
||||
<data name="CoreWindowingNotifyIconLaunchGameLabel" xml:space="preserve">
|
||||
<value>启动游戏</value>
|
||||
</data>
|
||||
<data name="CoreWindowingNotifyIconViewLabel" xml:space="preserve">
|
||||
<value>窗口</value>
|
||||
</data>
|
||||
<data name="CoreWindowThemeDark" xml:space="preserve">
|
||||
<value>深色</value>
|
||||
</data>
|
||||
@@ -3044,6 +3053,9 @@
|
||||
<data name="WebBridgeShareCopyToClipboardSuccess" xml:space="preserve">
|
||||
<value>已复制到剪贴板</value>
|
||||
</data>
|
||||
<data name="WebDailyNoteArchonQuestChapterFinished" xml:space="preserve">
|
||||
<value>所有魔神任务已完成</value>
|
||||
</data>
|
||||
<data name="WebDailyNoteArchonQuestStatusFinished" xml:space="preserve">
|
||||
<value>全部完成</value>
|
||||
</data>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Achievement;
|
||||
using EntityAchievement = Snap.Hutao.Model.Entity.Achievement;
|
||||
using MetadataAchievement = Snap.Hutao.Model.Metadata.Achievement.Achievement;
|
||||
|
||||
namespace Snap.Hutao.Service.Achievement;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using Snap.Hutao.Model.InterChange.Achievement;
|
||||
using Snap.Hutao.ViewModel.Achievement;
|
||||
using System.Collections.ObjectModel;
|
||||
using EntityArchive = Snap.Hutao.Model.Entity.AchievementArchive;
|
||||
using MetadataAchievement = Snap.Hutao.Model.Metadata.Achievement.Achievement;
|
||||
|
||||
namespace Snap.Hutao.Service.Achievement;
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Achievement;
|
||||
using MetadataAchievement = Snap.Hutao.Model.Metadata.Achievement.Achievement;
|
||||
|
||||
namespace Snap.Hutao.Service.Achievement;
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ using Snap.Hutao.Service.Announcement;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
using Snap.Hutao.Web.Hoyolab.Hk4e.Common.Announcement;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -12,7 +12,6 @@ using Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.Avatar;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using CalculateAvatar = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Avatar;
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using EntityAvatarInfo = Snap.Hutao.Model.Entity.AvatarInfo;
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.Abstraction.Extension;
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.ViewModel.AvatarProperty;
|
||||
|
||||
namespace Snap.Hutao.Service.AvatarInfo.Factory.Builder;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Cultivation;
|
||||
|
||||
namespace Snap.Hutao.Service.Cultivation;
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Metadata;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
namespace Snap.Hutao.Service.DailyNote;
|
||||
|
||||
internal class DailyNoteMetadataContext : IMetadataContext,
|
||||
IMetadataListChapterSource
|
||||
{
|
||||
public List<Chapter> Chapters { get; set; } = default!;
|
||||
}
|
||||
@@ -8,7 +8,6 @@ using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.DailyNote.NotifySuppression;
|
||||
using Snap.Hutao.Service.Game;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.Binding;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote;
|
||||
using Snap.Hutao.Web.Response;
|
||||
|
||||
namespace Snap.Hutao.Service.DailyNote;
|
||||
@@ -78,8 +77,8 @@ internal sealed partial class DailyNoteNotificationOperation
|
||||
.AddAttributionText(attribution)
|
||||
.AddButton(new ToastButton()
|
||||
.SetContent(SH.ServiceDailyNoteNotifierActionLaunchGameButton)
|
||||
.AddArgument(Activation.Action, Activation.LaunchGame)
|
||||
.AddArgument(Activation.Uid, entry.Uid))
|
||||
.AddArgument(AppActivation.Action, AppActivation.LaunchGame)
|
||||
.AddArgument(AppActivation.Uid, entry.Uid))
|
||||
.AddButton(new ToastButtonDismiss(SH.ServiceDailyNoteNotifierActionLaunchGameDismiss));
|
||||
|
||||
if (options.IsReminderNotification)
|
||||
|
||||
@@ -5,7 +5,11 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using Snap.Hutao.Core.DependencyInjection.Abstraction;
|
||||
using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.ViewModel.DailyNote;
|
||||
using Snap.Hutao.ViewModel.User;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
|
||||
@@ -83,9 +87,18 @@ internal sealed partial class DailyNoteService : IDailyNoteService, IRecipient<U
|
||||
await userService.GetRoleCollectionAsync().ConfigureAwait(false);
|
||||
await RefreshDailyNotesCoreAsync(forceRefresh, token).ConfigureAwait(false);
|
||||
|
||||
List<DailyNoteEntry> entryList = await dailyNoteDbService.GetDailyNoteEntryListIncludingUserAsync(token).ConfigureAwait(false);
|
||||
entryList.ForEach(entry => { entry.UserGameRole = userService.GetUserGameRoleByUid(entry.Uid); });
|
||||
entries = entryList.ToObservableCollection();
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
DailyNoteMetadataContext context = await scope.GetRequiredService<IMetadataService>().GetContextAsync<DailyNoteMetadataContext>(token).ConfigureAwait(false);
|
||||
|
||||
List<DailyNoteEntry> entryList = await dailyNoteDbService.GetDailyNoteEntryListIncludingUserAsync(token).ConfigureAwait(false);
|
||||
entryList.ForEach(entry =>
|
||||
{
|
||||
entry.UserGameRole = userService.GetUserGameRoleByUid(entry.Uid);
|
||||
entry.ArchonQuestView = DailyNoteArchonQuestView.Create(entry.DailyNote, context.Chapters);
|
||||
});
|
||||
entries = entryList.ToObservableCollection();
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
@@ -159,4 +172,4 @@ internal sealed partial class DailyNoteService : IDailyNoteService, IRecipient<U
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata;
|
||||
using Snap.Hutao.Model.Metadata.Avatar;
|
||||
using Snap.Hutao.Model.Metadata.Weapon;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
using Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Gdi;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using Windows.Graphics.Capture;
|
||||
using Windows.Graphics.DirectX;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using static Snap.Hutao.Win32.Gdi32;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal readonly struct GameScreenCaptureContext
|
||||
{
|
||||
public readonly GraphicsCaptureItem Item;
|
||||
|
||||
private readonly IDirect3DDevice direct3DDevice;
|
||||
private readonly HWND hwnd;
|
||||
|
||||
public GameScreenCaptureContext(IDirect3DDevice direct3DDevice, HWND hwnd)
|
||||
{
|
||||
this.direct3DDevice = direct3DDevice;
|
||||
this.hwnd = hwnd;
|
||||
|
||||
GraphicsCaptureItem.As<IGraphicsCaptureItemInterop>().CreateForWindow(hwnd, out Item);
|
||||
}
|
||||
|
||||
public Direct3D11CaptureFramePool CreatePool()
|
||||
{
|
||||
return Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, DeterminePixelFormat(hwnd), 2, Item.Size);
|
||||
}
|
||||
|
||||
public void RecreatePool(Direct3D11CaptureFramePool framePool)
|
||||
{
|
||||
framePool.Recreate(direct3DDevice, DeterminePixelFormat(hwnd), 2, Item.Size);
|
||||
}
|
||||
|
||||
public GraphicsCaptureSession CreateSession(Direct3D11CaptureFramePool framePool)
|
||||
{
|
||||
GraphicsCaptureSession session = framePool.CreateCaptureSession(Item);
|
||||
session.IsCursorCaptureEnabled = false;
|
||||
session.IsBorderRequired = false;
|
||||
return session;
|
||||
}
|
||||
|
||||
private static DirectXPixelFormat DeterminePixelFormat(HWND hwnd)
|
||||
{
|
||||
HDC hdc = GetDC(hwnd);
|
||||
if (hdc != HDC.NULL)
|
||||
{
|
||||
int bitsPerPixel = GetDeviceCaps(hdc, GET_DEVICE_CAPS_INDEX.BITSPIXEL);
|
||||
_ = ReleaseDC(hwnd, hdc);
|
||||
if (bitsPerPixel >= 32)
|
||||
{
|
||||
return DirectXPixelFormat.R16G16B16A16Float;
|
||||
}
|
||||
}
|
||||
|
||||
return DirectXPixelFormat.B8G8R8A8UIntNormalized;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal sealed class GameScreenCaptureMemoryPool : MemoryPool<byte>
|
||||
{
|
||||
private static LazySlim<GameScreenCaptureMemoryPool> lazyShared = new(() => new());
|
||||
|
||||
private readonly object syncRoot = new();
|
||||
private readonly LinkedList<GameScreenCaptureBuffer> unrentedBuffers = [];
|
||||
private readonly LinkedList<GameScreenCaptureBuffer> rentedBuffers = [];
|
||||
|
||||
private int bufferCount;
|
||||
|
||||
public new static GameScreenCaptureMemoryPool Shared { get => lazyShared.Value; }
|
||||
|
||||
public override int MaxBufferSize { get => Array.MaxLength; }
|
||||
|
||||
public int BufferCount { get => bufferCount; }
|
||||
|
||||
public override IMemoryOwner<byte> Rent(int minBufferSize = -1)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(minBufferSize, 0);
|
||||
|
||||
lock (syncRoot)
|
||||
{
|
||||
foreach (GameScreenCaptureBuffer buffer in unrentedBuffers)
|
||||
{
|
||||
if (buffer.Memory.Length >= minBufferSize)
|
||||
{
|
||||
unrentedBuffers.Remove(buffer);
|
||||
rentedBuffers.AddLast(buffer);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
GameScreenCaptureBuffer newBuffer = new(this, minBufferSize);
|
||||
rentedBuffers.AddLast(newBuffer);
|
||||
++bufferCount;
|
||||
return newBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (rentedBuffers.Count > 0)
|
||||
{
|
||||
HutaoException.InvalidOperation("There are still rented buffers.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class GameScreenCaptureBuffer : IMemoryOwner<byte>
|
||||
{
|
||||
private readonly GameScreenCaptureMemoryPool pool;
|
||||
private readonly byte[] buffer;
|
||||
|
||||
public GameScreenCaptureBuffer(GameScreenCaptureMemoryPool pool, int bufferSize)
|
||||
{
|
||||
this.pool = pool;
|
||||
buffer = GC.AllocateUninitializedArray<byte>(bufferSize);
|
||||
}
|
||||
|
||||
public Memory<byte> Memory { get => buffer.AsMemory(); }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
lock (pool.syncRoot)
|
||||
{
|
||||
pool.rentedBuffers.Remove(this);
|
||||
pool.unrentedBuffers.AddLast(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Windows.Graphics.Capture;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using WinRT;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.D3D11;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton, typeof(IGameScreenCaptureService))]
|
||||
internal sealed partial class GameScreenCaptureService : IGameScreenCaptureService
|
||||
{
|
||||
private readonly ILogger<GameScreenCaptureService> logger;
|
||||
|
||||
public bool IsSupported()
|
||||
{
|
||||
if (!Core.UniversalApiContract.IsPresent(WindowsVersion.Windows10Version1903))
|
||||
{
|
||||
logger.LogWarning("Windows 10 Version 1903 or later is required for Windows.Graphics.Capture API.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GraphicsCaptureSession.IsSupported())
|
||||
{
|
||||
logger.LogWarning("GraphicsCaptureSession is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public unsafe bool TryStartCapture(HWND hwnd, [NotNullWhen(true)] out GameScreenCaptureSession? session)
|
||||
{
|
||||
session = default;
|
||||
|
||||
D3D11_CREATE_DEVICE_FLAG flag = D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT
|
||||
#if DEBUG
|
||||
| D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_DEBUG
|
||||
#endif
|
||||
;
|
||||
|
||||
HRESULT hr;
|
||||
hr = D3D11CreateDevice(default, D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE, default, flag, [], D3D11_SDK_VERSION, out ID3D11Device* pD3D11Device, out _, out _);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
logger.LogWarning("D3D11CreateDevice failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = IUnknownMarshal.QueryInterface(pD3D11Device, in IDXGIDevice.IID, out IDXGIDevice* pDXGIDevice);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
logger.LogWarning("ID3D11Device.QueryInterface<IDXGIDevice> failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pDXGIDevice);
|
||||
|
||||
hr = CreateDirect3D11DeviceFromDXGIDevice(pDXGIDevice, out Win32.System.WinRT.IInspectable* inspectable);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
logger.LogWarning("CreateDirect3D11DeviceFromDXGIDevice failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(inspectable);
|
||||
|
||||
IDirect3DDevice direct3DDevice = IInspectable.FromAbi((nint)inspectable).ObjRef.AsInterface<IDirect3DDevice>();
|
||||
|
||||
GameScreenCaptureContext captureContext = new(direct3DDevice, hwnd);
|
||||
session = new(captureContext, logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi.Common;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.Graphics;
|
||||
using Windows.Graphics.Capture;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using WinRT;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal sealed class GameScreenCaptureSession : IDisposable
|
||||
{
|
||||
private readonly GameScreenCaptureContext captureContext;
|
||||
private readonly Direct3D11CaptureFramePool framePool;
|
||||
private readonly GraphicsCaptureSession session;
|
||||
private readonly ILogger logger;
|
||||
|
||||
private TaskCompletionSource<IMemoryOwner<byte>>? frameRawPixelDataTaskCompletionSource;
|
||||
private bool isFrameRawPixelDataRequested;
|
||||
private SizeInt32 contentSize;
|
||||
|
||||
private bool isDisposed;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public GameScreenCaptureSession(GameScreenCaptureContext captureContext, ILogger logger)
|
||||
{
|
||||
this.captureContext = captureContext;
|
||||
this.logger = logger;
|
||||
|
||||
contentSize = captureContext.Item.Size;
|
||||
|
||||
captureContext.Item.Closed += OnItemClosed;
|
||||
|
||||
framePool = captureContext.CreatePool();
|
||||
framePool.FrameArrived += OnFrameArrived;
|
||||
|
||||
session = captureContext.CreateSession(framePool);
|
||||
session.StartCapture();
|
||||
}
|
||||
|
||||
public async ValueTask<IMemoryOwner<byte>> RequestFrameRawPixelDataAsync()
|
||||
{
|
||||
if (Volatile.Read(ref isFrameRawPixelDataRequested))
|
||||
{
|
||||
HutaoException.InvalidOperation("The frame raw pixel data has already been requested.");
|
||||
}
|
||||
|
||||
if (isDisposed)
|
||||
{
|
||||
HutaoException.InvalidOperation("The session has been disposed.");
|
||||
}
|
||||
|
||||
frameRawPixelDataTaskCompletionSource = new();
|
||||
Volatile.Write(ref isFrameRawPixelDataRequested, true);
|
||||
|
||||
return await frameRawPixelDataTaskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
session.Dispose();
|
||||
framePool.Dispose();
|
||||
isDisposed = true;
|
||||
}
|
||||
|
||||
private void OnItemClosed(GraphicsCaptureItem sender, object args)
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private unsafe void OnFrameArrived(Direct3D11CaptureFramePool sender, object args)
|
||||
{
|
||||
// Simply ignore the frame if the frame raw pixel data is not requested.
|
||||
if (!Volatile.Read(ref isFrameRawPixelDataRequested))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (Direct3D11CaptureFrame? frame = sender.TryGetNextFrame())
|
||||
{
|
||||
if (frame is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool needsReset = false;
|
||||
|
||||
if (frame.ContentSize != contentSize)
|
||||
{
|
||||
needsReset = true;
|
||||
contentSize = frame.ContentSize;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
UnsafeProcessFrameSurface(frame.Surface);
|
||||
}
|
||||
catch (Exception ex) // TODO: test if it's device lost.
|
||||
{
|
||||
logger.LogError(ex, "Failed to process the frame surface.");
|
||||
needsReset = true;
|
||||
}
|
||||
|
||||
if (needsReset)
|
||||
{
|
||||
captureContext.RecreatePool(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void UnsafeProcessFrameSurface(IDirect3DSurface surface)
|
||||
{
|
||||
IDirect3DDxgiInterfaceAccess access = surface.As<IDirect3DDxgiInterfaceAccess>();
|
||||
if (FAILED(access.GetInterface(in IDXGISurface.IID, out IDXGISurface* pDXGISurface)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(pDXGISurface->GetDesc(out DXGI_SURFACE_DESC dxgiSurfaceDesc)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Should be the same device used to create the frame pool.
|
||||
if (FAILED(pDXGISurface->GetDevice(in ID3D11Device.IID, out ID3D11Device* pD3D11Device)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC d3d11Texture2DDesc = default;
|
||||
d3d11Texture2DDesc.Width = dxgiSurfaceDesc.Width;
|
||||
d3d11Texture2DDesc.Height = dxgiSurfaceDesc.Height;
|
||||
d3d11Texture2DDesc.ArraySize = 1;
|
||||
|
||||
// We have to copy out the resource to a CPU readable texture.
|
||||
d3d11Texture2DDesc.CPUAccessFlags = D3D11_CPU_ACCESS_FLAG.D3D11_CPU_ACCESS_READ;
|
||||
|
||||
// DirectX will automatically convert any format to B8G8R8A8_UNORM.
|
||||
d3d11Texture2DDesc.Format = DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
d3d11Texture2DDesc.MipLevels = 1;
|
||||
d3d11Texture2DDesc.SampleDesc.Count = 1;
|
||||
d3d11Texture2DDesc.Usage = D3D11_USAGE.D3D11_USAGE_STAGING;
|
||||
|
||||
if (FAILED(pD3D11Device->CreateTexture2D(ref d3d11Texture2DDesc, ref Unsafe.NullRef<D3D11_SUBRESOURCE_DATA>(), out ID3D11Texture2D* pD3D11Texture2D)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(access.GetInterface(in ID3D11Resource.IID, out ID3D11Resource* pD3D11Resource)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pD3D11Device->GetImmediateContext(out ID3D11DeviceContext* pD3D11DeviceContext);
|
||||
pD3D11DeviceContext->CopyResource((ID3D11Resource*)pD3D11Texture2D, pD3D11Resource);
|
||||
|
||||
if (FAILED(pD3D11DeviceContext->Map((ID3D11Resource*)pD3D11Texture2D, 0U, D3D11_MAP.D3D11_MAP_READ, 0U, out D3D11_MAPPED_SUBRESOURCE d3d11MappedSubresource)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The D3D11_MAPPED_SUBRESOURCE data is arranged as follows:
|
||||
// |--------- Row pitch ----------|
|
||||
// |---- Data width ----|- Blank -|
|
||||
// ┌────────────────────┬─────────┐
|
||||
// │ │ │
|
||||
// │ Actual data │ Stride │
|
||||
// │ │ │
|
||||
// └────────────────────┴─────────┘
|
||||
ReadOnlySpan2D<byte> subresource = new(d3d11MappedSubresource.pData, (int)d3d11Texture2DDesc.Height, (int)d3d11MappedSubresource.RowPitch);
|
||||
|
||||
int rowLength = contentSize.Width * 4;
|
||||
IMemoryOwner<byte> buffer = GameScreenCaptureMemoryPool.Shared.Rent(contentSize.Height * rowLength);
|
||||
|
||||
for (int row = 0; row < contentSize.Height; row++)
|
||||
{
|
||||
subresource[row][..rowLength].CopyTo(buffer.Memory.Span.Slice(row * rowLength, rowLength));
|
||||
}
|
||||
|
||||
ArgumentNullException.ThrowIfNull(frameRawPixelDataTaskCompletionSource);
|
||||
frameRawPixelDataTaskCompletionSource.SetResult(buffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal interface IGameScreenCaptureService
|
||||
{
|
||||
bool IsSupported();
|
||||
|
||||
bool TryStartCapture(HWND hwnd, [NotNullWhen(true)] out GameScreenCaptureSession? session);
|
||||
}
|
||||
@@ -5,7 +5,6 @@ using Snap.Hutao.Core.Diagnostics;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Memory;
|
||||
using Snap.Hutao.Win32.System.ProcessStatus;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Metadata;
|
||||
|
||||
namespace Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
internal interface IMetadataListChapterSource
|
||||
{
|
||||
public List<Chapter> Chapters { get; set; }
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Snap.Hutao.Model.Metadata.Avatar;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Model.Metadata.Weapon;
|
||||
@@ -24,6 +23,11 @@ internal static class MetadataServiceContextExtension
|
||||
listAchievementSource.Achievements = await metadataService.GetAchievementListAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataListChapterSource listChapterSource)
|
||||
{
|
||||
listChapterSource.Chapters = await metadataService.GetChapterListAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context is IMetadataListGachaEventSource listGachaEventSource)
|
||||
{
|
||||
listGachaEventSource.GachaEvents = await metadataService.GetGachaEventListAsync(token).ConfigureAwait(false);
|
||||
|
||||
@@ -10,6 +10,7 @@ internal static class MetadataFileNames
|
||||
public const string FileNameAvatar = "Avatar";
|
||||
public const string FileNameAvatarCurve = "AvatarCurve";
|
||||
public const string FileNameAvatarPromote = "AvatarPromote";
|
||||
public const string FileNameChapter = "Chapter";
|
||||
public const string FileNameDisplayItem = "DisplayItem";
|
||||
public const string FileNameGachaEvent = "GachaEvent";
|
||||
public const string FileNameMaterial = "Material";
|
||||
|
||||
@@ -20,6 +20,11 @@ internal static class MetadataServiceListExtension
|
||||
return metadataService.FromCacheOrFileAsync<List<Model.Metadata.Achievement.Achievement>>(FileNameAchievement, token);
|
||||
}
|
||||
|
||||
public static ValueTask<List<Chapter>> GetChapterListAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheOrFileAsync<List<Chapter>>(FileNameChapter, token);
|
||||
}
|
||||
|
||||
public static ValueTask<List<AchievementGoal>> GetAchievementGoalListAsync(this IMetadataService metadataService, CancellationToken token = default)
|
||||
{
|
||||
return metadataService.FromCacheOrFileAsync<List<AchievementGoal>>(FileNameAchievementGoal, token);
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.IO.Hashing;
|
||||
using Snap.Hutao.Core.IO.Http.Sharding;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.Web.Hutao;
|
||||
using Snap.Hutao.Web.Hutao.Response;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Snap.Hutao.Service.Update;
|
||||
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.IO.Hashing;
|
||||
using Snap.Hutao.Core.IO.Http.Sharding;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.Web.Hutao;
|
||||
using Snap.Hutao.Web.Hutao.Response;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Snap.Hutao.Service.Update;
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
<None Remove="Control\Theme\TransitionCollection.xaml" />
|
||||
<None Remove="Control\Theme\Uri.xaml" />
|
||||
<None Remove="Control\Theme\WindowOverride.xaml" />
|
||||
<None Remove="Core\Windowing\NotifyIcon\NotifyIconContextMenu.xaml" />
|
||||
<None Remove="GuideWindow.xaml" />
|
||||
<None Remove="IdentifyMonitorWindow.xaml" />
|
||||
<None Remove="IdentityStructs.json" />
|
||||
@@ -323,8 +324,8 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240404000" />
|
||||
<PackageReference Include="QRCoder" Version="1.4.3" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
|
||||
<PackageReference Include="QRCoder" Version="1.5.1" />
|
||||
<PackageReference Include="Snap.Discord.GameSDK" Version="1.6.0" />
|
||||
<PackageReference Include="Snap.Hutao.Deployment.Runtime" Version="1.16.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@@ -343,7 +344,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.10.1" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.11.0" />
|
||||
<Manifest Include="$(ApplicationManifest)" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -355,6 +356,11 @@
|
||||
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
|
||||
<ProjectCapability Include="Msix" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Core\Windowing\NotifyIcon\NotifyIconContextMenu.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="View\Dialog\SpiralAbyssUploadRecordHomaNotLoginDialog.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
<NavigationView
|
||||
x:Name="NavView"
|
||||
Margin="-1,0,0,-1"
|
||||
Margin="0,0,0,0"
|
||||
shch:NavigationViewHelper.PaneCornerRadius="0"
|
||||
CompactPaneLength="48"
|
||||
IsBackEnabled="{x:Bind ContentFrame.CanGoBack, Mode=OneWay}"
|
||||
|
||||
@@ -41,9 +41,11 @@
|
||||
x:Name="ImageZoomBorder"
|
||||
VerticalAlignment="Top"
|
||||
cw:VisualExtensions.NormalizedCenterPoint="0.5">
|
||||
<cww:ConstrainedBox AspectRatio="1080:390" CornerRadius="{ThemeResource ControlCornerRadiusTop}">
|
||||
<cww:ConstrainedBox
|
||||
Margin="-4"
|
||||
AspectRatio="1080:390"
|
||||
CornerRadius="{ThemeResource ControlCornerRadiusTop}">
|
||||
<shci:CachedImage
|
||||
Margin="-1"
|
||||
VerticalAlignment="Center"
|
||||
PlaceholderMargin="16"
|
||||
PlaceholderSource="{StaticResource UI_EmotionIcon271}"
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cw="using:CommunityToolkit.WinUI"
|
||||
xmlns:cwc="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:cwcont="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:cwconv="using:CommunityToolkit.WinUI.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
|
||||
@@ -12,6 +13,7 @@
|
||||
xmlns:shch="using:Snap.Hutao.Control.Helper"
|
||||
xmlns:shci="using:Snap.Hutao.Control.Image"
|
||||
xmlns:shcm="using:Snap.Hutao.Control.Markup"
|
||||
xmlns:shme="using:Snap.Hutao.Model.Entity"
|
||||
xmlns:shvc="using:Snap.Hutao.View.Control"
|
||||
xmlns:shvcp="using:Snap.Hutao.View.Card.Primitive"
|
||||
xmlns:shvd="using:Snap.Hutao.ViewModel.DailyNote"
|
||||
@@ -26,6 +28,16 @@
|
||||
<Page.Resources>
|
||||
<shc:BindingProxy x:Key="ViewModelBindingProxy" DataContext="{Binding}"/>
|
||||
|
||||
<cwconv:BoolToObjectConverter
|
||||
x:Name="DailyTaskIconConverter"
|
||||
FalseValue="{StaticResource UI_MarkQuest_Events_Start}"
|
||||
TrueValue="{StaticResource UI_MarkQuest_Events_Proce}"/>
|
||||
|
||||
<cwconv:BoolToObjectConverter
|
||||
x:Name="ArchonQuestIconConverter"
|
||||
FalseValue="{StaticResource UI_MarkQuest_Main_Start}"
|
||||
TrueValue="{StaticResource UI_MarkQuest_Main_Proce}"/>
|
||||
|
||||
<DataTemplate x:Key="UserAndUidTemplate">
|
||||
<Grid Padding="0,0,0,16">
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding Uid}"/>
|
||||
@@ -43,7 +55,7 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="DailyNoteEntryTemplate">
|
||||
<DataTemplate x:Key="DailyNoteEntryTemplate" x:DataType="shme:DailyNoteEntry">
|
||||
<ItemContainer cw:Effects.Shadow="{ThemeResource CompatCardShadow}">
|
||||
<ItemContainer.Resources>
|
||||
<SolidColorBrush x:Key="ItemContainerPointerOverBackground" Color="Transparent"/>
|
||||
@@ -108,6 +120,43 @@
|
||||
Grid.Row="1"
|
||||
Margin="0,8,0,0"
|
||||
Spacing="6">
|
||||
<Grid Style="{ThemeResource GridCardStyle}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ProgressBar
|
||||
Grid.ColumnSpan="2"
|
||||
Height="40"
|
||||
MinHeight="48"
|
||||
Background="{x:Null}"
|
||||
CornerRadius="{ThemeResource ControlCornerRadius}"
|
||||
Maximum="{Binding ArchonQuestView.Ids.Count, Mode=OneWay}"
|
||||
Opacity="{StaticResource LargeBackgroundProgressBarOpacity}"
|
||||
Value="{Binding ArchonQuestView.ProgressValue, Mode=OneWay}"/>
|
||||
<shci:CachedImage
|
||||
Grid.Column="0"
|
||||
Margin="4"
|
||||
VerticalAlignment="Center"
|
||||
shch:FrameworkElementHelper.SquareLength="32"
|
||||
Source="{Binding DailyNote.IsArchonQuestFinished, Converter={StaticResource ArchonQuestIconConverter}}"/>
|
||||
<StackPanel
|
||||
Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock
|
||||
Style="{StaticResource SubtitleTextBlockStyle}"
|
||||
Text="{Binding ArchonQuestView.ProgressFormatted, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap"/>
|
||||
<TextBlock
|
||||
Opacity="0.6"
|
||||
Style="{StaticResource CaptionTextBlockStyle}"
|
||||
Text="{Binding ArchonQuestView.ChapterFormatted, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Grid Style="{ThemeResource GridCardStyle}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
@@ -202,7 +251,7 @@
|
||||
Margin="4"
|
||||
VerticalAlignment="Center"
|
||||
shch:FrameworkElementHelper.SquareLength="32"
|
||||
Source="{StaticResource UI_MarkQuest_Events_Proce}"/>
|
||||
Source="{Binding DailyNote.DailyTask.IsExtraTaskRewardReceived, Converter={StaticResource DailyTaskIconConverter}}"/>
|
||||
<StackPanel
|
||||
Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
@@ -333,7 +382,7 @@
|
||||
ItemsSource="{Binding DailyNote.Expeditions, Mode=OneWay}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<cwc:UniformGrid
|
||||
<cwcont:UniformGrid
|
||||
ColumnSpacing="8"
|
||||
Columns="2"
|
||||
RowSpacing="8"/>
|
||||
@@ -450,16 +499,16 @@
|
||||
<x:Double x:Key="SettingsCardWrapNoIconThreshold">0</x:Double>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<cwc:HeaderedContentControl
|
||||
<cwcont:HeaderedContentControl
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsEnabled="{Binding RuntimeOptions.IsElevated, Converter={StaticResource BoolNegationConverter}}">
|
||||
<cwc:HeaderedContentControl.Header>
|
||||
<cwcont:HeaderedContentControl.Header>
|
||||
<TextBlock
|
||||
Margin="1,0,0,5"
|
||||
Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
|
||||
Text="{shcm:ResourceString Name=ViewPageDailyNoteSettingRefreshHeader}"/>
|
||||
</cwc:HeaderedContentControl.Header>
|
||||
</cwcont:HeaderedContentControl.Header>
|
||||
<StackPanel Spacing="{StaticResource SettingsCardSpacing}">
|
||||
<InfoBar
|
||||
Title="{shcm:ResourceString Name=ViewPageDailyNoteSettingRefreshElevatedHint}"
|
||||
@@ -467,12 +516,12 @@
|
||||
IsOpen="True"
|
||||
Severity="Warning"
|
||||
Visibility="{Binding RuntimeOptions.IsElevated, Converter={StaticResource BoolToVisibilityConverter}}"/>
|
||||
<cwc:SettingsCard
|
||||
<cwcont:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageDailyNoteSettingAutoRefreshDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageDailyNoteSettingAutoRefresh}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<ToggleSwitch Margin="24,0,0,0" IsOn="{Binding DailyNoteOptions.IsAutoRefreshEnabled, Mode=TwoWay}"/>
|
||||
</cwc:SettingsCard>
|
||||
</cwcont:SettingsCard>
|
||||
<RadioButtons
|
||||
Margin="1,11,0,5"
|
||||
IsEnabled="{Binding DailyNoteOptions.IsAutoRefreshEnabled}"
|
||||
@@ -488,15 +537,15 @@
|
||||
</RadioButtons.ItemTemplate>
|
||||
</RadioButtons>
|
||||
</StackPanel>
|
||||
</cwc:HeaderedContentControl>
|
||||
</cwcont:HeaderedContentControl>
|
||||
|
||||
<cwc:HeaderedContentControl
|
||||
<cwcont:HeaderedContentControl
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsEnabled="{Binding RuntimeOptions.IsToastAvailable}">
|
||||
<cwc:HeaderedContentControl.Header>
|
||||
<cwcont:HeaderedContentControl.Header>
|
||||
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageDailyNoteNotificationHeader}"/>
|
||||
</cwc:HeaderedContentControl.Header>
|
||||
</cwcont:HeaderedContentControl.Header>
|
||||
<StackPanel Spacing="{StaticResource SettingsCardSpacing}">
|
||||
<InfoBar
|
||||
Title="胡桃的通知权限已被关闭"
|
||||
@@ -504,23 +553,23 @@
|
||||
IsOpen="True"
|
||||
Severity="Warning"
|
||||
Visibility="{Binding RuntimeOptions.IsToastAvailable, Converter={StaticResource BoolToVisibilityRevertConverter}}"/>
|
||||
<cwc:SettingsCard
|
||||
<cwcont:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageDailyNoteSlientModeDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageDailyNoteSlientModeHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<ToggleSwitch Margin="24,0,0,0" IsOn="{Binding DailyNoteOptions.IsSilentWhenPlayingGame, Mode=TwoWay}"/>
|
||||
</cwc:SettingsCard>
|
||||
<cwc:SettingsCard
|
||||
</cwcont:SettingsCard>
|
||||
<cwcont:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageDailyNoteReminderDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageDailyNoteReminderHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<ToggleSwitch Margin="24,0,0,0" IsOn="{Binding DailyNoteOptions.IsReminderNotification, Mode=TwoWay}"/>
|
||||
</cwc:SettingsCard>
|
||||
</cwcont:SettingsCard>
|
||||
</StackPanel>
|
||||
</cwc:HeaderedContentControl>
|
||||
</cwcont:HeaderedContentControl>
|
||||
|
||||
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageDailyNoteDataInteropHeader}"/>
|
||||
<cwc:SettingsCard
|
||||
<cwcont:SettingsCard
|
||||
Command="{Binding ConfigDailyNoteWebhookUrlCommand}"
|
||||
Description="{shcm:ResourceString Name=ViewPageDailyNoteConfigWebhookDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageDailyNoteConfigWebhookHeader}"
|
||||
|
||||
@@ -98,6 +98,13 @@
|
||||
Style="{ThemeResource SettingButtonStyle}"/>
|
||||
</cwc:SettingsCard>
|
||||
|
||||
<cwc:SettingsCard Header="Test Windows.Graphics.Capture">
|
||||
<Button
|
||||
Command="{Binding TestWindowsGraphicsCaptureCommand}"
|
||||
Content="Test"
|
||||
Style="{ThemeResource SettingButtonStyle}"/>
|
||||
</cwc:SettingsCard>
|
||||
|
||||
<cwc:SettingsCard Header="Suppress Metadata Initialization">
|
||||
<ToggleSwitch IsOn="{Binding SuppressMetadataInitialization, Mode=TwoWay}"/>
|
||||
</cwc:SettingsCard>
|
||||
|
||||
@@ -46,7 +46,13 @@
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="MonsterBaseValueTemplate">
|
||||
<cwc:SettingsCard Header="{Binding Name}">
|
||||
<cwc:SettingsCard MinHeight="40" Padding="0,0,16,0">
|
||||
<cwc:SettingsCard.Resources>
|
||||
<x:Double x:Key="SettingsCardLeftIndention">16</x:Double>
|
||||
</cwc:SettingsCard.Resources>
|
||||
<cwc:SettingsCard.Header>
|
||||
<TextBlock Text="{Binding Name}" TextWrapping="NoWrap"/>
|
||||
</cwc:SettingsCard.Header>
|
||||
<TextBlock Text="{Binding Value}"/>
|
||||
</cwc:SettingsCard>
|
||||
</DataTemplate>
|
||||
@@ -94,23 +100,6 @@
|
||||
Margin="6,8,0,0"
|
||||
LocalSettingKeySuffixForCurrent="WikiMonsterPage.Monsters"/>
|
||||
</CommandBar.Content>
|
||||
<!--<AppBarElementContainer Visibility="Collapsed">
|
||||
<AutoSuggestBox
|
||||
Width="240"
|
||||
Height="36"
|
||||
Margin="16,6,6,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalContentAlignment="Center"
|
||||
PlaceholderText="{shcm:ResourceString Name=ViewPageWiKiMonsterAutoSuggestBoxPlaceHolder}"
|
||||
QueryIcon="{shcm:FontIcon Glyph=}"
|
||||
Text="{Binding FilterText, Mode=TwoWay}">
|
||||
<mxi:Interaction.Behaviors>
|
||||
<mxic:EventTriggerBehavior EventName="QuerySubmitted">
|
||||
<mxic:InvokeCommandAction Command="{Binding FilterCommand}" CommandParameter="{Binding FilterText}"/>
|
||||
</mxic:EventTriggerBehavior>
|
||||
</mxi:Interaction.Behaviors>
|
||||
</AutoSuggestBox>
|
||||
</AppBarElementContainer>-->
|
||||
</CommandBar>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core.IO;
|
||||
using Snap.Hutao.Core.IO.DataTransfer;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Factory.Picker;
|
||||
using Snap.Hutao.Model.InterChange.Achievement;
|
||||
using Snap.Hutao.Service.Achievement;
|
||||
|
||||
@@ -16,7 +16,6 @@ using Snap.Hutao.View.Dialog;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using EntityAchievementArchive = Snap.Hutao.Model.Entity.AchievementArchive;
|
||||
using MetadataAchievement = Snap.Hutao.Model.Metadata.Achievement.Achievement;
|
||||
using MetadataAchievementGoal = Snap.Hutao.Model.Metadata.Achievement.AchievementGoal;
|
||||
using SortDescription = CommunityToolkit.WinUI.Collections.SortDescription;
|
||||
using SortDirection = CommunityToolkit.WinUI.Collections.SortDirection;
|
||||
@@ -113,7 +112,7 @@ internal sealed partial class AchievementViewModel : Abstraction.ViewModel, INav
|
||||
{
|
||||
if (await Initialization.Task.ConfigureAwait(false))
|
||||
{
|
||||
if (data.Data is Activation.ImportUIAFFromClipboard)
|
||||
if (data.Data is AppActivation.ImportUIAFFromClipboard)
|
||||
{
|
||||
await ImportUIAFFromClipboardAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Service.Achievement;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
|
||||
@@ -5,7 +5,6 @@ using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Service.AvatarInfo.Factory.Builder;
|
||||
|
||||
namespace Snap.Hutao.ViewModel.AvatarProperty;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ internal sealed class CultivateItemView : ObservableObject, IEntityWithMetadata<
|
||||
/// <summary>
|
||||
/// 是否为今日物品
|
||||
/// </summary>
|
||||
public bool IsToday { get => Inner.IsTodaysItem(); }
|
||||
public bool IsToday { get => Inner.IsTodaysItem(true); }
|
||||
|
||||
/// <summary>
|
||||
/// 星期中的日期
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user