feat: add tray menu indicator for lightweight mode #3386

This commit is contained in:
Tunglies
2025-04-21 04:33:56 +08:00
parent 0646fa96a6
commit 824ad9fa29
3 changed files with 16 additions and 3 deletions

View File

@@ -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<tauri::menu::Menu<Wry>> {
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();

View File

@@ -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() {