37 lines
809 B
Rust
37 lines
809 B
Rust
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());
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|