From 84528ae8a70ed5c4a832ce2a1f9da830808e67e7 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sun, 5 Dec 2021 18:22:41 -0600 Subject: [PATCH] Use Instance class with static method --- Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs b/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs index f26348e3d..5f14b7598 100644 --- a/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs +++ b/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs @@ -9,7 +9,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey /// Listens keyboard globally. /// Uses WH_KEYBOARD_LL. /// - public static unsafe class GlobalHotkey + public unsafe class GlobalHotkey : IDisposable { private static readonly IntPtr hookId; @@ -28,7 +28,6 @@ namespace Flow.Launcher.Infrastructure.Hotkey { // Set the hook hookId = InterceptKeys.SetHook(& LowLevelKeyboardProc); - AppDomain.CurrentDomain.ProcessExit += (_, _) => Dispose(); } public static SpecialKeyState CheckModifiers() @@ -82,9 +81,14 @@ namespace Flow.Launcher.Infrastructure.Hotkey return (IntPtr)(-1); } - public static void Dispose() + public void Dispose() { InterceptKeys.UnhookWindowsHookEx(hookId); } + + ~GlobalHotkey() + { + Dispose(); + } } } \ No newline at end of file