From e517c788b0c01a9822760ee3c8b0aa800252a474 Mon Sep 17 00:00:00 2001 From: MakesYT <2696703792@qq.com> Date: Tue, 23 Jul 2024 16:06:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE=E6=BF=80=E6=B4=BB/=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core.Window/HotKeyImpl.cs | 24 +++++++++++--- Core/SDKs/Services/IHotKetImpl.cs | 2 ++ KitopiaAvalonia/Controls/HotKeyShow.axaml.cs | 33 ++++++++++++++++--- .../Windows/HotKeyEditorWindow.axaml.cs | 5 +-- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Core.Window/HotKeyImpl.cs b/Core.Window/HotKeyImpl.cs index a6eacae..d8d55d7 100644 --- a/Core.Window/HotKeyImpl.cs +++ b/Core.Window/HotKeyImpl.cs @@ -91,6 +91,15 @@ public bool Add(HotKeyModel hotKeyModel, Action rallBack) RallBack = rallBack }); } + else + { + HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo() + { + HotKeyModel = hotKeyModel, + Id = -1, + RallBack = rallBack + }); + } return registerHotKey; } @@ -104,10 +113,7 @@ public bool Del(string uuid) { var unregisterHotKey = User32.UnregisterHotKey(globalHotKeyWindow.TryGetPlatformHandle().Handle, HotKeys[uuid].Id); - if (unregisterHotKey) - { - HotKeys.Remove(uuid); - } + HotKeys.Remove(uuid); return unregisterHotKey; } @@ -150,6 +156,16 @@ public bool Modify(HotKeyModel hotKeyModel) return null; } + public bool IsActive(string uuid) + { + if (HotKeys.ContainsKey(uuid)) + { + return HotKeys[uuid].Id != -1; + } + + return false; + } + public IEnumerable GetAllRegistered() { return HotKeys.Values.Select(x => x.HotKeyModel); diff --git a/Core/SDKs/Services/IHotKetImpl.cs b/Core/SDKs/Services/IHotKetImpl.cs index 49d339d..935c0b4 100644 --- a/Core/SDKs/Services/IHotKetImpl.cs +++ b/Core/SDKs/Services/IHotKetImpl.cs @@ -11,6 +11,8 @@ public interface IHotKetImpl public bool RequestUserModify(string uuid); public bool Modify(HotKeyModel hotKeyModel); public HotKeyModel? GetByUuid(string uuid); + + public bool IsActive(string uuid); public IEnumerable GetAllRegistered(); public IEnumerable AllRegistered diff --git a/KitopiaAvalonia/Controls/HotKeyShow.axaml.cs b/KitopiaAvalonia/Controls/HotKeyShow.axaml.cs index 8741d41..f679773 100644 --- a/KitopiaAvalonia/Controls/HotKeyShow.axaml.cs +++ b/KitopiaAvalonia/Controls/HotKeyShow.axaml.cs @@ -4,8 +4,11 @@ using Avalonia.Controls.Primitives; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; +using Core.SDKs; using Core.SDKs.HotKey; +using Core.SDKs.Services; using Core.SDKs.Services.Config; +using Microsoft.Extensions.DependencyInjection; namespace KitopiaAvalonia.Controls; @@ -157,7 +160,8 @@ private static void HotKeyModelChanged(HotKeyModel? hotKeyModelN, HotKeyShow hot type = 10000; } - hotKeyShow.IsActivated = HotKeyManager.HotKetImpl.GetByUuid(hotKeyModel.UUID) != null; + + hotKeyShow.IsActivated = HotKeyManager.HotKetImpl.IsActive(hotKeyModel.UUID); hotKeyShow.KeyType = (HotKeyShow.KeyTypeE)type; hotKeyShow.KeyName = hotKeyModel.SelectKey.ToString(); } @@ -182,10 +186,29 @@ private void Edit() if (HotKeyModel.Value.SelectKey != EKey.未设置) { - IsActivated = true; - HotKeyManager.HotKetImpl.RequestUserModify(HotKeyModel.Value.UUID); - ConfigManger.Save(); - return; + if (!IsActivated) + { + if (!HotKeyManager.HotKetImpl.Modify(HotKeyModel.Value)) + { + ServiceManager.Services.GetService().ShowDialogAsync(null, new DialogContent() + { + Title = $"快捷键{HotKeyModel.Value.SignName}设置失败", + Content = "请重新设置快捷键,按键与系统其他程序冲突", + CloseButtonText = "关闭" + }); + HotKeyManager.HotKetImpl.RequestUserModify(HotKeyModel.Value.UUID); + ConfigManger.Save(); + return; + } + + IsActivated = true; + } + else + { + HotKeyManager.HotKetImpl.RequestUserModify(HotKeyModel.Value.UUID); + ConfigManger.Save(); + return; + } } } } \ No newline at end of file diff --git a/KitopiaAvalonia/Windows/HotKeyEditorWindow.axaml.cs b/KitopiaAvalonia/Windows/HotKeyEditorWindow.axaml.cs index 64fea8d..c5db937 100644 --- a/KitopiaAvalonia/Windows/HotKeyEditorWindow.axaml.cs +++ b/KitopiaAvalonia/Windows/HotKeyEditorWindow.axaml.cs @@ -151,10 +151,11 @@ private void ButtonBase_OnClick(object sender, RoutedEventArgs e) }; if (!HotKeyManager.HotKetImpl.Modify(hotKeyModel)) { - ServiceManager.Services.GetService().ShowDialog(this, new DialogContent() + ServiceManager.Services.GetService().ShowDialogAsync(this, new DialogContent() { Title = $"快捷键{hotKeyModel.SignName}设置失败", - Content = "请重新设置快捷键,按键与系统其他程序冲突" + Content = "请重新设置快捷键,按键与系统其他程序冲突", + CloseButtonText = "关闭" }); } else