{"record":{"id":"4f6cf8f5e2c37de1","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-tray-menu-window-after-creation","errorCode":null,"errorMessage":"failed to get tray menu window after creation","messagePattern":"failed to get tray menu window after creation","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/resolve.rs","lineNumber":628,"sourceCode":"\n/// Show the webview tray menu window near the given cursor position.\npub fn show_tray_menu_window(\n    app_handle: &AppHandle,\n    cursor: tauri::PhysicalPosition<f64>,\n) -> Result<()> {\n    use tauri::{Manager, PhysicalPosition};\n\n    TRAY_MENU_PERSISTENT.store(false, Ordering::Release);\n    TRAY_MENU_READY.store(false, Ordering::Release);\n    ignore_tray_menu_blur_for(TRAY_MENU_SHOW_BLUR_GRACE_MS);\n\n    let win = match app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL) {\n        Some(existing) => existing,\n        None => {\n            let result = TrayMenuWindow.create_with_params(app_handle, None)?;\n            let win = app_handle\n                .get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)\n                .ok_or_else(|| anyhow::anyhow!(\"failed to get tray menu window after creation\"))?;\n            if result.is_new {\n                setup_tray_menu_focus_handler(&win);\n            }\n            win\n        }\n    };\n\n    let (menu_w, menu_h) = win\n        .outer_size()\n        .map(|size| {\n            let width = if size.width == 0 {\n                240.0\n            } else {\n                size.width as f64\n            };\n            let height = if size.height == 0 {\n                448.0\n            } else {","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/resolve.rs#L610-L646","documentation":"show_tray_menu_window reuses an existing tray menu window or creates one via TrayMenuWindow.create_with_params. When creation was requested but the window still cannot be found by label immediately afterwards, this error is raised. It means the create call did not result in a registered webview window.","triggerScenarios":"The None-branch runs (window absent), create_with_params returns Ok, but the follow-up get_webview_window(TRAY_MENU_WINDOW_LABEL) still returns None — label mismatch, deferred/async registration, or the new window failed during webview initialization and was dropped.","commonSituations":"Label constant changed in creation code but not consts; window creation succeeded at the manager level but the webview build failed and cleaned up; concurrent close racing the lookup.","solutions":["Confirm the label passed to TrayMenuWindow creation equals crate::consts::TRAY_MENU_WINDOW_LABEL","Inspect logs from the webview window creation for build failures that unregister the window","Retry the lookup once after a yield/sleep if registration is asynchronous, or return the created window handle directly from create_with_params","Serialize tray window show/create to avoid concurrent close/recreate races"],"exampleFix":"// before\nlet result = TrayMenuWindow.create_with_params(app_handle, None)?;\nlet win = app_handle\n    .get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)\n    .ok_or_else(|| anyhow::anyhow!(\"failed to get tray menu window after creation\"))?;\n// after: have create_with_params return the window itself\nlet result = TrayMenuWindow.create_with_params(app_handle, None)?;\nlet win = result.window.ok_or_else(|| anyhow::anyhow!(\n    \"tray menu window missing after creation (is_new={})\", result.is_new\n))?;","handlingStrategy":"retry","validationCode":"if app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL).is_some() {\n    // existing window; skip creation path entirely\n}","typeGuard":null,"tryCatchPattern":"let win = loop {\n    if let Some(w) = app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL) {\n        break w;\n    }\n    TrayMenuWindow.create_with_params(app_handle, None)?;\n    tokio::time::sleep(Duration::from_millis(50)).await; // allow registration\n    // bound retries in real code\n};","preventionTips":["Return the created window handle from create_with_params instead of re-looking it up","Log webview creation failures that may unregister the window","Use a single creation path (the actor/manager) to prevent races"],"tags":["tauri","window","tray","webview"],"backgroundTag":"resource-not-found","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}