fix: change mixed port error

This commit is contained in:
GyDi 2022-03-18 11:39:02 +08:00 committed by GitHub
parent a3e7626dd9
commit ef314c1707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -192,31 +192,32 @@ impl Clash {
verge: &mut Verge, verge: &mut Verge,
profiles: &mut Profiles, profiles: &mut Profiles,
) -> Result<()> { ) -> Result<()> {
for (key, value) in patch.iter() { let mix_port_key = Value::from("mixed-port");
let mut port = None;
for (key, value) in patch.into_iter() {
let value = value.clone(); let value = value.clone();
let key_str = key.as_str().clone().unwrap_or("");
// restart the clash // check whether the mix_port is changed
if key_str == "mixed-port" { if key == mix_port_key {
self.restart_sidecar(profiles)?; if value.is_number() {
port = value.as_i64().as_ref().map(|n| n.to_string());
let port = if value.is_number() {
match value.as_i64().clone() {
Some(num) => Some(format!("{num}")),
None => None,
}
} else { } else {
match value.as_str().clone() { port = value.as_str().as_ref().map(|s| s.to_string());
Some(num) => Some(num.into()),
None => None,
} }
};
verge.init_sysproxy(port);
} }
self.config.insert(key.clone(), value); self.config.insert(key.clone(), value);
} }
self.save_config()
self.save_config()?;
if let Some(port) = port {
self.restart_sidecar(profiles)?;
verge.init_sysproxy(Some(port));
}
Ok(())
} }
/// enable tun mode /// enable tun mode