jlcodes99/cockpit-tools · warning

[Tray] 创建骨架托盘失败: {}

Error message

[Tray] 创建骨架托盘失败: {}

What it means

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.

Source

Thrown at src-tauri/src/lib.rs:484

                                "deep-link-current",
                            );
                        logger::log_info(&format!(
                            "[DeepLink] get_current 外部导入处理结果: handled={}",
                            handled
                        ));
                    }
                    Ok(None) => {
                        logger::log_info("[DeepLink] 启动时 get_current: empty");
                    }
                    Err(err) => {
                        logger::log_warn(&format!("[DeepLink] get_current 失败: {}", err));
                    }
                });
            }

            // 创建骨架托盘(无账号文件 I/O,秒出)
            if let Err(e) = modules::tray::create_tray_skeleton(app.handle()) {
                logger::log_error(&format!("[Tray] 创建骨架托盘失败: {}", e));
            }

            #[cfg(target_os = "macos")]
            {
                let tray_app_handle = app.handle().clone();
                std::thread::spawn(move || {
                    std::thread::sleep(std::time::Duration::from_millis(800));
                    if let Err(err) = modules::tray::apply_tray_icon_style(&tray_app_handle) {
                        logger::log_warn(&format!(
                            "[Tray] macOS 启动后重应用菜单栏图标样式失败: {}",
                            err
                        ));
                    }
                });
            }

            // 后台线程加载完整托盘菜单(含账号数据)
            let tray_app_handle = app.handle().clone();

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. 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).
  2. 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).
  3. Test with the official Tauri tray example on the same machine to confirm it is environment-level, not app-level.
  4. 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.

Example fix

// before
if let Err(e) = modules::tray::create_tray_skeleton(app.handle()) {
    logger::log_error(&format!("[Tray] 创建骨架托盘失败: {}", e));
}
// after
if let Err(e) = modules::tray::create_tray_skeleton(app.handle()) {
    logger::log_error(&format!("[Tray] 创建骨架托盘失败: {}", e));
    app.handle().plugin(tauri_plugin_notification::init()) // optional: notify user tray is unavailable
        .and_then(|_| Ok::<(), tauri::Error>(()))
        .ok();
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust: probe tray availability indirectly by checking the error and desktop env
fn tray_likely_available() -> bool {
    std::env::var("XDG_CURRENT_DESKTOP").is_ok() || std::env::var("GNOME_SHELL_SESSION_MODE").is_ok()
}

Try / catch

match modules::tray::create_tray_skeleton(app.handle()) {
    Ok(tray) => { /* keep tray alive */ }
    Err(e) => logger::log_error(&format!("[Tray] 创建骨架托盘失败: {e}")), // non-fatal: app continues
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/b8142e5a1835fd51. Report an issue: GitHub.