diff --git a/src-tauri/src/core/clash.rs b/src-tauri/src/core/clash.rs index 499191e..0091c85 100644 --- a/src-tauri/src/core/clash.rs +++ b/src-tauri/src/core/clash.rs @@ -328,7 +328,7 @@ impl Clash { if let Some(data) = result.data { // all of these can not be revised by script // http/https/socks port should be under control - let not_allow: Vec = vec![ + let not_allow = vec![ "port", "socks-port", "mixed-port", @@ -337,23 +337,29 @@ impl Clash { "external-controller", "secret", "log-level", - ] - .iter() - .map(|&i| Value::from(i)) - .collect(); + ]; for (key, value) in data.into_iter() { - if not_allow.iter().find(|&i| i == &key).is_none() { - config.insert(key, value); - } + key.as_str().map(|key_str| { + // change to lowercase + let mut key_str = String::from(key_str); + key_str.make_ascii_lowercase(); + + // filter + if !not_allow.contains(&&*key_str) { + config.insert(Value::String(key_str), value); + } + }); } + log::info!("profile enhanced status {}", result.status); + Self::_activate(info, config).unwrap(); } - log::info!("profile enhanced status {}", result.status); - - result.error.map(|error| log::error!("{error}")); + if let Some(error) = result.error { + log::error!("{error}"); + } } }); diff --git a/src-tauri/src/core/profiles.rs b/src-tauri/src/core/profiles.rs index afc1bf5..a7211c1 100644 --- a/src-tauri/src/core/profiles.rs +++ b/src-tauri/src/core/profiles.rs @@ -566,13 +566,17 @@ impl Profiles { "rules", ]; - valid_keys.iter().for_each(|key| { - let key = Value::String(key.to_string()); - if def_config.contains_key(&key) { - let value = def_config[&key].clone(); - new_config.insert(key, value); - } - }); + for (key, value) in def_config.into_iter() { + key.as_str().map(|key_str| { + // change to lowercase + let mut key_str = String::from(key_str); + key_str.make_ascii_lowercase(); + + if valid_keys.contains(&&*key_str) { + new_config.insert(Value::String(key_str), value); + } + }); + } return Ok(new_config); }