From 6e7d51841d2d48d029c61a87722f2a881e2cfc5f Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Mon, 27 Jul 2026 04:33:44 +0800 Subject: [PATCH] feat(pet): log both pet window commands on entry Switching to the floating pet produced no log line at all, which was ambiguous: the command may never have been invoked, or it may have failed before reaching the only log statement, which sat after placement and show(). Log both open and close on entry, with whether the window already existed, and log the error on each failure path. A missing line now means the command was not invoked, which points at the shell rather than the window. The pairing also makes the order readable. The shell closes the pet on startup whenever it renders inside the UI, and that destroy is what forces every later open through the rebuild path. Refs: N-11. Co-Authored-By: Claude Opus 5 --- src-tauri/src/lib.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 98d689a..3041e19 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -304,8 +304,19 @@ fn open_main_window(app: AppHandle) -> Result<(), String> { #[tauri::command] fn open_pet_window(app: AppHandle) -> Result<(), String> { - if let Some(window) = app.get_webview_window(PET_WINDOW_ID) { - return reveal_pet_window(&app, &window); + 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"); + }); } let config = app .config() @@ -323,7 +334,9 @@ fn open_pet_window(app: AppHandle) -> Result<(), String> { // 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) + reveal_pet_window(&app, &window).inspect_err(|error| { + tracing::info!(target: "astrbot::pet", %error, "revealing the rebuilt pet window failed"); + }) } /// Places the pet window on a monitor and shows it. @@ -424,7 +437,16 @@ async fn check_network_target( #[tauri::command] fn close_pet_window(app: AppHandle) -> Result<(), String> { - if let Some(window) = app.get_webview_window(PET_WINDOW_ID) { + let existing = app.get_webview_window(PET_WINDOW_ID); + // Paired with the open log so the order of the two is readable: the shell + // closes the pet on startup whenever it renders inside the UI, and that + // destroy is what forces every later open through the rebuild path. + tracing::info!( + target: "astrbot::pet", + window_existed = existing.is_some(), + "close_pet_window invoked" + ); + if let Some(window) = existing { window.destroy().map_err(|error| error.to_string())?; } Ok(())