Tauri 配置系统托盘上下文菜单
或者,您可以添加一个上下文菜单,该菜单在右键单击托盘图标时可见。导入 ,并键入:
SystemTrayMenu
SystemTrayMenuItem
CustomMenuItem
use tauri::{CustomMenuItem, SystemTrayMenu, SystemTrayMenuItem};
创建 :SystemTrayMenu
// 这里 `"quit".to_string()` 定义菜单项 ID,第二个参数是菜单项标签。
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let hide = CustomMenuItem::new("hide".to_string(), "Hide");
let tray_menu = SystemTrayMenu::new()
.add_item(quit)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(hide);
将托盘菜单添加到实例:SystemTray
let tray = SystemTray::new().with_menu(tray_menu);