mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add global key registeration
This commit is contained in:
parent
5f49c436e7
commit
605837b474
1 changed files with 39 additions and 6 deletions
|
|
@ -1,11 +1,13 @@
|
|||
using Flow.Launcher.Infrastructure.Hotkey;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using System;
|
||||
using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using System;
|
||||
using ChefKeys;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Infrastructure.Hotkey;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
|
||||
namespace Flow.Launcher.Helper;
|
||||
|
||||
|
|
@ -23,6 +25,7 @@ internal static class HotKeyMapper
|
|||
|
||||
SetHotkey(_settings.Hotkey, OnToggleHotkey);
|
||||
LoadCustomPluginHotkey();
|
||||
LoadGlobalPluginHotkey();
|
||||
}
|
||||
|
||||
internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
|
||||
|
|
@ -142,6 +145,36 @@ internal static class HotKeyMapper
|
|||
});
|
||||
}
|
||||
|
||||
internal static void LoadGlobalPluginHotkey()
|
||||
{
|
||||
var pluginHotkeyInfos = PluginManager.GetPluginHotkeyInfo();
|
||||
foreach (var info in pluginHotkeyInfos)
|
||||
{
|
||||
var pluginPair = info.Key;
|
||||
var hotkeyInfo = info.Value;
|
||||
var metadata = pluginPair.Metadata;
|
||||
foreach (var hotkey in hotkeyInfo)
|
||||
{
|
||||
if (hotkey.HotkeyType == HotkeyType.Global && hotkey is GlobalPluginHotkey globalHotkey)
|
||||
{
|
||||
var hotkeySetting = metadata.PluginHotkeys.Find(h => h.Id == hotkey.Id)?.Hotkey ?? hotkey.DefaultHotkey;
|
||||
SetGlobalPluginHotkey(globalHotkey, metadata, hotkeySetting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetGlobalPluginHotkey(GlobalPluginHotkey globalHotkey, PluginMetadata metadata, string hotkeySetting)
|
||||
{
|
||||
SetHotkey(hotkeySetting, (s, e) =>
|
||||
{
|
||||
if (_mainViewModel.ShouldIgnoreHotkeys() || metadata.Disabled)
|
||||
return;
|
||||
|
||||
globalHotkey.Action?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
internal static bool CheckAvailability(HotkeyModel currentHotkey)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in a new issue