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(())