Merge pull request #3461 from Flow-Launcher/keyboard_win32_exception

Fix possible win32 exception
This commit is contained in:
Jack Ye 2025-04-14 01:00:26 +08:00 committed by GitHub
commit 62935dbd0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -376,7 +376,8 @@ namespace Flow.Launcher.Infrastructure
if (!IsForegroundWindow(hwnd)) if (!IsForegroundWindow(hwnd))
{ {
var result = PInvoke.SetForegroundWindow(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 // Get the current foreground window thread ID