diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 6be024389..798501ae3 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -365,21 +365,10 @@ namespace Flow.Launcher.Infrastructure // No installed English layout found if (enHKL == HKL.Null) return; - // When application is exiting, the Application.Current will be null - if (Application.Current == null) return; - - // Get the FL main window - var hwnd = GetWindowHandle(Application.Current.MainWindow, true); + // Get the foreground window + var hwnd = PInvoke.GetForegroundWindow(); if (hwnd == HWND.Null) return; - // Check if the FL main window is the current foreground window - if (!IsForegroundWindow(hwnd)) - { - var result = PInvoke.SetForegroundWindow(hwnd); - // If we cannot set the foreground window, we can use the foreground window and switch the layout - if (!result) hwnd = PInvoke.GetForegroundWindow(); - } - // Get the current foreground window thread ID var threadId = PInvoke.GetWindowThreadProcessId(hwnd); if (threadId == 0) throw new Win32Exception(Marshal.GetLastWin32Error());