mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +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:
@@ -8,11 +8,9 @@ if git diff --cached --name-only | grep -q '^src-tauri/'; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
remote_name="$1"
|
# 检查所有 remote url 是否有目标仓库
|
||||||
remote_url=$(git remote get-url "$remote_name")
|
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"
|
||||||
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)"
|
|
||||||
echo "[pre-push] Running pnpm format:check..."
|
echo "[pre-push] Running pnpm format:check..."
|
||||||
|
|
||||||
pnpm format:check
|
pnpm format:check
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
- 修复系统代理端口不同步问题
|
- 修复系统代理端口不同步问题
|
||||||
- 修复自定义 `css` 背景图无法生效问题
|
- 修复自定义 `css` 背景图无法生效问题
|
||||||
- 修复在轻量模式下快速点击托盘图标带来的竞争态卡死问题
|
- 修复在轻量模式下快速点击托盘图标带来的竞争态卡死问题
|
||||||
|
- 修复同时开启静默启动与自动进入轻量模式后,自动进入轻量模式失效的问题
|
||||||
|
- 修复静默启动时托盘工具栏轻量模式开启与关闭状态的同步
|
||||||
|
|
||||||
### ✨ 新增功能
|
### ✨ 新增功能
|
||||||
|
|
||||||
|
|||||||
@@ -36,20 +36,20 @@ where
|
|||||||
|
|
||||||
pub fn run_once_auto_lightweight() {
|
pub fn run_once_auto_lightweight() {
|
||||||
LightWeightState::default().run_once_time(|| {
|
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()
|
let enable_auto = Config::verge()
|
||||||
.data()
|
.data()
|
||||||
.enable_auto_light_weight_mode
|
.enable_auto_light_weight_mode
|
||||||
.unwrap_or(true);
|
.unwrap_or(false);
|
||||||
if enable_auto && is_silent_start {
|
if enable_auto && is_silent_start {
|
||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
Type::Lightweight,
|
Type::Lightweight,
|
||||||
true,
|
true,
|
||||||
"正常创建窗口和添加定时器监听器"
|
"在静默启动的情况下,创建窗口再添加自动进入轻量模式窗口监听器"
|
||||||
);
|
);
|
||||||
set_lightweight_mode(false);
|
set_lightweight_mode(false);
|
||||||
disable_auto_light_weight_mode();
|
enable_auto_light_weight_mode();
|
||||||
|
|
||||||
// 触发托盘更新
|
// 触发托盘更新
|
||||||
if let Err(e) = Tray::global().update_part() {
|
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 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);
|
let enable_auto = { Config::verge().data().enable_auto_light_weight_mode }.unwrap_or(false);
|
||||||
|
|
||||||
if enable_auto && is_silent_start {
|
if enable_auto && !is_silent_start {
|
||||||
logging!(info, Type::Lightweight, true, "自动轻量模式静默启动");
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Lightweight,
|
||||||
|
true,
|
||||||
|
"非静默启动直接挂载自动进入轻量模式监听器!"
|
||||||
|
);
|
||||||
set_lightweight_mode(true);
|
set_lightweight_mode(true);
|
||||||
enable_auto_light_weight_mode();
|
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| {
|
with_lightweight_status(|state| {
|
||||||
state.set_lightweight_mode(value);
|
state.set_lightweight_mode(value);
|
||||||
});
|
});
|
||||||
@@ -126,7 +131,6 @@ pub fn entry_lightweight_mode() {
|
|||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
AppHandleManager::global().set_activation_policy_accessory();
|
AppHandleManager::global().set_activation_policy_accessory();
|
||||||
logging!(info, Type::Lightweight, true, "轻量模式已开启");
|
|
||||||
}
|
}
|
||||||
set_lightweight_mode(true);
|
set_lightweight_mode(true);
|
||||||
let _ = cancel_light_weight_timer();
|
let _ = cancel_light_weight_timer();
|
||||||
@@ -163,7 +167,6 @@ pub fn exit_lightweight_mode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_lightweight_mode(false);
|
set_lightweight_mode(false);
|
||||||
logging!(info, Type::Lightweight, true, "正在退出轻量模式");
|
|
||||||
|
|
||||||
// macOS激活策略
|
// macOS激活策略
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
|||||||
@@ -295,6 +295,7 @@ pub fn create_window(is_show: bool) -> bool {
|
|||||||
|
|
||||||
if !is_show {
|
if !is_show {
|
||||||
logging!(info, Type::Window, true, "静默模式启动时不创建窗口");
|
logging!(info, Type::Window, true, "静默模式启动时不创建窗口");
|
||||||
|
lightweight::set_lightweight_mode(true);
|
||||||
handle::Handle::notify_startup_completed();
|
handle::Handle::notify_startup_completed();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,20 +86,27 @@ pub struct WindowManager;
|
|||||||
|
|
||||||
impl WindowManager {
|
impl WindowManager {
|
||||||
pub fn get_main_window_state() -> WindowState {
|
pub fn get_main_window_state() -> WindowState {
|
||||||
if let Some(window) = Self::get_main_window() {
|
match Self::get_main_window() {
|
||||||
if window.is_minimized().unwrap_or(false) {
|
Some(window) => {
|
||||||
WindowState::Minimized
|
let is_minimized = window.is_minimized().unwrap_or(false);
|
||||||
} else if window.is_visible().unwrap_or(false) {
|
let is_visible = window.is_visible().unwrap_or(false);
|
||||||
if window.is_focused().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
|
WindowState::VisibleFocused
|
||||||
} else {
|
} else {
|
||||||
WindowState::VisibleUnfocused
|
WindowState::VisibleUnfocused
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
WindowState::Hidden
|
|
||||||
}
|
}
|
||||||
} else {
|
None => WindowState::NotExist,
|
||||||
WindowState::NotExist
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,17 +323,21 @@ impl WindowManager {
|
|||||||
pub fn hide_main_window() -> WindowOperationResult {
|
pub fn hide_main_window() -> WindowOperationResult {
|
||||||
logging!(info, Type::Window, true, "开始隐藏主窗口");
|
logging!(info, Type::Window, true, "开始隐藏主窗口");
|
||||||
|
|
||||||
if let Some(window) = Self::get_main_window() {
|
match Self::get_main_window() {
|
||||||
if window.hide().is_ok() {
|
Some(window) => match window.hide() {
|
||||||
logging!(info, Type::Window, true, "窗口已隐藏");
|
Ok(_) => {
|
||||||
WindowOperationResult::Hidden
|
logging!(info, Type::Window, true, "窗口已隐藏");
|
||||||
} else {
|
WindowOperationResult::Hidden
|
||||||
logging!(warn, Type::Window, true, "隐藏窗口失败");
|
}
|
||||||
WindowOperationResult::Failed
|
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