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:
希亚的西红柿
2025-06-23 23:13:31 +08:00
committed by GitHub
parent d5a174c71b
commit 6d519dac1e
5 changed files with 48 additions and 33 deletions

View File

@@ -8,11 +8,9 @@ if git diff --cached --name-only | grep -q '^src-tauri/'; then
fi
fi
remote_name="$1"
remote_url=$(git remote get-url "$remote_name")
if [[ "$remote_url" =~ github\.com[:/]+clash-verge-rev/clash-verge-rev(\.git)?$ ]]; then
echo "[pre-push] Detected push to clash-verge-rev/clash-verge-rev ($remote_url)"
# 检查所有 remote url 是否有目标仓库
if git remote -v | grep -Eq 'github\\.com[:/]+clash-verge-rev/clash-verge-rev(\\.git)?'; then
echo "[pre-push] Detected push to clash-verge-rev/clash-verge-rev"
echo "[pre-push] Running pnpm format:check..."
pnpm format:check

View File

@@ -5,6 +5,8 @@
- 修复系统代理端口不同步问题
- 修复自定义 `css` 背景图无法生效问题
- 修复在轻量模式下快速点击托盘图标带来的竞争态卡死问题
- 修复同时开启静默启动与自动进入轻量模式后,自动进入轻量模式失效的问题
- 修复静默启动时托盘工具栏轻量模式开启与关闭状态的同步
### ✨ 新增功能

View File

@@ -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")]

View File

@@ -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;
}

View File

@@ -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
}
}