feat: show detailed results in hotkey notifications (#6639)

* feat: show detailed results in hotkey notifications

* fix: Japanese locale appears to have a truncated translation key label

* fix: variable naming

* Update documentation to English

* Remove unnecessary mut

* feat: enhance system proxy notifications with toggle state

* chore: update changelog to include new shortcut notification feature

* fix: remove unnecessary quotes from system proxy toggle messages in localization files

* fix: tun mode toggled hotkey notifications

* fix: correct toggle_tun_mode logic to handle current state and errors

---------

Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
This commit is contained in:
wysha-object
2026-03-30 17:06:45 +00:00
committed by GitHub
co-authored by Tunglies
parent 071f92635f
commit b7230967b4
17 changed files with 93 additions and 44 deletions
+4 -4
View File
@@ -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 => {
+18 -8
View File
@@ -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<bool>) {
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>) -> 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
}
}
}
+17 -6
View File
@@ -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 => {