Skip to content

Commit 84528ae

Browse files
committed
Use Instance class with static method
1 parent 8f18e2f commit 84528ae

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey
99
/// Listens keyboard globally.
1010
/// <remarks>Uses WH_KEYBOARD_LL.</remarks>
1111
/// </summary>
12-
public static unsafe class GlobalHotkey
12+
public unsafe class GlobalHotkey : IDisposable
1313
{
1414
private static readonly IntPtr hookId;
1515

@@ -28,7 +28,6 @@ static GlobalHotkey()
2828
{
2929
// Set the hook
3030
hookId = InterceptKeys.SetHook(& LowLevelKeyboardProc);
31-
AppDomain.CurrentDomain.ProcessExit += (_, _) => Dispose();
3231
}
3332

3433
public static SpecialKeyState CheckModifiers()
@@ -82,9 +81,14 @@ private static IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lPa
8281
return (IntPtr)(-1);
8382
}
8483

85-
public static void Dispose()
84+
public void Dispose()
8685
{
8786
InterceptKeys.UnhookWindowsHookEx(hookId);
8887
}
88+
89+
~GlobalHotkey()
90+
{
91+
Dispose();
92+
}
8993
}
9094
}

0 commit comments

Comments
 (0)