mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
perf: change patch_config parameter from Mapping to &Mapping for efficiency
This commit is contained in:
@@ -29,7 +29,7 @@ pub async fn get_clash_info() -> CmdResult<ClashInfo> {
|
||||
/// 修改Clash配置
|
||||
#[tauri::command]
|
||||
pub async fn patch_clash_config(payload: Mapping) -> CmdResult {
|
||||
feat::patch_clash(payload).await.stringify_err()
|
||||
feat::patch_clash(&payload).await.stringify_err()
|
||||
}
|
||||
|
||||
/// 修改Clash模式
|
||||
@@ -171,7 +171,7 @@ pub async fn apply_dns_config(apply: bool) -> CmdResult {
|
||||
|
||||
// 应用DNS配置到运行时配置
|
||||
Config::runtime().await.edit_draft(|d| {
|
||||
d.patch_config(patch);
|
||||
d.patch_config(&patch);
|
||||
});
|
||||
|
||||
// 重新生成配置
|
||||
|
||||
@@ -16,7 +16,6 @@ pub struct IClashTemp(pub Mapping);
|
||||
|
||||
impl IClashTemp {
|
||||
pub async fn new() -> Self {
|
||||
let template = Self::template();
|
||||
let clash_path_result = dirs::clash_path();
|
||||
let map_result = if let Ok(path) = clash_path_result {
|
||||
help::read_mapping(&path).await
|
||||
@@ -26,24 +25,26 @@ impl IClashTemp {
|
||||
|
||||
match map_result {
|
||||
Ok(mut map) => {
|
||||
template.0.keys().for_each(|key| {
|
||||
if !map.contains_key(key)
|
||||
&& let Some(value) = template.0.get(key)
|
||||
{
|
||||
map.insert(key.clone(), value.clone());
|
||||
let template_map = Self::template().0;
|
||||
for (key, value) in template_map.into_iter() {
|
||||
if !map.contains_key(&key) {
|
||||
map.insert(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 确保 secret 字段存在且不为空
|
||||
if let Some(Value::String(s)) = map.get_mut("secret")
|
||||
if let Some(val) = map.get_mut("secret")
|
||||
&& let Value::String(s) = val
|
||||
&& s.is_empty()
|
||||
{
|
||||
*s = "set-your-secret".into();
|
||||
}
|
||||
|
||||
Self(Self::guard(map))
|
||||
}
|
||||
Err(err) => {
|
||||
logging!(error, Type::Config, "{err}");
|
||||
template
|
||||
Self::template()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,9 +145,9 @@ impl IClashTemp {
|
||||
config
|
||||
}
|
||||
|
||||
pub fn patch_config(&mut self, patch: Mapping) {
|
||||
for (key, value) in patch.into_iter() {
|
||||
self.0.insert(key, value);
|
||||
pub fn patch_config(&mut self, patch: &Mapping) {
|
||||
for (key, value) in patch.iter() {
|
||||
self.0.insert(key.to_owned(), value.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ pub async fn change_clash_mode(mode: String) {
|
||||
// 更新订阅
|
||||
Config::clash()
|
||||
.await
|
||||
.edit_draft(|d| d.patch_config(mapping));
|
||||
.edit_draft(|d| d.patch_config(&mapping));
|
||||
|
||||
// 分离数据获取和异步调用
|
||||
let clash_data = Config::clash().await.data_arc();
|
||||
|
||||
@@ -9,10 +9,8 @@ use clash_verge_logging::{Type, logging, logging_error};
|
||||
use serde_yaml_ng::Mapping;
|
||||
|
||||
/// Patch Clash configuration
|
||||
pub async fn patch_clash(patch: Mapping) -> Result<()> {
|
||||
Config::clash()
|
||||
.await
|
||||
.edit_draft(|d| d.patch_config(patch.clone()));
|
||||
pub async fn patch_clash(patch: &Mapping) -> Result<()> {
|
||||
Config::clash().await.edit_draft(|d| d.patch_config(patch));
|
||||
|
||||
let res = {
|
||||
// 激活订阅
|
||||
|
||||
Reference in New Issue
Block a user