mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-28 16:30:52 +08:00
fix: auto light-weight mode doesn't take effect in silent-start mode (#3875)
* fix: auto light-weight mode does not take effect when silent-start mode is enabled * refactor: streamline window state retrieval and hiding logic * fix: add checks for remote name and existence before format check in pre-push hook * fix: simplify remote checks in pre-push hook to enhance clarity and maintainability --------- Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
This commit is contained in:
@@ -36,20 +36,20 @@ where
|
||||
|
||||
pub fn run_once_auto_lightweight() {
|
||||
LightWeightState::default().run_once_time(|| {
|
||||
let is_silent_start = Config::verge().data().enable_silent_start.unwrap_or(true);
|
||||
let is_silent_start = Config::verge().data().enable_silent_start.unwrap_or(false);
|
||||
let enable_auto = Config::verge()
|
||||
.data()
|
||||
.enable_auto_light_weight_mode
|
||||
.unwrap_or(true);
|
||||
.unwrap_or(false);
|
||||
if enable_auto && is_silent_start {
|
||||
logging!(
|
||||
info,
|
||||
Type::Lightweight,
|
||||
true,
|
||||
"正常创建窗口和添加定时器监听器"
|
||||
"在静默启动的情况下,创建窗口再添加自动进入轻量模式窗口监听器"
|
||||
);
|
||||
set_lightweight_mode(false);
|
||||
disable_auto_light_weight_mode();
|
||||
enable_auto_light_weight_mode();
|
||||
|
||||
// 触发托盘更新
|
||||
if let Err(e) = Tray::global().update_part() {
|
||||
@@ -65,8 +65,13 @@ pub fn auto_lightweight_mode_init() {
|
||||
let is_silent_start = { Config::verge().data().enable_silent_start }.unwrap_or(false);
|
||||
let enable_auto = { Config::verge().data().enable_auto_light_weight_mode }.unwrap_or(false);
|
||||
|
||||
if enable_auto && is_silent_start {
|
||||
logging!(info, Type::Lightweight, true, "自动轻量模式静默启动");
|
||||
if enable_auto && !is_silent_start {
|
||||
logging!(
|
||||
info,
|
||||
Type::Lightweight,
|
||||
true,
|
||||
"非静默启动直接挂载自动进入轻量模式监听器!"
|
||||
);
|
||||
set_lightweight_mode(true);
|
||||
enable_auto_light_weight_mode();
|
||||
|
||||
@@ -84,7 +89,7 @@ pub fn is_in_lightweight_mode() -> bool {
|
||||
}
|
||||
|
||||
// 设置轻量模式状态
|
||||
fn set_lightweight_mode(value: bool) {
|
||||
pub fn set_lightweight_mode(value: bool) {
|
||||
with_lightweight_status(|state| {
|
||||
state.set_lightweight_mode(value);
|
||||
});
|
||||
@@ -126,7 +131,6 @@ pub fn entry_lightweight_mode() {
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
AppHandleManager::global().set_activation_policy_accessory();
|
||||
logging!(info, Type::Lightweight, true, "轻量模式已开启");
|
||||
}
|
||||
set_lightweight_mode(true);
|
||||
let _ = cancel_light_weight_timer();
|
||||
@@ -163,7 +167,6 @@ pub fn exit_lightweight_mode() {
|
||||
}
|
||||
|
||||
set_lightweight_mode(false);
|
||||
logging!(info, Type::Lightweight, true, "正在退出轻量模式");
|
||||
|
||||
// macOS激活策略
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
@@ -295,6 +295,7 @@ pub fn create_window(is_show: bool) -> bool {
|
||||
|
||||
if !is_show {
|
||||
logging!(info, Type::Window, true, "静默模式启动时不创建窗口");
|
||||
lightweight::set_lightweight_mode(true);
|
||||
handle::Handle::notify_startup_completed();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,20 +86,27 @@ pub struct WindowManager;
|
||||
|
||||
impl WindowManager {
|
||||
pub fn get_main_window_state() -> WindowState {
|
||||
if let Some(window) = Self::get_main_window() {
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
WindowState::Minimized
|
||||
} else if window.is_visible().unwrap_or(false) {
|
||||
if window.is_focused().unwrap_or(false) {
|
||||
match Self::get_main_window() {
|
||||
Some(window) => {
|
||||
let is_minimized = window.is_minimized().unwrap_or(false);
|
||||
let is_visible = window.is_visible().unwrap_or(false);
|
||||
let is_focused = window.is_focused().unwrap_or(false);
|
||||
|
||||
if is_minimized {
|
||||
return WindowState::Minimized;
|
||||
}
|
||||
|
||||
if !is_visible {
|
||||
return WindowState::Hidden;
|
||||
}
|
||||
|
||||
if is_focused {
|
||||
WindowState::VisibleFocused
|
||||
} else {
|
||||
WindowState::VisibleUnfocused
|
||||
}
|
||||
} else {
|
||||
WindowState::Hidden
|
||||
}
|
||||
} else {
|
||||
WindowState::NotExist
|
||||
None => WindowState::NotExist,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,17 +323,21 @@ impl WindowManager {
|
||||
pub fn hide_main_window() -> WindowOperationResult {
|
||||
logging!(info, Type::Window, true, "开始隐藏主窗口");
|
||||
|
||||
if let Some(window) = Self::get_main_window() {
|
||||
if window.hide().is_ok() {
|
||||
logging!(info, Type::Window, true, "窗口已隐藏");
|
||||
WindowOperationResult::Hidden
|
||||
} else {
|
||||
logging!(warn, Type::Window, true, "隐藏窗口失败");
|
||||
WindowOperationResult::Failed
|
||||
match Self::get_main_window() {
|
||||
Some(window) => match window.hide() {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Window, true, "窗口已隐藏");
|
||||
WindowOperationResult::Hidden
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(warn, Type::Window, true, "隐藏窗口失败: {}", e);
|
||||
WindowOperationResult::Failed
|
||||
}
|
||||
},
|
||||
None => {
|
||||
logging!(info, Type::Window, true, "窗口不存在,无需隐藏");
|
||||
WindowOperationResult::NoAction
|
||||
}
|
||||
} else {
|
||||
logging!(info, Type::Window, true, "窗口不存在,无需隐藏");
|
||||
WindowOperationResult::NoAction
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user