mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:43:44 +08:00
fix: when tun is closed, the full profile configuration is not restored
This commit is contained in:
parent
2ac27fcfa7
commit
7d65ce847a
@ -60,7 +60,7 @@ pub async fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
|
|||||||
global_merge,
|
global_merge,
|
||||||
global_script,
|
global_script,
|
||||||
profile_name,
|
profile_name,
|
||||||
dns_enhanced_mode,
|
dns,
|
||||||
) = {
|
) = {
|
||||||
let profiles = Config::profiles();
|
let profiles = Config::profiles();
|
||||||
let profiles = profiles.latest();
|
let profiles = profiles.latest();
|
||||||
@ -131,12 +131,9 @@ pub async fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
|
|||||||
.and_then(|item| item.name.clone())
|
.and_then(|item| item.name.clone())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let dns_enhanced_mode = current
|
let dns = current.get("dns").map_or(Mapping::new(), |val| {
|
||||||
.get("dns")
|
val.as_mapping().cloned().unwrap_or(Mapping::new())
|
||||||
.and_then(|val| val.get("enhanced-mode"))
|
});
|
||||||
.and_then(|val| val.as_str())
|
|
||||||
.unwrap_or("redir-host")
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
(
|
(
|
||||||
current,
|
current,
|
||||||
@ -148,7 +145,7 @@ pub async fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
|
|||||||
global_merge,
|
global_merge,
|
||||||
global_script,
|
global_script,
|
||||||
name,
|
name,
|
||||||
dns_enhanced_mode,
|
dns,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -268,7 +265,7 @@ pub async fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
config = use_tun(config, enable_tun, dns_enhanced_mode).await;
|
config = use_tun(config, enable_tun, dns).await;
|
||||||
config = use_sort(config);
|
config = use_sort(config);
|
||||||
|
|
||||||
let mut exists_set = HashSet::new();
|
let mut exists_set = HashSet::new();
|
||||||
|
@ -18,7 +18,7 @@ macro_rules! append {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn use_tun(mut config: Mapping, enable: bool, origin_enhanced_mode: String) -> Mapping {
|
pub async fn use_tun(mut config: Mapping, enable: bool, origin_dns_val: Mapping) -> Mapping {
|
||||||
let tun_key = Value::from("tun");
|
let tun_key = Value::from("tun");
|
||||||
let tun_val = config.get(&tun_key);
|
let tun_val = config.get(&tun_key);
|
||||||
let mut tun_val = tun_val.map_or(Mapping::new(), |val| {
|
let mut tun_val = tun_val.map_or(Mapping::new(), |val| {
|
||||||
@ -41,7 +41,42 @@ pub async fn use_tun(mut config: Mapping, enable: bool, origin_enhanced_mode: St
|
|||||||
crate::utils::resolve::set_public_dns("8.8.8.8".to_string()).await;
|
crate::utils::resolve::set_public_dns("8.8.8.8".to_string()).await;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
revise!(dns_val, "enhanced-mode", origin_enhanced_mode.as_str());
|
revise!(
|
||||||
|
dns_val,
|
||||||
|
"enable",
|
||||||
|
origin_dns_val
|
||||||
|
.get("enable")
|
||||||
|
.and_then(|v| v.as_bool())
|
||||||
|
.unwrap_or(true)
|
||||||
|
);
|
||||||
|
|
||||||
|
revise!(
|
||||||
|
dns_val,
|
||||||
|
"ipv6",
|
||||||
|
origin_dns_val
|
||||||
|
.get("ipv6")
|
||||||
|
.and_then(|v| v.as_bool())
|
||||||
|
.unwrap_or(true)
|
||||||
|
);
|
||||||
|
|
||||||
|
revise!(
|
||||||
|
dns_val,
|
||||||
|
"enhanced-mode",
|
||||||
|
origin_dns_val
|
||||||
|
.get("enhanced-mode")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("redir-host")
|
||||||
|
);
|
||||||
|
|
||||||
|
revise!(
|
||||||
|
dns_val,
|
||||||
|
"fake-ip-range",
|
||||||
|
origin_dns_val
|
||||||
|
.get("fake-ip-range")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("198.18.0.1/16")
|
||||||
|
);
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
crate::utils::resolve::restore_public_dns().await;
|
crate::utils::resolve::restore_public_dns().await;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user