diff --git a/desktop/src/main.rs b/desktop/src/main.rs index 853e110..8d7ebd5 100644 --- a/desktop/src/main.rs +++ b/desktop/src/main.rs @@ -391,7 +391,7 @@ fn main() { save_window_state, get_window_state, ]) - .setup(|app| { + .setup(move |app| { // Restore window position/size if let Some(window) = app.get_webview_window("main") { if let (Some(x), Some(y)) = (config.window_x, config.window_y) { @@ -437,20 +437,20 @@ fn main() { tokio::time::sleep(Duration::from_secs(5)).await; let state = handle2.state::(); - let mut child_guard = match state.child.lock() { - Ok(g) => g, - Err(_) => break, + // Drop guard before any await + let died = { + let mut child_guard = match state.child.lock() { + Ok(g) => g, + Err(_) => break, + }; + match &mut *child_guard { + Some(child) => child.try_wait().ok().flatten().is_some(), + None => true, + } }; - let died = match &mut *child_guard { - Some(child) => child.try_wait().ok().flatten().is_some(), - None => true, - }; - drop(child_guard); - if died { warn!("Backend process died unexpectedly!"); - // Inject a notice into the UI if let Some(window) = handle2.get_webview_window("main") { let _ = window.eval( r#"if (typeof showBackendCrashBanner === 'function') showBackendCrashBanner();"#, @@ -458,7 +458,7 @@ fn main() { } } - // If we were restarting, check if new backend is ready + // If restarting, check if new backend is ready let restarting = state.restarting.lock().ok().map(|r| *r).unwrap_or(false); if restarting { if wait_for_backend().await.is_ok() {