Skip to content

Commit eec6145

Browse files
committed
Fix possible win32 exception
1 parent 9dd5f06 commit eec6145

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious)
376376
if (!IsForegroundWindow(hwnd))
377377
{
378378
var result = PInvoke.SetForegroundWindow(hwnd);
379-
if (!result) throw new Win32Exception(Marshal.GetLastWin32Error());
379+
// If we cannot set the foreground window, we can use the foreground window and switch the layout
380+
if (!result) hwnd = PInvoke.GetForegroundWindow();
380381
}
381382

382383
// Get the current foreground window thread ID

0 commit comments

Comments
 (0)