mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-06 23:00:15 +08:00
refactor(config): move DNS and tunnel rules into clash-verge-config-render
override_source, needs_public_dns and sanitize_tunnels_proxy are pure rules over a rendered Mapping; the app keeps the DNS override state, IPC and file access.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use anyhow::{Context as _, bail, ensure};
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use serde_yaml_ng::{Mapping, Value};
|
||||
use std::{
|
||||
io::Read as _,
|
||||
os::unix::process::CommandExt as _,
|
||||
@@ -24,23 +23,6 @@ fn dns_state_dir() -> anyhow::Result<PathBuf> {
|
||||
Ok(dir)
|
||||
}
|
||||
|
||||
// Without the placeholder, a LAN resolver is reached outside TUN and fake-ip is bypassed.
|
||||
fn needs_public_dns(config: &Mapping) -> bool {
|
||||
let section = |name: &str| config.get(name).and_then(Value::as_mapping);
|
||||
let enabled = |name: &str| {
|
||||
section(name)
|
||||
.and_then(|map| map.get("enable"))
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
};
|
||||
enabled("tun")
|
||||
&& enabled("dns")
|
||||
&& section("dns")
|
||||
.and_then(|dns| dns.get("enhanced-mode"))
|
||||
.and_then(Value::as_str)
|
||||
== Some("fake-ip")
|
||||
}
|
||||
|
||||
/// Sets the placeholder DNS while the running config needs it, and restores the system DNS otherwise.
|
||||
#[allow(
|
||||
clippy::significant_drop_tightening,
|
||||
@@ -59,7 +41,12 @@ pub async fn sync_public_dns() {
|
||||
}
|
||||
let core_running = !matches!(*CoreManager::global().get_running_mode(), RunningMode::NotRunning);
|
||||
let runtime = Config::runtime().await.latest_arc();
|
||||
if core_running && runtime.config.as_ref().is_some_and(needs_public_dns) {
|
||||
if core_running
|
||||
&& runtime
|
||||
.config
|
||||
.as_ref()
|
||||
.is_some_and(clash_verge_config_render::needs_public_dns)
|
||||
{
|
||||
set_public_dns(guard).await;
|
||||
} else {
|
||||
let _ = unset_public_dns(guard).await;
|
||||
|
||||
Reference in New Issue
Block a user