From 93e25da08044ea06189a72be2600a272028f8a4f Mon Sep 17 00:00:00 2001 From: David Chalifoux Date: Fri, 19 Apr 2024 21:33:16 -0500 Subject: [PATCH 1/2] Add "show" menu item to fix Linux support --- src-tauri/src/main.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 36d24be..e559a65 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,7 +2,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use mdns_sd::{ServiceDaemon, ServiceEvent}; -use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu}; +use tauri::{ + CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, +}; use tauri_plugin_positioner::{Position, WindowExt}; #[derive(Clone, Debug, serde::Serialize)] @@ -65,9 +67,14 @@ async fn scan() -> Vec { } fn main() { - let quit = CustomMenuItem::new("quit".to_string(), "Quit"); + let quit_button = CustomMenuItem::new("quit".to_string(), "Quit"); + let show_hide_button = CustomMenuItem::new("show".to_string(), "Show"); + + let tray_menu = SystemTrayMenu::new() + .add_item(show_hide_button) + .add_native_item(SystemTrayMenuItem::Separator) + .add_item(quit_button); - let tray_menu = SystemTrayMenu::new().add_item(quit); let system_tray = SystemTray::new().with_menu(tray_menu); tauri::Builder::default() @@ -91,7 +98,6 @@ fn main() { tauri::WindowEvent::Focused(focused) => { // hide window whenever it loses focus if !focused { - println!("Lost focus, hiding"); event.window().hide().unwrap(); } } @@ -103,10 +109,18 @@ fn main() { match event { SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { "quit" => app.exit(0), + "show" => { + let window = app.get_window("main").unwrap(); + + let _ = window.move_window(Position::TrayCenter); + + window.show().unwrap(); + window.set_focus().unwrap(); + } _ => {} }, + SystemTrayEvent::LeftClick { .. } => { - println!("Left click on icon"); let window = app.get_window("main").unwrap(); let _ = window.move_window(Position::TrayCenter); @@ -114,12 +128,9 @@ fn main() { let is_visible = window.is_visible().unwrap_or_default(); if !is_visible { - println!("Showing"); - window.show().unwrap(); window.set_focus().unwrap(); } else { - println!("Hiding"); window.hide().unwrap(); } } From 942b61e9a41f0382b59fb64b075acfb0baa6301f Mon Sep 17 00:00:00 2001 From: David Chalifoux Date: Fri, 19 Apr 2024 21:34:35 -0500 Subject: [PATCH 2/2] Version bump --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 51997e7..75f9f9d 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -7,7 +7,7 @@ }, "package": { "productName": "Keylight Commander", - "version": "0.0.10" + "version": "0.0.11" }, "tauri": { "macOSPrivateApi": true,