From 4f73c0819d65b5561e33dd9fe0fd471ec2b67ace Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Mon, 27 Jul 2026 04:39:20 +0800 Subject: [PATCH] fix(pet): hide the pet window instead of destroying it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The desktop-floating pet never appeared. The log established that open_pet_window ran, took the rebuild branch, and then produced neither the success log nor the failure log — so it returned Err somewhere in the config lookup, from_config, or build(), all three of which used a bare `?` with no log of their own. Two changes. close_pet_window now hides the window rather than destroying it, so every later open takes the branch that demonstrably works instead of the rebuild branch; hiding also keeps the pet's listeners and animation state, which the mode switch wants back immediately anyway. And open_pet_window is wrapped so any failure on any path is logged with the error, rather than only the reveal step. Co-Authored-By: Claude Opus 5 --- src-tauri/src/lib.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3041e19..cb8bf05 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -304,19 +304,23 @@ fn open_main_window(app: AppHandle) -> Result<(), String> { #[tauri::command] fn open_pet_window(app: AppHandle) -> Result<(), String> { + // Wrapped so every failure path is reported. The rebuild path used to fail + // silently: the entry log said the command ran, no success log followed, and + // the three `?` returns before the reveal had no log of their own. + open_pet_window_inner(&app).inspect_err(|error| { + tracing::info!(target: "astrbot::pet", %error, "open_pet_window failed"); + }) +} + +fn open_pet_window_inner(app: &AppHandle) -> Result<(), String> { let existing = app.get_webview_window(PET_WINDOW_ID); - // Logged on entry so that "no log line at all" means the command was never - // invoked, rather than leaving that indistinguishable from a failure before - // the first log statement. tracing::info!( target: "astrbot::pet", window_existed = existing.is_some(), "open_pet_window invoked" ); if let Some(window) = existing { - return reveal_pet_window(&app, &window).inspect_err(|error| { - tracing::info!(target: "astrbot::pet", %error, "revealing the existing pet window failed"); - }); + return reveal_pet_window(app, &window); } let config = app .config() @@ -325,18 +329,13 @@ fn open_pet_window(app: AppHandle) -> Result<(), String> { .iter() .find(|window| window.label == PET_WINDOW_ID) .ok_or_else(|| "pet window config is unavailable".to_owned())?; - let window = WebviewWindowBuilder::from_config(&app, config) - .map_err(|error| error.to_string())? + let window = WebviewWindowBuilder::from_config(app, config) + .map_err(|error| format!("pet window builder: {error}"))? .build() - .map_err(|error| error.to_string())?; - // The rebuild path used to stop here. `close_pet_window` destroys the - // window rather than hiding it, and the app closes it on startup whenever - // the pet is set to render inside the UI, so switching to the floating pet - // always took this path — and the config declares `visible: false`, so the - // window was built and never shown. It simply did not appear. - reveal_pet_window(&app, &window).inspect_err(|error| { - tracing::info!(target: "astrbot::pet", %error, "revealing the rebuilt pet window failed"); - }) + .map_err(|error| format!("pet window build: {error}"))?; + // The rebuild path used to stop here: the config declares `visible: false`, + // so the window was built and never shown. + reveal_pet_window(app, &window) } /// Places the pet window on a monitor and shows it. @@ -446,8 +445,12 @@ fn close_pet_window(app: AppHandle) -> Result<(), String> { window_existed = existing.is_some(), "close_pet_window invoked" ); + // Hidden, not destroyed. Destroying forced every later open through the + // rebuild path, which is the path that fails — and rebuilding also throws + // away the pet's listeners and animation state for no gain, since the same + // window is wanted again as soon as the mode is switched back. if let Some(window) = existing { - window.destroy().map_err(|error| error.to_string())?; + window.hide().map_err(|error| error.to_string())?; } Ok(()) }