From ea8685523d1ab01675cc37c704c0dc742f06035d Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Sun, 23 Jun 2024 19:29:46 +0800 Subject: [PATCH] refactor --- .../Core/LifeCycle/AppActivation.cs | 1 - .../Core/LifeCycle/AppInstanceExtension.cs | 5 -- .../Snap.Hutao/Core/Setting/LocalSetting.cs | 39 ------------- .../Snap.Hutao/Core/Threading/AsyncBarrier.cs | 20 ------- .../ConcurrentCancellationTokenSource.cs | 9 +-- .../Snap.Hutao/Core/Threading/Delay.cs | 12 +--- .../Threading/DispatcherQueueExtension.cs | 15 ----- .../DispatcherQueueSwitchOperation.cs | 13 ----- .../Snap.Hutao/Core/Threading/TaskContext.cs | 10 ---- .../Core/Threading/TaskExtension.cs | 56 ++----------------- .../Threading/ThreadPoolSwitchOperation.cs | 13 ----- .../Snap.Hutao/Core/Threading/ValueResult.cs | 22 -------- .../Core/Threading/ValueResultExtension.cs | 10 ---- .../Windowing/HotKey/HotKeyCombination.cs | 7 +++ .../Windowing/HotKey/HotKeyMessageWindow.cs | 4 +- .../Core/Windowing/HotKey/HotKeyOptions.cs | 6 +- .../Snap.Hutao/IdentifyMonitorWindow.xaml.cs | 2 +- .../Win32/UI/Input/KeyboardAndMouse/INPUT.cs | 4 +- 18 files changed, 26 insertions(+), 222 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs index 34070474..21aa3d26 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs @@ -18,7 +18,6 @@ using Snap.Hutao.Service.Metadata; using Snap.Hutao.Service.Navigation; using Snap.Hutao.ViewModel.Guide; using System.Diagnostics; -using System.Text.RegularExpressions; namespace Snap.Hutao.Core.LifeCycle; diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppInstanceExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppInstanceExtension.cs index a8bb4d9b..ecb0a4cb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppInstanceExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppInstanceExtension.cs @@ -21,11 +21,6 @@ internal static class AppInstanceExtension // Hold the reference here to prevent memory corruption. private static HANDLE redirectEventHandle; - /// - /// 同步非阻塞重定向 - /// - /// app实例 - /// 参数 public static unsafe void RedirectActivationTo(this AppInstance appInstance, AppActivationArguments args) { try diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Setting/LocalSetting.cs b/src/Snap.Hutao/Snap.Hutao/Core/Setting/LocalSetting.cs index d432d6c9..c43c3854 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Setting/LocalSetting.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Setting/LocalSetting.cs @@ -5,117 +5,96 @@ using Windows.Storage; namespace Snap.Hutao.Core.Setting; -/// -/// 本地设置 -/// [HighQuality] internal static class LocalSetting { private static readonly ApplicationDataContainer Container = ApplicationData.Current.LocalSettings; - /// public static byte Get(string key, byte defaultValue) { return Get(key, defaultValue); } - /// public static short Get(string key, short defaultValue) { return Get(key, defaultValue); } - /// public static ushort Get(string key, ushort defaultValue) { return Get(key, defaultValue); } - /// public static int Get(string key, int defaultValue) { return Get(key, defaultValue); } - /// public static uint Get(string key, uint defaultValue) { return Get(key, defaultValue); } - /// public static long Get(string key, long defaultValue) { return Get(key, defaultValue); } - /// public static ulong Get(string key, ulong defaultValue) { return Get(key, defaultValue); } - /// public static float Get(string key, float defaultValue) { return Get(key, defaultValue); } - /// public static double Get(string key, double defaultValue) { return Get(key, defaultValue); } - /// public static bool Get(string key, bool defaultValue) { return Get(key, defaultValue); } - /// public static char Get(string key, char defaultValue) { return Get(key, defaultValue); } - /// public static string Get(string key, string defaultValue) { return Get(key, defaultValue); } - /// public static DateTimeOffset Get(string key, in DateTimeOffset defaultValue) { return Get(key, defaultValue); } - /// public static TimeSpan Get(string key, in TimeSpan defaultValue) { return Get(key, defaultValue); } - /// public static Guid Get(string key, in Guid defaultValue) { return Get(key, defaultValue); } - /// public static Windows.Foundation.Point Get(string key, Windows.Foundation.Point defaultValue) { return Get(key, defaultValue); } - /// public static Windows.Foundation.Size Get(string key, Windows.Foundation.Size defaultValue) { return Get(key, defaultValue); } - /// public static Windows.Foundation.Rect Get(string key, Windows.Foundation.Rect defaultValue) { return Get(key, defaultValue); @@ -126,109 +105,91 @@ internal static class LocalSetting return Get(key, defaultValue); } - /// public static void Set(string key, byte value) { Set(key, value); } - /// public static void Set(string key, short value) { Set(key, value); } - /// public static void Set(string key, ushort value) { Set(key, value); } - /// public static void Set(string key, int value) { Set(key, value); } - /// public static void Set(string key, uint value) { Set(key, value); } - /// public static void Set(string key, long value) { Set(key, value); } - /// public static void Set(string key, ulong value) { Set(key, value); } - /// public static void Set(string key, float value) { Set(key, value); } - /// public static void Set(string key, double value) { Set(key, value); } - /// public static void Set(string key, bool value) { Set(key, value); } - /// public static void Set(string key, char value) { Set(key, value); } - /// public static void Set(string key, string value) { Set(key, value); } - /// public static void Set(string key, in DateTimeOffset value) { Set(key, value); } - /// public static void Set(string key, in TimeSpan value) { Set(key, value); } - /// public static void Set(string key, in Guid value) { Set(key, value); } - /// public static void Set(string key, Windows.Foundation.Point value) { Set(key, value); } - /// public static void Set(string key, Windows.Foundation.Size value) { Set(key, value); } - /// public static void Set(string key, Windows.Foundation.Rect value) { Set(key, value); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/AsyncBarrier.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/AsyncBarrier.cs index 5ae015bc..498e32b3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/AsyncBarrier.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/AsyncBarrier.cs @@ -3,26 +3,11 @@ namespace Snap.Hutao.Core.Threading; -/// -/// An asynchronous barrier that blocks the signaler until all other participants have signaled. -/// FIFO -/// internal class AsyncBarrier { - /// - /// The number of participants being synchronized. - /// private readonly int participantCount; - - /// - /// The set of participants who have reached the barrier, with their awaiters that can resume those participants. - /// private readonly Queue waiters; - /// - /// Initializes a new instance of the class. - /// - /// The number of participants. public AsyncBarrier(int participants) { ArgumentOutOfRangeException.ThrowIfNegativeOrZero(participants, "Participants of AsyncBarrier must be greater than 0"); @@ -33,11 +18,6 @@ internal class AsyncBarrier waiters = new Queue(participants - 1); } - /// - /// Signals that a participant is ready, and returns a Task - /// that completes when all other participants have also signaled ready. - /// - /// A Task, which will complete (or may already be completed) when the last participant calls this method. [SuppressMessage("", "SH007")] public ValueTask SignalAndWaitAsync() { diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ConcurrentCancellationTokenSource.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ConcurrentCancellationTokenSource.cs index b3f865a2..821d20a9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ConcurrentCancellationTokenSource.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ConcurrentCancellationTokenSource.cs @@ -3,22 +3,17 @@ namespace Snap.Hutao.Core.Threading; -/// -/// 无区分项的并发 -/// [HighQuality] [SuppressMessage("", "CA1001")] internal class ConcurrentCancellationTokenSource { private CancellationTokenSource source = new(); - /// - /// 注册取消令牌 - /// - /// 取消令牌 public CancellationToken Register() { source.Cancel(); + source.Dispose(); + source = new(); return source.Token; } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/Delay.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/Delay.cs index 0a7590da..5c92c0bd 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/Delay.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/Delay.cs @@ -3,7 +3,9 @@ namespace Snap.Hutao.Core.Threading; +#if NET9_0_OR_GREATER [Obsolete] +#endif internal readonly struct Delay { /// @@ -16,14 +18,4 @@ internal readonly struct Delay { return Task.Delay((int)(System.Random.Shared.NextDouble() * (max - min)) + min).AsValueTask(); } - - public static ValueTask FromSeconds(int seconds) - { - return Task.Delay(TimeSpan.FromSeconds(seconds)).AsValueTask(); - } - - public static ValueTask FromMilliSeconds(int seconds) - { - return Task.Delay(TimeSpan.FromMilliseconds(seconds)).AsValueTask(); - } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueExtension.cs index 0bc5db7a..6f523573 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueExtension.cs @@ -6,17 +6,9 @@ using System.Runtime.ExceptionServices; namespace Snap.Hutao.Core.Threading; -/// -/// 调度器队列拓展 -/// [HighQuality] internal static class DispatcherQueueExtension { - /// - /// 在调度器队列同步调用,直到执行结束,会持续阻塞当前线程 - /// - /// 调度器队列 - /// 执行的回调 public static void Invoke(this DispatcherQueue dispatcherQueue, Action action) { if (dispatcherQueue.HasThreadAccess) @@ -49,13 +41,6 @@ internal static class DispatcherQueueExtension } } - /// - /// 在调度器队列同步调用,直到执行结束,会持续阻塞当前线程 - /// - /// 调度器队列 - /// 执行的回调 - /// 返回类型 - /// 回调返回值 public static T Invoke(this DispatcherQueue dispatcherQueue, Func action) { T result = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueSwitchOperation.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueSwitchOperation.cs index 0f68e4df..92dbc7d0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueSwitchOperation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/DispatcherQueueSwitchOperation.cs @@ -6,48 +6,35 @@ using Snap.Hutao.Core.Threading.Abstraction; namespace Snap.Hutao.Core.Threading; -/// -/// 调度器队列切换操作 -/// 等待此类型对象后上下文会被切换至主线程 -/// [HighQuality] internal readonly struct DispatcherQueueSwitchOperation : IAwaitable, ICriticalAwaiter { private readonly DispatcherQueue dispatherQueue; - /// - /// 构造一个新的调度器队列等待器 - /// - /// 调度器队列 public DispatcherQueueSwitchOperation(DispatcherQueue dispatherQueue) { this.dispatherQueue = dispatherQueue; } - /// public bool IsCompleted { get => dispatherQueue.HasThreadAccess; } - /// public DispatcherQueueSwitchOperation GetAwaiter() { return this; } - /// public void GetResult() { } - /// public void OnCompleted(Action continuation) { dispatherQueue.TryEnqueue(new DispatcherQueueHandler(continuation)); } - /// public void UnsafeOnCompleted(Action continuation) { using (ExecutionContext.SuppressFlow()) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskContext.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskContext.cs index e1d1ee2b..656de2d2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskContext.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskContext.cs @@ -5,18 +5,12 @@ using Microsoft.UI.Dispatching; namespace Snap.Hutao.Core.Threading; -/// -/// 任务上下文 -/// [Injection(InjectAs.Singleton, typeof(ITaskContext))] internal sealed class TaskContext : ITaskContext, ITaskContextUnsafe { private readonly DispatcherQueueSynchronizationContext synchronizationContext; private readonly DispatcherQueue dispatcherQueue; - /// - /// 构造一个新的任务上下文 - /// public TaskContext() { dispatcherQueue = DispatcherQueue.GetForCurrentThread(); @@ -26,25 +20,21 @@ internal sealed class TaskContext : ITaskContext, ITaskContextUnsafe public DispatcherQueue DispatcherQueue { get => dispatcherQueue; } - /// public ThreadPoolSwitchOperation SwitchToBackgroundAsync() { return new(dispatcherQueue); } - /// public DispatcherQueueSwitchOperation SwitchToMainThreadAsync() { return new(dispatcherQueue); } - /// public void InvokeOnMainThread(Action action) { dispatcherQueue.Invoke(action); } - /// public T InvokeOnMainThread(Func action) { return dispatcherQueue.Invoke(action); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskExtension.cs index b5dc143b..44b06918 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskExtension.cs @@ -24,10 +24,6 @@ internal static class TaskExtension return new(task); } - /// - /// 安全的触发任务 - /// - /// 任务 public static async void SafeForget(this Task task) { try @@ -54,11 +50,6 @@ internal static class TaskExtension #endif } - /// - /// 安全的触发任务 - /// - /// 任务 - /// 日志器 public static async void SafeForget(this Task task, ILogger logger) { try @@ -71,16 +62,10 @@ internal static class TaskExtension } catch (Exception e) { - logger?.LogError(e, "{Caller}:\r\n{Exception}", nameof(SafeForget), ExceptionFormat.Format(e.GetBaseException())); + logger?.LogError(e, "SafeForget:\r\n{Exception}", ExceptionFormat.Format(e.GetBaseException())); } } - /// - /// 安全的触发任务 - /// - /// 任务 - /// 日志器 - /// 发生异常时调用 public static async void SafeForget(this Task task, ILogger logger, Action onException) { try @@ -93,18 +78,11 @@ internal static class TaskExtension } catch (Exception e) { - logger?.LogError(e, "{Caller}:\r\n{Exception}", nameof(SafeForget), ExceptionFormat.Format(e.GetBaseException())); + logger?.LogError(e, "SafeForget:\r\n{Exception}", ExceptionFormat.Format(e.GetBaseException())); onException?.Invoke(e); } } - /// - /// 安全的触发任务 - /// - /// 任务 - /// 日志器 - /// 任务取消时调用 - /// 发生异常时调用 public static async void SafeForget(this Task task, ILogger logger, Action onCanceled, Action? onException = null) { try @@ -117,15 +95,11 @@ internal static class TaskExtension } catch (Exception e) { - logger?.LogError(e, "{Caller}:\r\n{Exception}", nameof(SafeForget), ExceptionFormat.Format(e.GetBaseException())); + logger?.LogError(e, "SafeForget:\r\n{Exception}", ExceptionFormat.Format(e.GetBaseException())); onException?.Invoke(e); } } - /// - /// 安全的触发任务 - /// - /// 任务 public static async void SafeForget(this ValueTask task) { try @@ -152,11 +126,6 @@ internal static class TaskExtension #endif } - /// - /// 安全的触发任务 - /// - /// 任务 - /// 日志器 public static async void SafeForget(this ValueTask task, ILogger logger) { try @@ -169,16 +138,10 @@ internal static class TaskExtension } catch (Exception e) { - logger?.LogError(e, "{Caller}:\r\n{Exception}", nameof(SafeForget), ExceptionFormat.Format(e.GetBaseException())); + logger?.LogError(e, "SafeForget:\r\n{Exception}", ExceptionFormat.Format(e.GetBaseException())); } } - /// - /// 安全的触发任务 - /// - /// 任务 - /// 日志器 - /// 发生异常时调用 public static async void SafeForget(this ValueTask task, ILogger logger, Action onException) { try @@ -191,18 +154,11 @@ internal static class TaskExtension } catch (Exception e) { - logger?.LogError(e, "{Caller}:\r\n{Exception}", nameof(SafeForget), ExceptionFormat.Format(e.GetBaseException())); + logger?.LogError(e, "SafeForget:\r\n{Exception}", ExceptionFormat.Format(e.GetBaseException())); onException?.Invoke(e); } } - /// - /// 安全的触发任务 - /// - /// 任务 - /// 日志器 - /// 任务取消时调用 - /// 发生异常时调用 public static async void SafeForget(this ValueTask task, ILogger logger, Action onCanceled, Action? onException = null) { try @@ -215,7 +171,7 @@ internal static class TaskExtension } catch (Exception e) { - logger?.LogError(e, "{Caller}:\r\n{Exception}", nameof(SafeForget), ExceptionFormat.Format(e.GetBaseException())); + logger?.LogError(e, "SafeForget:\r\n{Exception}", ExceptionFormat.Format(e.GetBaseException())); onException?.Invoke(e); } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ThreadPoolSwitchOperation.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ThreadPoolSwitchOperation.cs index 54c67f98..81fd1f76 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ThreadPoolSwitchOperation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ThreadPoolSwitchOperation.cs @@ -6,49 +6,36 @@ using Snap.Hutao.Core.Threading.Abstraction; namespace Snap.Hutao.Core.Threading; -/// -/// 线程池切换操作 -/// 等待此类型对象后上下文会被切换至线程池线程 -/// internal readonly struct ThreadPoolSwitchOperation : IAwaitable, ICriticalAwaiter { private static readonly WaitCallback WaitCallbackRunAction = RunAction; private readonly DispatcherQueue dispatherQueue; - /// - /// 构造一个新的线程池切换操作 - /// - /// 主线程队列 public ThreadPoolSwitchOperation(DispatcherQueue dispatherQueue) { this.dispatherQueue = dispatherQueue; } - /// public bool IsCompleted { // 如果已经处于后台就不再切换新的线程 get => !dispatherQueue.HasThreadAccess; } - /// public ThreadPoolSwitchOperation GetAwaiter() { return this; } - /// public void GetResult() { } - /// public void OnCompleted(Action continuation) { QueueContinuation(continuation, true); } - /// public void UnsafeOnCompleted(Action continuation) { QueueContinuation(continuation, false); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResult.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResult.cs index 1f6162c6..f6f75f11 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResult.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResult.cs @@ -5,39 +5,17 @@ using Snap.Hutao.Core.Abstraction; namespace Snap.Hutao.Core.Threading; -/// -/// 用于包装异步操作的结果 -/// -/// 结果类型 -/// 值类型 internal readonly struct ValueResult : IDeconstruct { - /// - /// 是否成功 - /// public readonly TResult IsOk; - - /// - /// 值 - /// public readonly TValue Value; - /// - /// 构造一个新的结果 - /// - /// 是否成功 - /// 值 public ValueResult(TResult isOk, TValue value) { IsOk = isOk; Value = value; } - /// - /// 用于元组析构 - /// - /// 是否成功 - /// 值 public void Deconstruct(out TResult isOk, out TValue value) { isOk = IsOk; diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResultExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResultExtension.cs index c00b4416..fccaff98 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResultExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/ValueResultExtension.cs @@ -3,18 +3,8 @@ namespace Snap.Hutao.Core.Threading; -/// -/// 结果扩展 -/// internal static class ValueResultExtension { - /// - /// 尝试获取结果的值 - /// - /// 值的类型 - /// 结果 - /// 值 - /// 是否获取成功 public static bool TryGetValue(this in ValueResult valueResult, [NotNullWhen(true)] out TValue value) { value = valueResult.Value; diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs index edd0c9bd..f103d631 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs @@ -33,6 +33,7 @@ internal sealed class HotKeyCombination : ObservableObject private HOT_KEY_MODIFIERS modifiers; private VirtualKey key; private bool isEnabled; + private bool isOn; [SuppressMessage("", "SH002")] public HotKeyCombination(IServiceProvider serviceProvider, HWND hwnd, string settingKey, int hotKeyId, HOT_KEY_MODIFIERS defaultModifiers, VirtualKey defaultKey) @@ -162,6 +163,12 @@ internal sealed class HotKeyCombination : ObservableObject } } + public bool IsOn + { + get => isOn; + set => SetProperty(ref isOn, value); + } + public string DisplayName { get => ToString(); } public bool Register() diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs index c5ab5581..601a7f38 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs @@ -8,6 +8,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static Snap.Hutao.Win32.ConstValues; using static Snap.Hutao.Win32.User32; +using static Snap.Hutao.Win32.Kernel32; +using static Snap.Hutao.Win32.Macros; namespace Snap.Hutao.Core.Windowing.HotKey; @@ -39,7 +41,7 @@ internal sealed class HotKeyMessageWindow : IDisposable if (HWND == default) { - Marshal.ThrowExceptionForHR(Marshal.GetLastPInvokeError()); + Marshal.ThrowExceptionForHR(HRESULT_FROM_WIN32(GetLastError())); } WindowTable.TryAdd(HWND, this); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyOptions.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyOptions.cs index 5ecec692..b3f7fd7d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyOptions.cs @@ -120,19 +120,19 @@ internal sealed partial class HotKeyOptions : ObservableObject, IDisposable { lock (syncRoot) { - if (IsMouseClickRepeatForeverOn) + if (MouseClickRepeatForeverKeyCombination.IsOn) { // Turn off cancellationTokenSource?.Cancel(); cancellationTokenSource = default; - IsMouseClickRepeatForeverOn = false; + MouseClickRepeatForeverKeyCombination.IsOn = false; } else { // Turn on cancellationTokenSource = new(); ThreadPool.QueueUserWorkItem(RunMouseClickRepeatForever, cancellationTokenSource.Token); - IsMouseClickRepeatForeverOn = true; + MouseClickRepeatForeverKeyCombination.IsOn = true; } } } diff --git a/src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml.cs index afbbeb6d..1e1d1e2d 100644 --- a/src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml.cs @@ -44,7 +44,7 @@ internal sealed partial class IdentifyMonitorWindow : Window window.Activate(); } - await Delay.FromSeconds(secondsDelay).ConfigureAwait(true); + await Task.Delay(TimeSpan.FromSeconds(secondsDelay)).ConfigureAwait(true); foreach (IdentifyMonitorWindow window in windows) { diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/UI/Input/KeyboardAndMouse/INPUT.cs b/src/Snap.Hutao/Snap.Hutao/Win32/UI/Input/KeyboardAndMouse/INPUT.cs index d619c421..07c0099a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/UI/Input/KeyboardAndMouse/INPUT.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/UI/Input/KeyboardAndMouse/INPUT.cs @@ -9,10 +9,10 @@ namespace Snap.Hutao.Win32.UI.Input.KeyboardAndMouse; internal struct INPUT { public INPUT_TYPE type; - public AnonymousUnion Anonymous; + public Union Anonymous; [StructLayout(LayoutKind.Explicit)] - internal struct AnonymousUnion + internal struct Union { [FieldOffset(0)] public MOUSEINPUT mi;