Replies: 1 comment
-
you can do something like this pub fn create_system_tray() -> SystemTray {
let quit = CustomMenuItem::new("quit".to_string(), "Quit Program");
let hide = CustomMenuItem::new("hide".to_string(), "Close to tray");
let tray_menu = SystemTrayMenu::new()
.add_item(hide)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(quit);
SystemTray::new().with_menu(tray_menu)
}
pub fn on_system_tray_event(app: &AppHandle<Wry>, event: SystemTrayEvent) {
match event {
SystemTrayEvent::DoubleClick { position: _ , size: _, .. } => {
let window = app.get_window("main").unwrap();
window.unminimize().unwrap();
window.show().unwrap();
window.set_focus().unwrap();
},
SystemTrayEvent::MenuItemClick { id, ..} => {
match id.as_str() {
"quit" => {
app.get_window("main").unwrap().hide().unwrap();
std::process::exit(0);
}
"hide" => {
app.get_window("main").unwrap().hide().unwrap();
}
_ => {}
}
}
_ => {}
}
}
// setup you tray
tauri::Builder::default()
.system_tray(create_system_tray())
.on_system_tray_event(on_system_tray_event)
.run(tauri::generate_context!())
.expect("error while running tauri application"); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I am new to tauri and trying out tray app.
As documented, I was able to close the frontend with backend running in background using :
api.prevent_exit()
Now, I would like to bring back frontend window by clicking on tray icon. How could that be accomplished?
Thanks in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions