feat(pet): log both pet window commands on entry
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run

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 <noreply@anthropic.com>
这个提交存在于:
YokiiroBW 2026-07-27 04:33:44 +08:00
父节点 b5e3acbb72
当前提交 6e7d51841d

查看文件

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