From 032e5bf32e276b44c67b75b1b2dbe3fc5a64c37d Mon Sep 17 00:00:00 2001 From: Tunglies Date: Sun, 15 Jun 2025 05:10:15 +0800 Subject: [PATCH] fix: add macOS specific activation policy handling for silent start (#3740) * fix: add macOS specific activation policy handling for silent start * fix: resolve abnormal Dock icon launch during macOS silent startup --- UPDATELOG.md | 1 + src-tauri/src/utils/resolve.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/UPDATELOG.md b/UPDATELOG.md index 0db4fc6d..0b55cdb7 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -38,6 +38,7 @@ - 修复提权漏洞,改用带认证的 IPC 通信机制 - 修复静默启动无法使用自动轻量模式 - 修复 JS 脚本转义特殊字符报错 +- 修复 macOS 静默启动时异常启动 Dock 栏图标 --- diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index 576279d7..3932a85f 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -1,3 +1,5 @@ +#[cfg(target_os = "macos")] +use crate::AppHandleManager; use crate::{ config::{Config, IVerge, PrfItem}, core::*, @@ -218,6 +220,14 @@ pub async fn resolve_setup_async(app_handle: &AppHandle) { // 创建窗口 let is_silent_start = { Config::verge().data().enable_silent_start }.unwrap_or(false); + #[cfg(target_os = "macos")] + { + if is_silent_start { + use crate::AppHandleManager; + + AppHandleManager::global().set_activation_policy_accessory(); + } + } create_window(!is_silent_start); // 初始化定时器 @@ -414,6 +424,10 @@ pub fn create_window(is_show: bool) -> bool { let _ = window_clone.show(); let _ = window_clone.set_focus(); logging!(info, Type::Window, true, "窗口已立即显示"); + #[cfg(target_os = "macos")] + { + AppHandleManager::global().set_activation_policy_regular(); + } let timeout_seconds = if crate::module::lightweight::is_in_lightweight_mode() { 3