mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
refactor: backend (#7102)
* refactor(tray): move tray log opening to utils helper * refactor(enhance): move owned config through pipeline * refactor(enhance): move sequence values in use_seq * refactor(enhance): move values while sorting fields * refactor(enhance): move values when lowercasing owned config * refactor(backend): move owned config values in utilities * refactor(tray): borrow hotkey accelerators * refactor(core): borrow proxy config strings * fix(backend): preserve config patch semantics * refactor(enhance): clarify config transform names
This commit is contained in:
@@ -7,6 +7,7 @@ use clash_verge_logging::{Type, logging};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml_ng::{Mapping, Value};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||
str::FromStr as _,
|
||||
};
|
||||
@@ -267,11 +268,11 @@ impl IClashTemp {
|
||||
let val_str = val_str.trim();
|
||||
|
||||
let val = match val_str.starts_with(':') {
|
||||
true => format!("127.0.0.1{val_str}"),
|
||||
false => val_str.to_owned(),
|
||||
true => Cow::Owned(format!("127.0.0.1{val_str}")),
|
||||
false => Cow::Borrowed(val_str),
|
||||
};
|
||||
|
||||
SocketAddr::from_str(val.as_str()).ok().map(|s| s.to_string())
|
||||
SocketAddr::from_str(&val).ok().map(|s| s.to_string())
|
||||
}
|
||||
None => None,
|
||||
})
|
||||
|
||||
@@ -37,23 +37,22 @@ impl IRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
let patch_tun = patch.get("tun");
|
||||
if let Some(patch_tun_value) = patch_tun {
|
||||
let mut tun = config
|
||||
.get("tun")
|
||||
.and_then(|val| val.as_mapping())
|
||||
.cloned()
|
||||
.unwrap_or_else(Mapping::new);
|
||||
let Some(patch_tun) = patch.get("tun") else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(patch_tun_mapping) = patch_tun_value.as_mapping() {
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
config.insert("tun".into(), Value::from(tun));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user