diff --git a/Changelog.md b/Changelog.md index 5910f457f..0287a845d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,8 @@ ### ✨ 新增功能 +- 快捷键操作通知操作结果 + ### 🚀 优化改进 - 优化 macOS 读取系统代理性能 diff --git a/crates/clash-verge-i18n/locales/ar.yml b/crates/clash-verge-i18n/locales/ar.yml index 5cea0d066..257ee47a4 100644 --- a/crates/clash-verge-i18n/locales/ar.yml +++ b/crates/clash-verge-i18n/locales/ar.yml @@ -8,10 +8,12 @@ notifications: body: تم التبديل إلى {mode}. systemProxyToggled: title: وكيل النظام - body: تم تحديث حالة وكيل النظام. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: وضع TUN - body: تم تحديث حالة وضع TUN. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: الوضع الخفيف body: تم الدخول إلى الوضع الخفيف. diff --git a/crates/clash-verge-i18n/locales/de.yml b/crates/clash-verge-i18n/locales/de.yml index 2ff5bd52c..c87d618dc 100644 --- a/crates/clash-verge-i18n/locales/de.yml +++ b/crates/clash-verge-i18n/locales/de.yml @@ -8,10 +8,12 @@ notifications: body: Auf {mode} umgeschaltet. systemProxyToggled: title: Systemproxy - body: Der Status des Systemproxys wurde aktualisiert. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: TUN-Modus - body: Der Status des TUN-Modus wurde aktualisiert. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Leichtmodus body: Leichtmodus aktiviert. diff --git a/crates/clash-verge-i18n/locales/en.yml b/crates/clash-verge-i18n/locales/en.yml index c9467a742..0e3e855b8 100644 --- a/crates/clash-verge-i18n/locales/en.yml +++ b/crates/clash-verge-i18n/locales/en.yml @@ -8,10 +8,12 @@ notifications: body: Switched to {mode}. systemProxyToggled: title: System Proxy - body: System proxy status has been updated. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: TUN Mode - body: TUN mode status has been updated. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Lightweight Mode body: Entered lightweight mode. diff --git a/crates/clash-verge-i18n/locales/es.yml b/crates/clash-verge-i18n/locales/es.yml index edda25ca5..52a251eec 100644 --- a/crates/clash-verge-i18n/locales/es.yml +++ b/crates/clash-verge-i18n/locales/es.yml @@ -8,10 +8,12 @@ notifications: body: Cambiado a {mode}. systemProxyToggled: title: Proxy del sistema - body: El estado del proxy del sistema se ha actualizado. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: Modo TUN - body: El estado del modo TUN se ha actualizado. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Modo ligero body: Se ha entrado en el modo ligero. diff --git a/crates/clash-verge-i18n/locales/fa.yml b/crates/clash-verge-i18n/locales/fa.yml index 82b7276b5..8e4954e5f 100644 --- a/crates/clash-verge-i18n/locales/fa.yml +++ b/crates/clash-verge-i18n/locales/fa.yml @@ -8,10 +8,12 @@ notifications: body: به {mode} تغییر کرد. systemProxyToggled: title: پروکسی سیستم - body: وضعیت پروکسی سیستم به‌روزرسانی شد. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: حالت TUN - body: وضعیت حالت TUN به‌روزرسانی شد. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: حالت سبک body: به حالت سبک وارد شد. diff --git a/crates/clash-verge-i18n/locales/id.yml b/crates/clash-verge-i18n/locales/id.yml index 694d1a8f9..3d206babf 100644 --- a/crates/clash-verge-i18n/locales/id.yml +++ b/crates/clash-verge-i18n/locales/id.yml @@ -8,10 +8,12 @@ notifications: body: Beralih ke {mode}. systemProxyToggled: title: Proksi Sistem - body: Status proksi sistem telah diperbarui. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: Mode TUN - body: Status mode TUN telah diperbarui. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Mode Ringan body: Masuk ke mode ringan. diff --git a/crates/clash-verge-i18n/locales/jp.yml b/crates/clash-verge-i18n/locales/jp.yml index 21c1b0c0e..6612d49fe 100644 --- a/crates/clash-verge-i18n/locales/jp.yml +++ b/crates/clash-verge-i18n/locales/jp.yml @@ -8,10 +8,12 @@ notifications: body: '{mode} に切り替えました。' systemProxyToggled: title: システムプロキシ - body: システムプロキシの状態が更新されました。 + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: TUN モード - body: TUN モードの状態が更新されました。 + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: 軽量モード body: 軽量モードに入りました。 diff --git a/crates/clash-verge-i18n/locales/ko.yml b/crates/clash-verge-i18n/locales/ko.yml index 01cb981c8..4d50b4a7a 100644 --- a/crates/clash-verge-i18n/locales/ko.yml +++ b/crates/clash-verge-i18n/locales/ko.yml @@ -8,10 +8,12 @@ notifications: body: '{mode}(으)로 전환되었습니다.' systemProxyToggled: title: 시스템 프록시 - body: 시스템 프록시 상태가 업데이트되었습니다. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: TUN 모드 - body: TUN 모드 상태가 업데이트되었습니다. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: 경량 모드 body: 경량 모드에 진입했습니다. diff --git a/crates/clash-verge-i18n/locales/ru.yml b/crates/clash-verge-i18n/locales/ru.yml index 10c7becb8..2c80376fe 100644 --- a/crates/clash-verge-i18n/locales/ru.yml +++ b/crates/clash-verge-i18n/locales/ru.yml @@ -8,10 +8,12 @@ notifications: body: Переключено на {mode}. systemProxyToggled: title: Системный прокси - body: Статус системного прокси обновлен. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: Режим TUN - body: Статус режима TUN обновлен. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Легкий режим body: Включен легкий режим. diff --git a/crates/clash-verge-i18n/locales/tr.yml b/crates/clash-verge-i18n/locales/tr.yml index 271c4b00d..da2cc2de6 100644 --- a/crates/clash-verge-i18n/locales/tr.yml +++ b/crates/clash-verge-i18n/locales/tr.yml @@ -8,10 +8,12 @@ notifications: body: '{mode} moduna geçildi.' systemProxyToggled: title: Sistem Vekil'i - body: Sistem vekil'i durumu güncellendi. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: TUN Modu - body: TUN modu durumu güncellendi. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Hafif Mod body: Hafif moda geçildi. diff --git a/crates/clash-verge-i18n/locales/tt.yml b/crates/clash-verge-i18n/locales/tt.yml index 83e7d2946..aeafd27ee 100644 --- a/crates/clash-verge-i18n/locales/tt.yml +++ b/crates/clash-verge-i18n/locales/tt.yml @@ -8,10 +8,12 @@ notifications: body: '{mode} режимына күчтел.' systemProxyToggled: title: Системалы прокси - body: Системалы прокси хәле яңартылды. + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: TUN режимы - body: TUN режимы хәле яңартылды. + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: Җиңел режим body: Җиңел режимга күчелде. diff --git a/crates/clash-verge-i18n/locales/zh.yml b/crates/clash-verge-i18n/locales/zh.yml index 59d2aa512..e5148bdf7 100644 --- a/crates/clash-verge-i18n/locales/zh.yml +++ b/crates/clash-verge-i18n/locales/zh.yml @@ -8,10 +8,12 @@ notifications: body: 已切换至 {mode}。 systemProxyToggled: title: 系统代理 - body: 系统代理状态已更新。 + 'on': 系统代理已启用。 + 'off': 系统代理已禁用。 tunModeToggled: title: TUN 模式 - body: TUN 模式状态已更新。 + 'on': TUN 模式已开启。 + 'off': TUN 模式已关闭。 lightweightModeEntered: title: 轻量模式 body: 已进入轻量模式。 diff --git a/crates/clash-verge-i18n/locales/zhtw.yml b/crates/clash-verge-i18n/locales/zhtw.yml index 1c6cfd0c1..74e06f7a1 100644 --- a/crates/clash-verge-i18n/locales/zhtw.yml +++ b/crates/clash-verge-i18n/locales/zhtw.yml @@ -8,10 +8,12 @@ notifications: body: 已切換至 {mode}。 systemProxyToggled: title: 系統代理 - body: 系統代理狀態已更新。 + 'on': System proxy has been enabled. + 'off': System proxy has been disabled. tunModeToggled: title: 虛擬網路介面卡模式 - body: 已更新虛擬網路介面卡模式狀態。 + 'on': TUN mode has been enabled. + 'off': TUN mode has been disabled. lightweightModeEntered: title: 輕量模式 body: 已進入輕量模式。 diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs index a34fda63c..b88618d7c 100755 --- a/src-tauri/src/core/hotkey.rs +++ b/src-tauri/src/core/hotkey.rs @@ -135,14 +135,14 @@ impl Hotkey { } HotkeyFunction::ToggleSystemProxy => { AsyncHandler::spawn(async move || { - feat::toggle_system_proxy().await; - notify_event(NotificationEvent::SystemProxyToggled).await; + let is_proxy_enabled = feat::toggle_system_proxy().await; + notify_event(NotificationEvent::SystemProxyToggled(is_proxy_enabled)).await; }); } HotkeyFunction::ToggleTunMode => { AsyncHandler::spawn(async move || { - feat::toggle_tun_mode(None).await; - notify_event(NotificationEvent::TunModeToggled).await; + let is_tun_enable = feat::toggle_tun_mode(None).await; + notify_event(NotificationEvent::TunModeToggled(is_tun_enable)).await; }); } HotkeyFunction::EntryLightweightMode => { diff --git a/src-tauri/src/feat/proxy.rs b/src-tauri/src/feat/proxy.rs index 3b211d9e2..48a6e419d 100644 --- a/src-tauri/src/feat/proxy.rs +++ b/src-tauri/src/feat/proxy.rs @@ -7,7 +7,7 @@ use std::env; use tauri_plugin_clipboard_manager::ClipboardExt as _; /// Toggle system proxy on/off -pub async fn toggle_system_proxy() { +pub async fn toggle_system_proxy() -> bool { let verge = Config::verge().await; let enable = verge.latest_arc().enable_system_proxy.unwrap_or(false); let auto_close_connection = verge.latest_arc().auto_close_connection.unwrap_or(false); @@ -20,9 +20,10 @@ pub async fn toggle_system_proxy() { logging!(error, Type::ProxyMode, "Failed to close all connections: {err}"); } + let enable = !enable; let patch_result = super::patch_verge( &IVerge { - enable_system_proxy: Some(!enable), + enable_system_proxy: Some(enable), ..IVerge::default() }, false, @@ -33,24 +34,33 @@ pub async fn toggle_system_proxy() { Ok(_) => handle::Handle::refresh_verge(), Err(err) => logging!(error, Type::ProxyMode, "{err}"), } + + enable } /// Toggle TUN mode on/off -pub async fn toggle_tun_mode(not_save_file: Option) { - let enable = Config::verge().await.latest_arc().enable_tun_mode; - let enable = enable.unwrap_or(false); +/// Returns the updated toggle state +pub async fn toggle_tun_mode(not_save_file: Option) -> bool { + let current = Config::verge().await.latest_arc().enable_tun_mode.unwrap_or(false); + let enable = !current; match super::patch_verge( &IVerge { - enable_tun_mode: Some(!enable), + enable_tun_mode: Some(enable), ..IVerge::default() }, not_save_file.unwrap_or(false), ) .await { - Ok(_) => handle::Handle::refresh_verge(), - Err(err) => logging!(error, Type::ProxyMode, "{err}"), + Ok(_) => { + handle::Handle::refresh_verge(); + enable + } + Err(err) => { + logging!(error, Type::ProxyMode, "{err}"); + current + } } } diff --git a/src-tauri/src/utils/notification.rs b/src-tauri/src/utils/notification.rs index 33ae195c5..1bafcb0d6 100644 --- a/src-tauri/src/utils/notification.rs +++ b/src-tauri/src/utils/notification.rs @@ -9,8 +9,8 @@ pub enum NotificationEvent<'a> { ClashModeChanged { mode: &'a str, }, - SystemProxyToggled, - TunModeToggled, + SystemProxyToggled(bool), + TunModeToggled(bool), LightweightModeEntered, ProfilesReactivated, AppQuit, @@ -37,14 +37,25 @@ pub async fn notify_event<'a>(event: NotificationEvent<'a>) { .into(); notify(title, body); } - NotificationEvent::SystemProxyToggled => { + NotificationEvent::SystemProxyToggled(enabled) => { let title = clash_verge_i18n::t!("notifications.systemProxyToggled.title"); - let body = clash_verge_i18n::t!("notifications.systemProxyToggled.body"); + let key = if enabled { + "notifications.systemProxyToggled.on" + } else { + "notifications.systemProxyToggled.off" + }; + + let body = clash_verge_i18n::t!(key); notify(title, body); } - NotificationEvent::TunModeToggled => { + NotificationEvent::TunModeToggled(enabled) => { let title = clash_verge_i18n::t!("notifications.tunModeToggled.title"); - let body = clash_verge_i18n::t!("notifications.tunModeToggled.body"); + let key = if enabled { + "notifications.tunModeToggled.on" + } else { + "notifications.tunModeToggled.off" + }; + let body = clash_verge_i18n::t!(key); notify(title, body); } NotificationEvent::LightweightModeEntered => {