fix(resolve): implement resolve_done state management and refactor timer logic

This commit is contained in:
Tunglies
2025-11-24 13:52:08 +08:00
parent cbd1fa44d7
commit 871881c460
5 changed files with 25 additions and 37 deletions

View File

@@ -21,7 +21,6 @@ use sysproxy::{Autoproxy, GuardMonitor, GuardType, Sysproxy};
use tauri_plugin_autostart::ManagerExt as _;
pub struct Sysopt {
initialed: AtomicBool,
update_sysproxy: AtomicBool,
reset_sysproxy: AtomicBool,
guard: Arc<RwLock<GuardMonitor>>,
@@ -30,7 +29,6 @@ pub struct Sysopt {
impl Default for Sysopt {
fn default() -> Self {
Self {
initialed: AtomicBool::new(false),
update_sysproxy: AtomicBool::new(false),
reset_sysproxy: AtomicBool::new(false),
guard: Arc::new(RwLock::new(GuardMonitor::new(
@@ -110,10 +108,6 @@ impl Sysopt {
Self::default()
}
pub fn is_initialed(&self) -> bool {
self.initialed.load(Ordering::SeqCst)
}
fn access_guard(&self) -> Arc<RwLock<GuardMonitor>> {
Arc::clone(&self.guard)
}
@@ -151,7 +145,6 @@ impl Sysopt {
/// init the sysproxy
pub async fn update_sysproxy(&self) -> Result<()> {
self.initialed.store(true, Ordering::SeqCst);
if self.update_sysproxy.load(Ordering::Acquire) {
logging!(info, Type::Core, "Sysproxy update is already in progress.");
return Ok(());

View File

@@ -1,8 +1,4 @@
use crate::{
config::Config,
core::{CoreManager, manager::RunningMode, sysopt::Sysopt},
feat, singleton,
};
use crate::{config::Config, feat, singleton, utils::resolve::is_resolve_done};
use anyhow::{Context as _, Result};
use clash_verge_logging::{Type, logging, logging_error};
use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder};
@@ -392,8 +388,7 @@ impl Timer {
.spawn_async_routine(move || {
let uid = uid.clone();
Box::pin(async move {
Self::wait_untile_core_manager(Duration::from_millis(1000)).await;
Self::wait_until_sysopt(Duration::from_millis(1000)).await;
Self::wait_until_resolve_done(Duration::from_millis(5000)).await;
Self::async_task(&uid).await;
}) as Pin<Box<dyn std::future::Future<Output = ()> + Send>>
})
@@ -524,29 +519,11 @@ impl Timer {
Self::emit_update_event(uid, false);
}
async fn wait_untile_core_manager(max_wait: Duration) {
async fn wait_until_resolve_done(max_wait: Duration) {
let _ = timeout(max_wait, async {
while *CoreManager::global().get_running_mode() != RunningMode::NotRunning {
logging!(
debug,
Type::Timer,
"Waiting for CoreManager to be initialized..."
);
sleep(Duration::from_millis(30)).await;
}
})
.await;
}
async fn wait_until_sysopt(max_wait: Duration) {
let _ = timeout(max_wait, async {
while !Sysopt::global().is_initialed() {
logging!(
debug,
Type::Timer,
"Waiting for Sysopt to be initialized..."
);
sleep(Duration::from_millis(30)).await;
while !is_resolve_done() {
logging!(debug, Type::Timer, "Waiting for resolve to be done...");
sleep(Duration::from_millis(200)).await;
}
})
.await;