mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: silent start does not take effect (#3708)
* fix: light mode error * feat: optimize the logic * fix: clippy issues
This commit is contained in:
@@ -54,12 +54,12 @@ pub fn auto_lightweight_mode_init() {
|
|||||||
let _ = app_handle.state::<Mutex<LightWeightState>>();
|
let _ = app_handle.state::<Mutex<LightWeightState>>();
|
||||||
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!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
Type::Lightweight,
|
Type::Lightweight,
|
||||||
true,
|
true,
|
||||||
"Add timer listener when creating window in silent start mode"
|
"Add timer listener when creating window normally"
|
||||||
);
|
);
|
||||||
set_lightweight_mode(true);
|
set_lightweight_mode(true);
|
||||||
enable_auto_light_weight_mode();
|
enable_auto_light_weight_mode();
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
use std::sync::Once;
|
use std::sync::{Arc, Once, OnceLock};
|
||||||
|
|
||||||
use crate::{logging, utils::logging::Type};
|
use crate::{logging, utils::logging::Type};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct LightWeightState {
|
pub struct LightWeightState {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
once: Once,
|
once: Arc<Once>,
|
||||||
pub is_lightweight: bool,
|
pub is_lightweight: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightWeightState {
|
impl LightWeightState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
once: Once::new(),
|
once: Arc::new(Once::new()),
|
||||||
is_lightweight: false,
|
is_lightweight: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +38,7 @@ impl LightWeightState {
|
|||||||
|
|
||||||
impl Default for LightWeightState {
|
impl Default for LightWeightState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
static INSTANCE: OnceLock<LightWeightState> = OnceLock::new();
|
||||||
|
INSTANCE.get_or_init(LightWeightState::new).clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,6 +263,17 @@ pub fn create_window(is_show: bool) -> bool {
|
|||||||
is_show
|
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(app_handle) = handle::Handle::global().app_handle() {
|
||||||
if let Some(window) = app_handle.get_webview_window("main") {
|
if let Some(window) = app_handle.get_webview_window("main") {
|
||||||
logging!(info, Type::Window, true, "主窗口已存在,将显示现有窗口");
|
logging!(info, Type::Window, true, "主窗口已存在,将显示现有窗口");
|
||||||
|
|||||||
Reference in New Issue
Block a user