From 824ad9fa29edbd91383b414c541de462afefe024 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Mon, 21 Apr 2025 04:33:56 +0800 Subject: [PATCH] feat: add tray menu indicator for lightweight mode #3386 --- UPDATELOG.md | 2 ++ src-tauri/src/core/tray/mod.rs | 11 +++++++++-- src-tauri/src/module/lightweight.rs | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/UPDATELOG.md b/UPDATELOG.md index 4470650a..340b2ad2 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -14,10 +14,12 @@ - 静默启动异常窗口创建和关闭流程 - 使用 tauri window-state 管理窗口,尝试解决各种窗口异常 - Windows 错误的全局快捷键 'Ctrl+Q' 注册 + - Vless URL 解码时网络类型错误 #### 新增了: - 允许代理主机地址设置为非 127.0.0.1 对 WSL 代理友好 - 关闭系统代理时关闭已建立的网络连接 + - 托盘显示当前轻量模式状态 #### 优化了: - 系统代理 Bypass 设置 diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 37d813e1..f2639af0 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -6,7 +6,10 @@ use crate::{ cmd, config::Config, feat, - module::{lightweight::entry_lightweight_mode, mihomo::Rate}, + module::{ + lightweight::{entry_lightweight_mode, is_in_lightweight_mode}, + mihomo::Rate, + }, process::AsyncHandler, resolve, utils::{dirs::find_target_icons, i18n::t, logging::Type, resolve::VERSION}, @@ -254,6 +257,7 @@ impl Tray { .data() .all_profile_uid_and_name() .unwrap_or_default(); + let is_lightweight_mode = is_in_lightweight_mode(); let tray = app_handle.tray_by_id("main").unwrap(); let _ = tray.set_menu(Some(create_tray_menu( @@ -262,6 +266,7 @@ impl Tray { *system_proxy, *tun_mode, profile_uid_and_name, + is_lightweight_mode, )?)); Ok(()) } @@ -456,6 +461,7 @@ fn create_tray_menu( system_proxy_enabled: bool, tun_mode_enabled: bool, profile_uid_and_name: Vec<(String, String)>, + is_lightweight_mode: bool, ) -> Result> { let mode = mode.unwrap_or(""); let version = VERSION.get().unwrap(); @@ -566,11 +572,12 @@ fn create_tray_menu( ) .unwrap(); - let lighteweight_mode = &MenuItem::with_id( + let lighteweight_mode = &CheckMenuItem::with_id( app_handle, "entry_lightweight_mode", t("LightWeight Mode"), true, + is_lightweight_mode, hotkeys.get("entry_lightweight_mode").map(|s| s.as_str()), ) .unwrap(); diff --git a/src-tauri/src/module/lightweight.rs b/src-tauri/src/module/lightweight.rs index 17849275..40d3ff74 100644 --- a/src-tauri/src/module/lightweight.rs +++ b/src-tauri/src/module/lightweight.rs @@ -1,6 +1,6 @@ use crate::{ config::Config, - core::{handle, timer::Timer}, + core::{handle, timer::Timer, tray::Tray}, log_err, logging, logging_error, utils::logging::Type, AppHandleManager, @@ -64,6 +64,8 @@ pub fn entry_lightweight_mode() { // 标记已进入轻量模式 set_lightweight_mode(true); let _ = cancel_light_weight_timer(); + + logging_error!(Type::Tray, true, Tray::global().update_menu()); } // 从轻量模式恢复 @@ -74,6 +76,8 @@ pub fn exit_lightweight_mode() { // 重置UI就绪状态 crate::utils::resolve::reset_ui_ready(); + + logging_error!(Type::Tray, true, Tray::global().update_menu()); } pub fn add_light_weight_timer() {