mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-28 00:10:05 +08:00
fix(dns): save the DNS override decision on every runtime replacement
Refs #8431
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::core::notify::{Refresh, announce};
|
||||
use crate::{
|
||||
config::{
|
||||
Config, IVerge,
|
||||
runtime::IRuntime,
|
||||
snapshot::{capture_config_files, restore_files},
|
||||
},
|
||||
core::auto_backup::AutoBackupManager,
|
||||
@@ -12,7 +13,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_draft::{DraftTransaction, SharedDraft};
|
||||
use clash_verge_logging::{Type, logging_error};
|
||||
use serde_yaml_ng::Mapping;
|
||||
use std::sync::Arc;
|
||||
@@ -108,6 +109,12 @@ 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)?;
|
||||
@@ -155,12 +162,16 @@ 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);
|
||||
}
|
||||
return match restore_files(&snapshots).await {
|
||||
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 {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user