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-31 01:06:45 +08:00 committed by GitHub
parent 071f92635f
commit b7230967b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 93 additions and 44 deletions

View File

@ -11,6 +11,8 @@
### ✨ 新增功能
- 快捷键操作通知操作结果
### 🚀 优化改进
- 优化 macOS 读取系统代理性能

View File

@ -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: تم الدخول إلى الوضع الخفيف.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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: به حالت سبک وارد شد.

View File

@ -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.

View File

@ -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: 軽量モードに入りました。

View File

@ -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: 경량 모드에 진입했습니다.

View File

@ -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: Включен легкий режим.

View File

@ -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.

View File

@ -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: Җиңел режимга күчелде.

View File

@ -8,10 +8,12 @@ notifications:
body: 已切换至 {mode}。
systemProxyToggled:
title: 系统代理
body: 系统代理状态已更新。
'on': 系统代理已启用。
'off': 系统代理已禁用。
tunModeToggled:
title: TUN 模式
body: TUN 模式状态已更新。
'on': TUN 模式已开启。
'off': TUN 模式已关闭。
lightweightModeEntered:
title: 轻量模式
body: 已进入轻量模式。

View File

@ -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: 已進入輕量模式。

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 => {

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
}
}
}

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 => {