{"record":{"id":"676e201d92cf4563","repo":"jlcodes99/cockpit-tools","slug":"tray-676e20","errorCode":null,"errorMessage":"[Tray] 后台更新托盘菜单失败: {}","messagePattern":"\\[Tray\\] 后台更新托盘菜单失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src-tauri/src/lib.rs","lineNumber":505,"sourceCode":"            #[cfg(target_os = \"macos\")]\n            {\n                let tray_app_handle = app.handle().clone();\n                std::thread::spawn(move || {\n                    std::thread::sleep(std::time::Duration::from_millis(800));\n                    if let Err(err) = modules::tray::apply_tray_icon_style(&tray_app_handle) {\n                        logger::log_warn(&format!(\n                            \"[Tray] macOS 启动后重应用菜单栏图标样式失败: {}\",\n                            err\n                        ));\n                    }\n                });\n            }\n\n            // 后台线程加载完整托盘菜单（含账号数据）\n            let tray_app_handle = app.handle().clone();\n            std::thread::spawn(move || {\n                if let Err(e) = modules::tray::update_tray_menu(&tray_app_handle) {\n                    logger::log_error(&format!(\"[Tray] 后台更新托盘菜单失败: {}\", e));\n                }\n            });\n\n            if let Err(err) =\n                modules::floating_card_window::show_floating_card_window_on_startup(&app.handle())\n            {\n                logger::log_warn(&format!(\"[FloatingCard] 启动时显示悬浮卡片失败: {}\", err));\n            }\n\n            let startup_args: Vec<String> = std::env::args().collect();\n            logger::log_info(&format!(\"[Startup] 启动参数数量: {}\", startup_args.len()));\n            let startup_external_import_handled =\n                modules::external_import::handle_external_import_args(\n                    &app.handle(),\n                    &startup_args,\n                    \"startup\",\n                );\n            logger::log_info(&format!(","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/lib.rs#L487-L523","documentation":"After startup, a background thread calls modules::tray::update_tray_menu(&handle) to rebuild the full tray menu with account data. update_tray_menu returns Result<(), String>; any Err is logged as this message. The failure originates in the tray-menu rebuild worker (menu item construction, tray set_menu, or account loading), not in the spawn itself.","triggerScenarios":"The rebuild worker inside spawn_tray_menu_rebuild_worker fails: account files unreadable/corrupt while building the account submenu, TrayIcon lookup/registration fails (tray vanished), or menu item creation returns Err.","commonSituations":"Race at startup where the tray is destroyed/recreated, corrupted local account store producing menu-load errors, Linux tray host restarting mid-rebuild, or a poisoned internal worker state after a previous panic.","solutions":["Read the logged inner error string ({}) to find the failing step (menu build vs account load vs tray handle).","If account-related, repair/restore the local account files (or trigger the backup-restore flow) and re-run update_tray_menu.","Retry the menu update after a delay — update_tray_menu schedules a rebuild worker, so calling it again after the tray host is back usually succeeds.","Ensure create_tray_skeleton succeeded first; if the tray was never created, menu updates will fail until the app restarts."],"exampleFix":"// before\nif let Err(e) = modules::tray::update_tray_menu(&tray_app_handle) {\n    logger::log_error(&format!(\"[Tray] 后台更新托盘菜单失败: {}\", e));\n}\n// after\nif let Err(e) = modules::tray::update_tray_menu(&tray_app_handle) {\n    logger::log_error(&format!(\"[Tray] 后台更新托盘菜单失败: {}\", e));\n    let h = tray_app_handle.clone();\n    std::thread::spawn(move || {\n        std::thread::sleep(std::time::Duration::from_secs(2));\n        let _ = modules::tray::update_tray_menu(&h);\n    });\n}","handlingStrategy":"retry","validationCode":"// Retry only when the tray handle still exists; update_tray_menu schedules a rebuild worker\nlet _ = modules::tray::update_tray_menu(&handle); // Err(e) => schedule one retry after delay","typeGuard":null,"tryCatchPattern":"if let Err(e) = modules::tray::update_tray_menu(&h) {\n    logger::log_error(&format!(\"[Tray] 后台更新托盘菜单失败: {e}\"));\n    // retry once after short delay since the rebuild is worker-scheduled and transient failures are common\n}","preventionTips":["Retry menu updates with a short backoff — the tray host may restart mid-build.","Ensure create_tray_skeleton succeeded before attempting menu updates.","Validate/repair the account store before building account submenus so corrupt data can't break the rebuild.","Log the inner error string verbatim for diagnosis."],"tags":["tauri","tray-icon","background-thread","menu"],"backgroundTag":"tray-menu-rebuild-failed","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}