| Crates.io | unistore-tray |
| lib.rs | unistore-tray |
| version | 0.1.0 |
| created_at | 2026-01-20 11:26:45.482908+00 |
| updated_at | 2026-01-20 11:26:45.482908+00 |
| description | System tray capability for UniStore - cross-platform tray icon, menu, and notifications |
| homepage | https://github.com/yangbo1317/unistore |
| repository | https://github.com/yangbo1317/unistore |
| max_upload_size | |
| id | 2056398 |
| size | 130,178 |
跨平台系统托盘能力 - UniStore 能力生态的一部分。
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 | 说明 |
|---|---|
default |
基础托盘功能 |
notifications |
气泡通知支持 |
full |
所有功能 |
Licensed under either of:
at your option.