Skip to content

Commit 28c7538

Browse files
committed
Fix possible Win32Exception
1 parent 9035aa6 commit 28c7538

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,10 @@ public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious)
365365
// No installed English layout found
366366
if (enHKL == HKL.Null) return;
367367

368-
// When application is exiting, the Application.Current will be null
369-
if (Application.Current == null) return;
370-
371-
// Get the FL main window
372-
var hwnd = GetWindowHandle(Application.Current.MainWindow, true);
368+
// Get the foreground window
369+
var hwnd = PInvoke.GetForegroundWindow();
373370
if (hwnd == HWND.Null) return;
374371

375-
// Check if the FL main window is the current foreground window
376-
if (!IsForegroundWindow(hwnd))
377-
{
378-
var result = PInvoke.SetForegroundWindow(hwnd);
379-
// If we cannot set the foreground window, we can use the foreground window and switch the layout
380-
if (!result) hwnd = PInvoke.GetForegroundWindow();
381-
}
382-
383372
// Get the current foreground window thread ID
384373
var threadId = PInvoke.GetWindowThreadProcessId(hwnd);
385374
if (threadId == 0) throw new Win32Exception(Marshal.GetLastWin32Error());

0 commit comments

Comments
 (0)