diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs index b5cfcf8..5c774dc 100644 --- a/src-tauri/src/config/prfitem.rs +++ b/src-tauri/src/config/prfitem.rs @@ -428,8 +428,10 @@ impl PrfItem { /// create the enhanced item by using `merge` rule pub fn from_merge(uid: Option) -> Result { let mut id = help::get_uid("m"); + let mut template = tmpl::ITEM_MERGE.into(); if let Some(uid) = uid { id = uid; + template = tmpl::ITEM_MERGE_EMPTY.into(); } let file = format!("{id}.yaml"); @@ -445,7 +447,7 @@ impl PrfItem { option: None, home: None, updated: Some(chrono::Local::now().timestamp() as usize), - file_data: Some(tmpl::ITEM_MERGE.into()), + file_data: Some(template), }) } diff --git a/src-tauri/src/enhance/mod.rs b/src-tauri/src/enhance/mod.rs index 0ea77f5..9d0f89c 100644 --- a/src-tauri/src/enhance/mod.rs +++ b/src-tauri/src/enhance/mod.rs @@ -138,8 +138,28 @@ pub async fn enhance() -> (Mapping, Vec, HashMap) { let mut result_map = HashMap::new(); // 保存脚本日志 let mut exists_keys = use_keys(&config); // 保存出现过的keys - // 处理用户的profile + // 全局Merge和Script + if let ChainType::Merge(merge) = global_merge.data { + exists_keys.extend(use_keys(&merge)); + config = use_merge(merge, config.to_owned()); + } + if let ChainType::Script(script) = global_script.data { + let mut logs = vec![]; + + match use_script(script, config.to_owned()) { + Ok((res_config, res_logs)) => { + exists_keys.extend(use_keys(&res_config)); + config = res_config; + logs.extend(res_logs); + } + Err(err) => logs.push(("exception".into(), err.to_string())), + } + + result_map.insert(global_script.uid, logs); + } + + // 订阅关联的Merge、Script、Rules、Proxies、Groups if let ChainType::Rules(rules) = rules_item.data { config = use_seq(rules, config.to_owned(), "rules"); } @@ -172,27 +192,6 @@ pub async fn enhance() -> (Mapping, Vec, HashMap) { result_map.insert(script_item.uid, logs); } - // 全局Merge和Script - if let ChainType::Merge(merge) = global_merge.data { - exists_keys.extend(use_keys(&merge)); - config = use_merge(merge, config.to_owned()); - } - - if let ChainType::Script(script) = global_script.data { - let mut logs = vec![]; - - match use_script(script, config.to_owned()) { - Ok((res_config, res_logs)) => { - exists_keys.extend(use_keys(&res_config)); - config = res_config; - logs.extend(res_logs); - } - Err(err) => logs.push(("exception".into(), err.to_string())), - } - - result_map.insert(global_script.uid, logs); - } - // 合并默认的config for (key, value) in clash_config.into_iter() { if key.as_str() == Some("tun") { diff --git a/src-tauri/src/utils/tmpl.rs b/src-tauri/src/utils/tmpl.rs index be83ca5..15aa926 100644 --- a/src-tauri/src/utils/tmpl.rs +++ b/src-tauri/src/utils/tmpl.rs @@ -15,6 +15,13 @@ pub const ITEM_MERGE: &str = "# Profile Enhancement Merge Template for Clash Ver profile: store-selected: true + +dns: + use-system-hosts: false +"; + +pub const ITEM_MERGE_EMPTY: &str = "# Profile Enhancement Merge Template for Clash Verge + "; /// enhanced profile