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.
This commit is contained in:
NimBold
2026-08-27 15:50:53 +03:30
parent 0c65837360
commit 8163e2241a
+5 -12
View File
@@ -18518,22 +18518,15 @@ pub fn run() {
// newly-created host window is not focusable yet. Wry // newly-created host window is not focusable yet. Wry
// propagates that error from WebviewWindowBuilder::build, // propagates that error from WebviewWindowBuilder::build,
// which destroys the native window and makes a release build // which destroys the native window and makes a release build
// look like it started headlessly before exiting. Focus the // look like it started headlessly before exiting. Leave the
// window only after WebView2 has been created successfully. // 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); main_window_builder = main_window_builder.focused(false);
} }
let main_window = main_window_builder main_window_builder
.build() .build()
.map_err(|error| format!("failed to create main window: {error}"))?; .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()); restore_pending_main_window(app.handle());
#[cfg(any(target_os = "windows", target_os = "linux"))] #[cfg(any(target_os = "windows", target_os = "linux"))]