unistore-tray

Crates.iounistore-tray
lib.rsunistore-tray
version0.1.0
created_at2026-01-20 11:26:45.482908+00
updated_at2026-01-20 11:26:45.482908+00
descriptionSystem tray capability for UniStore - cross-platform tray icon, menu, and notifications
homepagehttps://github.com/yangbo1317/unistore
repositoryhttps://github.com/yangbo1317/unistore
max_upload_size
id2056398
size130,178
(yangbo1317)

documentation

README

unistore-tray

跨平台系统托盘能力 - UniStore 能力生态的一部分。

功能特性

  • 跨平台: 支持 Windows/macOS/Linux
  • 统一 API: 屏蔽平台差异,提供一致的接口
  • 异步友好: 与 tokio 运行时无缝集成
  • 事件驱动: 通过 broadcast channel 订阅托盘事件
  • 可扩展菜单: 灵活的菜单构建器 API

快速开始

use unistore_tray::{SystemTray, TrayConfig, TrayEvent, MenuBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 创建托盘配置
    let config = TrayConfig::builder()
        .tooltip("My App v1.0")
        .build();

    // 创建系统托盘
    let tray = SystemTray::new(config)?;

    // 设置菜单
    let menu = MenuBuilder::new()
        .item("open", "打开主窗口")
        .separator()
        .item("exit", "退出")
        .build();
    tray.set_menu(menu)?;

    // 订阅事件
    let mut rx = tray.subscribe();
    
    loop {
        match rx.recv().await {
            Ok(TrayEvent::MenuItemClicked(id)) => {
                match id.as_str() {
                    "exit" => break,
                    "open" => println!("打开窗口"),
                    _ => {}
                }
            }
            Ok(TrayEvent::DoubleClick) => {
                println!("双击托盘图标");
            }
            _ => {}
        }
    }

    Ok(())
}

平台支持

功能 Windows macOS Linux
托盘图标
右键菜单
提示文字
左键单击 ⚠️ ⚠️
双击
气泡通知 ⚠️ ⚠️

⚠️ 表示行为可能与 Windows 不同 ❌ 表示平台不支持

Feature Flags

Feature 说明
default 基础托盘功能
notifications 气泡通知支持
full 所有功能

License

Licensed under either of:

at your option.

Commit count: 0

cargo fmt