From 1970155c515b2f15656767175aee33481e39bf79 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Sat, 12 Apr 2025 03:27:21 +0800 Subject: [PATCH] fix: macos use hotkey closing window can not entry auto-lightweight-mode #3326 --- UPDATELOG.md | 1 + src-tauri/src/feat/window.rs | 13 ++++++++++++- src-tauri/src/module/lightweight.rs | 6 +++++- src-tauri/src/utils/resolve.rs | 2 -- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/UPDATELOG.md b/UPDATELOG.md index 6ed564fe..898f22dc 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -10,6 +10,7 @@ #### 修复了: - 首页“代理模式”快速切换导致的卡死问题 - 解锁测试报错信息 + - Macos 快捷键关闭窗口无法启用自动轻量模式 ## v2.2.3 diff --git a/src-tauri/src/feat/window.rs b/src-tauri/src/feat/window.rs index d44b0a38..7bc986ad 100644 --- a/src-tauri/src/feat/window.rs +++ b/src-tauri/src/feat/window.rs @@ -109,10 +109,21 @@ pub fn quit() { #[cfg(target_os = "macos")] pub fn hide() { + use crate::module::lightweight::add_light_weight_timer; + + let enable_auto_light_weight_mode = Config::verge() + .data() + .enable_auto_light_weight_mode + .unwrap_or(false); + + if enable_auto_light_weight_mode { + add_light_weight_timer(); + } + if let Some(window) = handle::Handle::global().get_window() { if window.is_visible().unwrap_or(false) { - AppHandleManager::global().set_activation_policy_accessory(); let _ = window.hide(); } } + AppHandleManager::global().set_activation_policy_accessory(); } diff --git a/src-tauri/src/module/lightweight.rs b/src-tauri/src/module/lightweight.rs index fed23aee..d0e51fbf 100644 --- a/src-tauri/src/module/lightweight.rs +++ b/src-tauri/src/module/lightweight.rs @@ -5,7 +5,7 @@ use tauri::{Listener, Manager}; use crate::{ config::Config, core::{handle, timer::Timer}, - log_err, logging, + log_err, logging, logging_error, utils::logging::Type, AppHandleManager, }; @@ -40,6 +40,10 @@ pub fn entry_lightweight_mode() { let _ = cancel_light_weight_timer(); } +pub fn add_light_weight_timer() { + logging_error!(Type::Lightweight, setup_light_weight_timer()); +} + fn setup_window_close_listener() -> u32 { if let Some(window) = handle::Handle::global().get_window() { let handler = window.listen("tauri://close-requested", move |_event| { diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index e46fd435..f0ca11fb 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -151,8 +151,6 @@ pub fn create_window(is_showup: bool) { return; } - logging!(info, Type::Window, true, "Creating new application window"); - #[cfg(target_os = "windows")] let window = tauri::WebviewWindowBuilder::new( &app_handle,