From e92074e5868dcc8c3bd62087b0a5555c38444a1f Mon Sep 17 00:00:00 2001 From: huzibaca Date: Sat, 21 Sep 2024 15:38:14 +0800 Subject: [PATCH] chore: try adjusting the triggering of the tray mouse button --- src-tauri/src/core/tray.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src-tauri/src/core/tray.rs b/src-tauri/src/core/tray.rs index 41bee5b..2c6817a 100644 --- a/src-tauri/src/core/tray.rs +++ b/src-tauri/src/core/tray.rs @@ -22,9 +22,29 @@ pub struct Tray {} impl Tray { pub fn update_systray(app_handle: &AppHandle) -> Result<()> { let tray = app_handle.tray_by_id("main").unwrap(); + #[cfg(not(target_os = "macos"))] + let _ = tray.set_show_menu_on_left_click(false); + tray.on_tray_icon_event(|tray, event| { let tray_event = { Config::verge().latest().tray_event.clone() }; let tray_event: String = tray_event.unwrap_or("main_window".into()); + + #[cfg(target_os = "macos")] + if let TrayIconEvent::Click { + button: MouseButton::Right, + .. + } = event + { + let app = tray.app_handle(); + match tray_event.as_str() { + "system_proxy" => feat::toggle_system_proxy(), + "tun_mode" => feat::toggle_tun_mode(), + "main_window" => resolve::create_window(app), + _ => {} + } + } + + #[cfg(not(target_os = "macos"))] if let TrayIconEvent::Click { button: MouseButton::Left, ..