From eec6145e1aca49f36be49a8b36099e8865ab97cf Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 13 Apr 2025 20:35:27 +0800 Subject: [PATCH] Fix possible win32 exception --- Flow.Launcher.Infrastructure/Win32Helper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 54604a27118..6be0243899a 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -376,7 +376,8 @@ public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious) if (!IsForegroundWindow(hwnd)) { var result = PInvoke.SetForegroundWindow(hwnd); - if (!result) throw new Win32Exception(Marshal.GetLastWin32Error()); + // 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