refactor(config): remove the unused runtime patch API

This commit is contained in:
Tunglies
2026-12-03 20:56:41 +08:00
parent 63000f39f5
commit 6cce982f58
3 changed files with 7 additions and 45 deletions
@@ -68,8 +68,8 @@ pub fn use_sort(mut config: Mapping) -> Mapping {
}
#[inline]
pub fn use_keys<'a>(config: &'a Mapping) -> impl Iterator<Item = String> + 'a {
config.iter().filter_map(|(key, _)| key.as_str()).map(|s: &str| {
pub(super) fn lowercase_config_keys(config: &Mapping) -> impl Iterator<Item = String> {
config.keys().filter_map(Value::as_str).map(|s: &str| {
let mut s: String = s.into();
s.make_ascii_lowercase();
s
+5 -6
View File
@@ -4,11 +4,10 @@ mod script;
mod seq;
mod tun;
pub use field::use_keys;
pub use seq::SeqMap;
use self::{
field::{use_lowercase, use_sort},
field::{lowercase_config_keys, use_lowercase, use_sort},
merge::use_merge,
script::use_script,
seq::use_seq,
@@ -90,7 +89,7 @@ async fn process_override_items<Fut: Future<Output = ScriptOutcome> + Send>(
execute_script: &(impl Fn(String, serde_json::Value, String) -> Fut + Sync),
) -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
if let ChainType::Merge(merge) = &merge_item.data {
exists_keys.extend(use_keys(merge));
exists_keys.extend(lowercase_config_keys(merge));
let before = authoritative.current(&config);
config = use_merge(merge.clone(), config);
let notes: ResultLog = authoritative
@@ -666,7 +665,7 @@ pub async fn render<Fut: Future<Output = ScriptOutcome> + Send>(
let result_map = HashMap::new();
let config = process_seq_items(config, rules_item, proxies_item, groups_item);
let exists_keys = use_keys(&config).collect::<Vec<_>>();
let exists_keys = lowercase_config_keys(&config).collect::<Vec<_>>();
let gui_tun_keys = gui_tun_keys(&clash_config);
let config = merge_default_config(
@@ -1186,7 +1185,7 @@ mod authoritative_field_tests {
mod tests {
use super::{
AuthoritativeFields, ChainItem, ChainType, Mapping, ScriptOutcome, String, cleanup_proxy_groups,
ensure_lan_bind_address, process_override_items, use_keys,
ensure_lan_bind_address, lowercase_config_keys, process_override_items,
};
use std::collections::HashMap;
use std::future::{Ready, ready};
@@ -1299,7 +1298,7 @@ hosts: {script.example: "192.0.2.4"}"#;
r"{global-merge-wins: other, global-script-wins: other, profile-merge-wins: other,
profile-script-wins: other, nested: {winner: other}, dns: {enable: true}, tun: {enable: true}}",
);
let exists_keys = use_keys(&config).collect();
let exists_keys = lowercase_config_keys(&config).collect();
config.insert("application-only".into(), true.into());
let global_merge = Arc::new(ChainItem {
-37
View File
@@ -2,10 +2,6 @@ use serde_yaml_ng::{Mapping, Value};
use std::collections::{HashMap, HashSet};
use tristr::alias::String;
use clash_verge_config_render::use_keys;
const PATCH_CONFIG_INNER: [&str; 5] = ["allow-lan", "ipv6", "log-level", "unified-delay", "tunnels"];
#[derive(Default, Clone)]
pub struct IRuntime {
pub config: Option<Mapping>,
@@ -17,39 +13,6 @@ pub struct IRuntime {
}
impl IRuntime {
#[inline]
pub fn patch_config(&mut self, patch: &Mapping) {
let config = if let Some(config) = self.config.as_mut() {
config
} else {
return;
};
for key in PATCH_CONFIG_INNER.iter() {
if let Some(value) = patch.get(key) {
config.insert((*key).into(), value.clone());
}
}
let Some(patch_tun) = patch.get("tun") else {
return;
};
let tun_key = Value::from("tun");
if !matches!(config.get(&tun_key), Some(Value::Mapping(_))) {
config.insert(tun_key.clone(), Value::Mapping(Mapping::new()));
}
if let (Some(patch_tun_mapping), Some(Value::Mapping(tun))) = (patch_tun.as_mapping(), config.get_mut(&tun_key))
{
for key in use_keys(patch_tun_mapping) {
if let Some(value) = patch_tun_mapping.get(key.as_str()) {
tun.insert(Value::from(key.as_str()), value.clone());
}
}
}
}
/// Rebuilds `dialer-proxy` links from an ordered proxy chain, or removes them for `None`.
#[inline]
pub fn update_proxy_chain_config(&mut self, proxy_chain_config: Option<Value>) {