From 2e38404434340882c8cac67a555e78ea86a92e69 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Thu, 20 Mar 2025 23:17:37 +0800 Subject: [PATCH] fix: homepage entry lightweight mode exiting Macos tray icon fix: lightweight mode better handling and logging logic --- UPDATELOG.md | 1 + src-tauri/src/cmd/lighteweight.rs | 2 +- src-tauri/src/module/lightweight.rs | 14 ++++------ .../setting/mods/lite-mode-viewer.tsx | 26 ++++++++++++------- src/pages/home.tsx | 12 +++++++-- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/UPDATELOG.md b/UPDATELOG.md index 1258f603..68f5725d 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -7,6 +7,7 @@ #### 修复 1. **首页** - 修复 Direct 模式首页无法渲染。 + - 修复 首页启用轻量模式导致 ClashVergeRev 从托盘退出。 2. **系统** - 修复 MacOS 无法使用快捷键粘贴/选择/复制订阅地址。 diff --git a/src-tauri/src/cmd/lighteweight.rs b/src-tauri/src/cmd/lighteweight.rs index 9a2c2755..ac71ad37 100644 --- a/src-tauri/src/cmd/lighteweight.rs +++ b/src-tauri/src/cmd/lighteweight.rs @@ -6,4 +6,4 @@ use super::CmdResult; pub async fn entry_lightweight_mode() -> CmdResult { lightweight::entry_lightweight_mode(); Ok(()) -} \ No newline at end of file +} diff --git a/src-tauri/src/module/lightweight.rs b/src-tauri/src/module/lightweight.rs index 0f5bca5e..a853d611 100644 --- a/src-tauri/src/module/lightweight.rs +++ b/src-tauri/src/module/lightweight.rs @@ -25,18 +25,15 @@ pub fn disable_auto_light_weight_mode() { } pub fn entry_lightweight_mode() { - println!("尝试进入轻量模式。motherfucker"); - if let Some(window) = handle::Handle::global().get_window() { - log_err!(window.close()); - } - if let Some(window) = handle::Handle::global().get_window() { if let Some(webview) = window.get_webview_window("main") { - log_err!(webview.destroy()); + let _ = webview.destroy(); + let _ = window.hide(); println!("[lightweight_mode] 轻量模式已开启"); log::info!(target: "app", "[lightweight_mode] 轻量模式已开启"); } } + let _ = cancel_light_weight_timer(); } fn setup_window_close_listener() -> u32 { @@ -132,10 +129,9 @@ fn cancel_light_weight_timer() -> Result<()> { delay_timer .remove_task(task.task_id) .context("failed to remove light weight timer task")?; + println!("[lightweight_mode] 轻量模式计时器已取消"); + log::info!(target: "app", "[lightweight_mode] 轻量模式计时器已取消"); } - println!("[lightweight_mode] 轻量模式计时器已取消"); - log::info!(target: "app", "[lightweight_mode] 轻量模式计时器已取消"); - Ok(()) } diff --git a/src/components/setting/mods/lite-mode-viewer.tsx b/src/components/setting/mods/lite-mode-viewer.tsx index 4241425b..a1e20a52 100644 --- a/src/components/setting/mods/lite-mode-viewer.tsx +++ b/src/components/setting/mods/lite-mode-viewer.tsx @@ -66,9 +66,9 @@ export const LiteModeViewer = forwardRef((props, ref) => { sx={{ cursor: "pointer", color: "primary.main", - "&:hover": { textDecoration: "underline" } + "&:hover": { textDecoration: "underline" }, }} - onClick={() => entry_lightweight_mode()} + onClick={async () => await entry_lightweight_mode()} > {t("Enable")} @@ -115,17 +115,25 @@ export const LiteModeViewer = forwardRef((props, ref) => { slotProps={{ input: { endAdornment: ( - {t("mins")} - ) - } + + {t("mins")} + + ), + }, }} /> - - {t("When closing the window, LightWeight Mode will be automatically activated after _n minutes", - { n: values.autoEnterLiteModeDelay })} + + {t( + "When closing the window, LightWeight Mode will be automatically activated after _n minutes", + { n: values.autoEnterLiteModeDelay }, + )} @@ -133,4 +141,4 @@ export const LiteModeViewer = forwardRef((props, ref) => { ); -}); \ No newline at end of file +}); diff --git a/src/pages/home.tsx b/src/pages/home.tsx index 04adf1cb..fff5b89d 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -37,7 +37,11 @@ import { BasePage } from "@/components/base"; import { ClashInfoCard } from "@/components/home/clash-info-card"; import { SystemInfoCard } from "@/components/home/system-info-card"; import { useLockFn } from "ahooks"; -import { entry_lightweight_mode, openWebUrl, patchVergeConfig } from "@/services/cmds"; +import { + entry_lightweight_mode, + openWebUrl, + patchVergeConfig, +} from "@/services/cmds"; import { TestCard } from "@/components/home/test-card"; import { IpInfoCard } from "@/components/home/ip-info-card"; @@ -260,7 +264,11 @@ const HomePage = () => { header={ - entry_lightweight_mode()} size="small" color="inherit"> + await entry_lightweight_mode()} + size="small" + color="inherit" + >