mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
fix(resolve): implement resolve_done state management and refactor timer logic
This commit is contained in:
@@ -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(());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
core::{CoreManager, handle, tray},
|
||||
feat::clean_async,
|
||||
process::AsyncHandler,
|
||||
utils,
|
||||
utils::{self, resolve::reset_resolve_done},
|
||||
};
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use serde_yaml_ng::{Mapping, Value};
|
||||
@@ -42,6 +42,7 @@ pub async fn restart_app() {
|
||||
if cleanup_result { 0 } else { 1 }
|
||||
);
|
||||
|
||||
reset_resolve_done();
|
||||
let app_handle = handle::Handle::app_handle();
|
||||
app_handle.restart();
|
||||
}
|
||||
|
||||
@@ -260,6 +260,7 @@ pub fn run() {
|
||||
resolve::resolve_setup_async();
|
||||
resolve::resolve_setup_sync();
|
||||
init_signal();
|
||||
resolve::resolve_done();
|
||||
|
||||
logging!(info, Type::Setup, "初始化已启动");
|
||||
Ok(())
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use flexi_logger::LoggerHandle;
|
||||
|
||||
@@ -24,6 +26,8 @@ pub mod ui;
|
||||
pub mod window;
|
||||
pub mod window_script;
|
||||
|
||||
static RESOLVE_DONE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub async fn prioritize_initialization() -> Option<LoggerHandle> {
|
||||
init_work_config().await;
|
||||
init_resources().await;
|
||||
@@ -208,3 +212,15 @@ pub(super) async fn init_window() {
|
||||
}
|
||||
WindowManager::create_window(!is_silent_start).await;
|
||||
}
|
||||
|
||||
pub fn resolve_done() {
|
||||
RESOLVE_DONE.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
pub fn is_resolve_done() -> bool {
|
||||
RESOLVE_DONE.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub fn reset_resolve_done() {
|
||||
RESOLVE_DONE.store(false, Ordering::Release);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user