1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-26 04:02:46 +01:00
client/src-tauri/src/tray.rs

42 lines
1.3 KiB
Rust
Raw Normal View History

2023-12-20 15:49:25 +01:00
use tauri::{
menu::{Menu, MenuItem},
2024-06-17 20:47:54 +02:00
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
2023-12-20 15:49:25 +01:00
Manager, Runtime,
};
pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
2024-02-28 04:33:54 +01:00
let branding = MenuItem::with_id(app, "name", "Spacebar", false, None::<String>)?;
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<String>)?;
2023-12-20 15:49:25 +01:00
let menu1 = Menu::with_items(app, &[&branding, &quit_i])?;
let _ = TrayIconBuilder::with_id("main")
.tooltip("Spacebar")
.icon(app.default_window_icon().unwrap().clone())
.menu(&menu1)
.menu_on_left_click(false)
.on_menu_event(move |app, event| match event.id.as_ref() {
"quit" => {
app.exit(0);
}
_ => {}
})
.on_tray_icon_event(|tray, event| {
2024-06-17 20:47:54 +02:00
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
2023-12-20 15:49:25 +01:00
let app = tray.app_handle();
2024-02-28 04:33:54 +01:00
if let Some(window) = app.get_webview_window("main") {
2023-12-20 15:49:25 +01:00
let _ = window.show();
let _ = window.set_focus();
}
}
})
.build(app);
Ok(())
}