Skip to content

Commit

Permalink
修复 快捷键激活/设置
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Jul 23, 2024
1 parent 085cba4 commit e517c78
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
24 changes: 20 additions & 4 deletions Core.Window/HotKeyImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public bool Add(HotKeyModel hotKeyModel, Action<HotKeyModel> rallBack)
RallBack = rallBack
});
}
else
{
HotKeys.Add(hotKeyModel.UUID, new HotkeyInfo()
{
HotKeyModel = hotKeyModel,
Id = -1,
RallBack = rallBack
});
}

return registerHotKey;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<HotKeyModel> GetAllRegistered()
{
return HotKeys.Values.Select(x => x.HotKeyModel);
Expand Down
2 changes: 2 additions & 0 deletions Core/SDKs/Services/IHotKetImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HotKeyModel> GetAllRegistered();

public IEnumerable<HotKeyModel> AllRegistered
Expand Down
33 changes: 28 additions & 5 deletions KitopiaAvalonia/Controls/HotKeyShow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand All @@ -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<IContentDialog>().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;
}
}
}
}
5 changes: 3 additions & 2 deletions KitopiaAvalonia/Windows/HotKeyEditorWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
};
if (!HotKeyManager.HotKetImpl.Modify(hotKeyModel))
{
ServiceManager.Services.GetService<IContentDialog>().ShowDialog(this, new DialogContent()
ServiceManager.Services.GetService<IContentDialog>().ShowDialogAsync(this, new DialogContent()
{
Title = $"快捷键{hotKeyModel.SignName}设置失败",
Content = "请重新设置快捷键,按键与系统其他程序冲突"
Content = "请重新设置快捷键,按键与系统其他程序冲突",
CloseButtonText = "关闭"
});
}
else
Expand Down

0 comments on commit e517c78

Please sign in to comment.