From 4e54b61380b93398cee17963f365315cb4c195ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=8C=E4=BA=9A=E7=9A=84=E8=A5=BF=E7=BA=A2=E6=9F=BF?= Date: Thu, 12 Jun 2025 23:39:03 +0800 Subject: [PATCH] fix: silent start does not take effect (#3708) * fix: light mode error * feat: optimize the logic * fix: clippy issues --- src-tauri/src/module/lightweight.rs | 4 ++-- src-tauri/src/state/lightweight.rs | 10 ++++++---- src-tauri/src/utils/resolve.rs | 11 +++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/module/lightweight.rs b/src-tauri/src/module/lightweight.rs index e77669dc..93a03135 100644 --- a/src-tauri/src/module/lightweight.rs +++ b/src-tauri/src/module/lightweight.rs @@ -54,12 +54,12 @@ pub fn auto_lightweight_mode_init() { let _ = app_handle.state::>(); 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 { + if enable_auto && !is_silent_start { logging!( info, Type::Lightweight, true, - "Add timer listener when creating window in silent start mode" + "Add timer listener when creating window normally" ); set_lightweight_mode(true); enable_auto_light_weight_mode(); diff --git a/src-tauri/src/state/lightweight.rs b/src-tauri/src/state/lightweight.rs index 3f8db1f6..da960984 100644 --- a/src-tauri/src/state/lightweight.rs +++ b/src-tauri/src/state/lightweight.rs @@ -1,17 +1,18 @@ -use std::sync::Once; +use std::sync::{Arc, Once, OnceLock}; use crate::{logging, utils::logging::Type}; +#[derive(Clone)] pub struct LightWeightState { #[allow(unused)] - once: Once, + once: Arc, pub is_lightweight: bool, } impl LightWeightState { pub fn new() -> Self { Self { - once: Once::new(), + once: Arc::new(Once::new()), is_lightweight: false, } } @@ -37,6 +38,7 @@ impl LightWeightState { impl Default for LightWeightState { fn default() -> Self { - Self::new() + static INSTANCE: OnceLock = OnceLock::new(); + INSTANCE.get_or_init(LightWeightState::new).clone() } } diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index 2d9ae87b..ce76a53f 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -263,6 +263,17 @@ pub fn create_window(is_show: bool) -> bool { is_show ); + if !is_show { + logging!( + info, + Type::Window, + true, + "Not to create window when starting in silent mode" + ); + handle::Handle::notify_startup_completed(); + return false; + } + if let Some(app_handle) = handle::Handle::global().app_handle() { if let Some(window) = app_handle.get_webview_window("main") { logging!(info, Type::Window, true, "主窗口已存在,将显示现有窗口");