Skip to content

Commit

Permalink
feat(tauri): add closing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Oct 1, 2023
1 parent 09e15be commit a7e8548
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ static HAS_DECORATIONS: Mutex<bool> = Mutex::new(true);
static IS_COMPACT: Mutex<bool> = Mutex::new(false);

#[tauri::command]
fn set_minimize<R: Runtime>(minimize_to_tray: bool, _window: tauri::Window<R>) {
fn set_minimize<R: Runtime>(minimize_to_tray: bool, window: tauri::Window<R>) {
println!("Minimize! {}", minimize_to_tray.to_string().as_str());
if minimize_to_tray {
window.hide().unwrap();
} else {
window.close().unwrap();
}
}

#[tauri::command]
fn set_close<R: Runtime>(close_to_tray: bool, _window: tauri::Window<R>) {
fn set_close<R: Runtime>(close_to_tray: bool, window: tauri::Window<R>) {
println!("set_close! {}", close_to_tray);
if close_to_tray {
window.hide().unwrap();
} else {
window.close().unwrap();
}
}

#[tauri::command]
Expand Down Expand Up @@ -203,6 +213,11 @@ impl PomatezExtras for Builder<Wry> {
.add_item(quit);
let tray = SystemTray::new().with_menu(tray_menu);
self.system_tray(tray).on_system_tray_event(|app, event| match event {
SystemTrayEvent::LeftClick { .. } => {
let window = app.get_window("main").unwrap();
window.show().unwrap();
window.set_focus().unwrap();
}
SystemTrayEvent::MenuItemClick { id, .. } => {
match id.as_str() {
"show" => {
Expand Down

0 comments on commit a7e8548

Please sign in to comment.