Fix possible win32 exception

This commit is contained in:
Jack251970 2025-04-13 20:35:27 +08:00
parent 9dd5f06930
commit eec6145e1a

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