basic system tray functionality

This commit is contained in:
Joseph Montanaro committed 2022-12-21 14:49:01 -08:00
1 parent 50f0985f4f
commit 5ffa55c03c
9 files changed
+136 -14

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
use tauri::{
AppHandle,
Manager,
SystemTray,
SystemTrayEvent,
SystemTrayMenu,
CustomMenuItem,
};
pub fn create() -> SystemTray {
let show = CustomMenuItem::new("show".to_string(), "Show");
let quit = CustomMenuItem::new("exit".to_string(), "Exit");
let menu = SystemTrayMenu::new()
.add_item(show)
.add_item(quit);
SystemTray::new().with_menu(menu)
}
pub fn handle_event(app: &AppHandle, event: SystemTrayEvent) {
match event {
SystemTrayEvent::MenuItemClick{ id, .. } => {
match id.as_str() {
"exit" => app.exit(0),
"show" => {
let _ = app.get_window("main").map(|w| w.show());
}
_ => (),
}
}
_ => (),
}
}