{"record":{"id":"b8142e5a1835fd51","repo":"jlcodes99/cockpit-tools","slug":"tray","errorCode":null,"errorMessage":"[Tray] 创建骨架托盘失败: {}","messagePattern":"\\[Tray\\] 创建骨架托盘失败: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src-tauri/src/lib.rs","lineNumber":484,"sourceCode":"                                \"deep-link-current\",\n                            );\n                        logger::log_info(&format!(\n                            \"[DeepLink] get_current 外部导入处理结果: handled={}\",\n                            handled\n                        ));\n                    }\n                    Ok(None) => {\n                        logger::log_info(\"[DeepLink] 启动时 get_current: empty\");\n                    }\n                    Err(err) => {\n                        logger::log_warn(&format!(\"[DeepLink] get_current 失败: {}\", err));\n                    }\n                });\n            }\n\n            // 创建骨架托盘（无账号文件 I/O，秒出）\n            if let Err(e) = modules::tray::create_tray_skeleton(app.handle()) {\n                logger::log_error(&format!(\"[Tray] 创建骨架托盘失败: {}\", e));\n            }\n\n            #[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();","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/lib.rs#L466-L502","documentation":"During app setup in run(), the code calls modules::tray::create_tray_skeleton(app.handle()) to build a minimal tray icon without account-file I/O. If that returns Err (a tauri::Error from TrayIconBuilder/MenuItem construction or tray registration), the error is logged with this message and startup continues without a tray. It is thrown by the library because a tray icon could not be created, typically due to a desktop-environment/system-tray API failure.","triggerScenarios":"TrayIconBuilder::build() fails (no system tray available), MenuItem::with_id gets an invalid text/id, default_window_icon() is None and icon setup fails, or on macOS the status-item identity configuration fails.","commonSituations":"Running on Linux desktops without a StatusNotifier/AppIndicator tray host (e.g. minimal WM setups like plain i3/sway without waybar), headless/CI environments, or sessions where the tray daemon died.","solutions":["Verify a system tray host (StatusNotifier/appindicator) is running on the desktop session; install/enable one (e.g. gnome-shell extension AppIndicator, waybar with tray module).","Check the logged inner error ({}) to identify whether it is icon, menu, or tray registration related; fix the specific cause (e.g. bundle a default window icon via tauri.conf.json).","Test with the official Tauri tray example on the same machine to confirm it is environment-level, not app-level.","Treat as non-fatal by design: the app continues without a tray; if a tray is required, surface a user-visible notification instead of only logging."],"exampleFix":"// before\nif let Err(e) = modules::tray::create_tray_skeleton(app.handle()) {\n    logger::log_error(&format!(\"[Tray] 创建骨架托盘失败: {}\", e));\n}\n// after\nif let Err(e) = modules::tray::create_tray_skeleton(app.handle()) {\n    logger::log_error(&format!(\"[Tray] 创建骨架托盘失败: {}\", e));\n    app.handle().plugin(tauri_plugin_notification::init()) // optional: notify user tray is unavailable\n        .and_then(|_| Ok::<(), tauri::Error>(()))\n        .ok();\n}","handlingStrategy":"try-catch","validationCode":"// Rust: probe tray availability indirectly by checking the error and desktop env\nfn tray_likely_available() -> bool {\n    std::env::var(\"XDG_CURRENT_DESKTOP\").is_ok() || std::env::var(\"GNOME_SHELL_SESSION_MODE\").is_ok()\n}","typeGuard":null,"tryCatchPattern":"match modules::tray::create_tray_skeleton(app.handle()) {\n    Ok(tray) => { /* keep tray alive */ }\n    Err(e) => logger::log_error(&format!(\"[Tray] 创建骨架托盘失败: {e}\")), // non-fatal: app continues\n}","preventionTips":["Run the app only in desktop sessions with a system-tray host (StatusNotifier/AppIndicator on Linux).","Log the full inner error, not just a marker, so the failing tray step is identifiable.","Keep the tray failure non-fatal so a missing tray never blocks app startup.","Bundle a default window icon so icon construction cannot fail."],"tags":["tauri","tray-icon","desktop-environment","linux"],"backgroundTag":"tray-icon-unavailable","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"}