mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-21 11:42:09 +08:00
refactor(service): simplify DNS override sync and runtime asset staging
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::{
|
||||
};
|
||||
use anyhow::{Result, anyhow};
|
||||
use chrono::Utc;
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use reqwest_dav::list_cmd::ListFile;
|
||||
use serde::Serialize;
|
||||
use smartstring::alias::String;
|
||||
@@ -88,7 +88,6 @@ async fn finalize_restored_verge_config(
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
logging_error!(Type::Config, Config::sync_dns_override().await);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ use crate::core::notify::{Refresh, announce};
|
||||
use crate::{
|
||||
config::{
|
||||
Config, IVerge,
|
||||
runtime::IRuntime,
|
||||
snapshot::{capture_config_files, restore_files},
|
||||
},
|
||||
core::auto_backup::AutoBackupManager,
|
||||
@@ -13,7 +12,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use clash_verge_draft::{DraftTransaction, SharedDraft};
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_logging::{Type, logging_error};
|
||||
use serde_yaml_ng::Mapping;
|
||||
use std::sync::Arc;
|
||||
@@ -109,12 +108,6 @@ async fn ensure_effect(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn sync_dns_of_replaced_runtime(config_write: &MutexGuard<'_, ()>, original: &SharedDraft<IRuntime>) {
|
||||
if !Arc::ptr_eq(original, &Config::runtime().await.data_arc()) {
|
||||
logging_error!(Type::Config, Config::sync_dns_override_locked(config_write).await);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn apply(config_write: &MutexGuard<'_, ()>, patch: Patch<'_>, effects: Effects) -> Result<()> {
|
||||
let manager = CoreManager::global();
|
||||
let update = manager.claim_config_update(config_write)?;
|
||||
@@ -162,16 +155,12 @@ pub(super) async fn apply(config_write: &MutexGuard<'_, ()>, patch: Patch<'_>, e
|
||||
let runtime_path = crate::utils::dirs::app_home_dir()?.join(crate::constants::files::RUNTIME_CONFIG);
|
||||
snapshots.retain(|snapshot| snapshot.path != runtime_path);
|
||||
}
|
||||
let restored = restore_files(&snapshots).await;
|
||||
// After the restore, which would otherwise overwrite the saved decision.
|
||||
sync_dns_of_replaced_runtime(config_write, &original_runtime).await;
|
||||
return match restored {
|
||||
return match restore_files(&snapshots).await {
|
||||
Ok(()) => Err(error),
|
||||
Err(rollback_error) => Err(proxy_control::rollback_failure(error, rollback_error)),
|
||||
};
|
||||
}
|
||||
transaction.commit();
|
||||
sync_dns_of_replaced_runtime(config_write, &original_runtime).await;
|
||||
match patch {
|
||||
Patch::Verge { patch, .. } => {
|
||||
if patch.auto_check_update == Some(false) {
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
};
|
||||
use anyhow::{Context as _, Result, anyhow, bail};
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use scopeguard::{ScopeGuard, defer, guard};
|
||||
|
||||
pub async fn probe_listener(request: ListenerProbe) -> Result<ListenerProbeOutcome> {
|
||||
@@ -30,7 +30,7 @@ pub async fn probe_listener(request: ListenerProbe) -> Result<ListenerProbeOutco
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub async fn save_proxy_ports(settings: ProxyPortSettings) -> Result<SaveProxyPortsOutcome> {
|
||||
settings.validate()?;
|
||||
let config_write = Config::lock_config_write().await;
|
||||
let _config_write = Config::lock_config_write().await;
|
||||
let manager = CoreManager::global();
|
||||
if !manager.try_start_config_update() {
|
||||
bail!("configuration update is already running");
|
||||
@@ -124,7 +124,6 @@ pub async fn save_proxy_ports(settings: ProxyPortSettings) -> Result<SaveProxyPo
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
logging_error!(Type::Config, Config::sync_dns_override_locked(&config_write).await);
|
||||
// The save landed, so the port the app had borrowed is now irrelevant.
|
||||
let _ = ScopeGuard::into_inner(borrowed_port);
|
||||
announce(Refresh::Clash);
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
utils::help::{mask_err, mask_url},
|
||||
};
|
||||
use anyhow::{Result, bail};
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use smartstring::alias::String;
|
||||
|
||||
/// Toggle proxy profile
|
||||
@@ -217,10 +217,7 @@ pub async fn update_profile(uid: &String, option: Option<&PrfOption>, is_mannual
|
||||
if should_refresh {
|
||||
logging!(debug, Type::Config, "[订阅更新] 更新内核配置");
|
||||
match CoreManager::global().update_config_with_force(is_mannual_trigger).await {
|
||||
Ok(outcome) if outcome.is_valid() => {
|
||||
logging_error!(Type::Config, Config::sync_dns_override().await);
|
||||
announce(Refresh::Clash);
|
||||
}
|
||||
Ok(outcome) if outcome.is_valid() => announce(Refresh::Clash),
|
||||
Ok(outcome @ (ValidationOutcome::Skipped { .. } | ValidationOutcome::Busy)) if !is_mannual_trigger => {
|
||||
logging!(info, Type::Config, "[订阅更新] 本次配置刷新已跳过: {}", outcome);
|
||||
}
|
||||
@@ -247,9 +244,5 @@ pub async fn update_profile(uid: &String, option: Option<&PrfOption>, is_mannual
|
||||
|
||||
/// 增强配置
|
||||
pub async fn enhance_profiles() -> Result<ValidationOutcome> {
|
||||
let outcome = CoreManager::global().update_config_forced().await?;
|
||||
if outcome.is_valid() {
|
||||
logging_error!(Type::Config, Config::sync_dns_override().await);
|
||||
}
|
||||
Ok(outcome)
|
||||
CoreManager::global().update_config_forced().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user