From 8163e2241a453106eecb4662038d4fd731c445c3 Mon Sep 17 00:00:00 2001 From: NimBold Date: Thu, 27 Aug 2026 15:50:53 +0330 Subject: [PATCH] fix(startup): avoid reentrant Windows focus (#37) - Keep the main WebView2 window unfocused during native construction. - Remove the synchronous post-build focus request that caused the Windows stack overflow. - Refs #37. --- src-tauri/src/lib.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ce42028..d3b9eb2 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -18518,22 +18518,15 @@ pub fn run() { // newly-created host window is not focusable yet. Wry // propagates that error from WebviewWindowBuilder::build, // which destroys the native window and makes a release build - // look like it started headlessly before exiting. Focus the - // window only after WebView2 has been created successfully. + // look like it started headlessly before exiting. Leave the + // window unfocused until Windows has completed native + // activation; a synchronous post-build focus request can + // re-enter the WebView2 focus callback on affected systems. main_window_builder = main_window_builder.focused(false); } - let main_window = main_window_builder + main_window_builder .build() .map_err(|error| format!("failed to create main window: {error}"))?; - #[cfg(target_os = "windows")] - if let Err(error) = main_window.set_focus() { - // The window is already usable if the OS declines this - // best-effort activation request. A later user interaction - // can focus it without risking startup failure. - log::warn!("could not focus the main window after startup: {error}"); - } - #[cfg(not(target_os = "windows"))] - let _ = main_window; restore_pending_main_window(app.handle()); #[cfg(any(target_os = "windows", target_os = "linux"))]