diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 961280e..f0c1969 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -23,6 +23,9 @@ pub struct IVerge { /// maybe be able to set the alpha pub theme_blur: Option, + /// tray click event + pub tray_event: Option, + /// enable traffic graph default is true pub traffic_graph: Option, @@ -166,6 +169,7 @@ impl IVerge { patch!(language); patch!(theme_mode); patch!(theme_blur); + patch!(tray_event); patch!(traffic_graph); patch!(enable_memory_usage); diff --git a/src-tauri/src/core/tray.rs b/src-tauri/src/core/tray.rs index 01a5045..da0d890 100644 --- a/src-tauri/src/core/tray.rs +++ b/src-tauri/src/core/tray.rs @@ -145,9 +145,20 @@ impl Tray { Ok(()) } - + pub fn on_left_click(app_handle: &AppHandle) { + let tray_event = { Config::verge().latest().tray_event.clone() }; + let tray_event = tray_event.unwrap_or("main_window".into()); + println!("{tray_event}"); + match tray_event.as_str() { + "system_proxy" => feat::toggle_system_proxy(), + "tun_mode" => feat::toggle_tun_mode(), + _ => resolve::create_window(app_handle), + } + } pub fn on_system_tray_event(app_handle: &AppHandle, event: SystemTrayEvent) { match event { + #[cfg(not(target_os = "linux"))] + SystemTrayEvent::LeftClick { .. } => Tray::on_left_click(app_handle), SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { mode @ ("rule_mode" | "global_mode" | "direct_mode" | "script_mode") => { let mode = &mode[0..mode.len() - 5]; @@ -177,10 +188,6 @@ impl Tray { } _ => {} }, - #[cfg(target_os = "windows")] - SystemTrayEvent::LeftClick { .. } => { - resolve::create_window(app_handle); - } _ => {} } } diff --git a/src/components/setting/setting-verge.tsx b/src/components/setting/setting-verge.tsx index d54094d..b0507f3 100644 --- a/src/components/setting/setting-verge.tsx +++ b/src/components/setting/setting-verge.tsx @@ -29,8 +29,7 @@ const SettingVerge = ({ onError }: Props) => { const { t } = useTranslation(); const { verge, patchVerge, mutateVerge } = useVerge(); - const { theme_mode, language } = verge ?? {}; - + const { theme_mode, language, tray_event } = verge ?? {}; const configRef = useRef(null); const hotkeyRef = useRef(null); const miscRef = useRef(null); @@ -91,6 +90,24 @@ const SettingVerge = ({ onError }: Props) => { + {OS !== "linux" && ( + + e.target.value} + onChange={(e) => onChangeData({ tray_event: e })} + onGuard={(e) => patchVerge({ tray_event: e })} + > + + + + )} +