fix(core): serialize runtime config updates

This commit is contained in:
Tunglies
2026-05-28 17:41:39 +08:00
parent 43843f1eca
commit 08fd2ce68b
3 changed files with 48 additions and 8 deletions
+18 -1
View File
@@ -6,7 +6,14 @@ use anyhow::Result;
use arc_swap::{ArcSwap, ArcSwapOption};
use clash_verge_logger::AsyncLogger;
use once_cell::sync::Lazy;
use std::{fmt, sync::Arc, time::Instant};
use std::{
fmt,
sync::{
Arc,
atomic::{AtomicBool, Ordering},
},
time::Instant,
};
use tauri_plugin_shell::process::CommandChild;
use crate::singleton;
@@ -34,6 +41,7 @@ impl fmt::Display for RunningMode {
pub struct CoreManager {
state: ArcSwap<State>,
last_update: ArcSwapOption<Instant>,
config_update_in_progress: AtomicBool,
}
#[derive(Debug)]
@@ -56,6 +64,7 @@ impl Default for CoreManager {
Self {
state: ArcSwap::new(Arc::new(State::default())),
last_update: ArcSwapOption::new(None),
config_update_in_progress: AtomicBool::new(false),
}
}
}
@@ -95,6 +104,14 @@ impl CoreManager {
self.last_update.store(Some(Arc::new(time)));
}
fn try_start_config_update(&self) -> bool {
!self.config_update_in_progress.swap(true, Ordering::AcqRel)
}
fn finish_config_update(&self) {
self.config_update_in_progress.store(false, Ordering::Release);
}
pub async fn init(&self) -> Result<()> {
self.start_core().await?;
Ok(())