refactor: backend (#7102)

* refactor(tray): move tray log opening to utils helper

* refactor(enhance): move owned config through pipeline

* refactor(enhance): move sequence values in use_seq

* refactor(enhance): move values while sorting fields

* refactor(enhance): move values when lowercasing owned config

* refactor(backend): move owned config values in utilities

* refactor(tray): borrow hotkey accelerators

* refactor(core): borrow proxy config strings

* fix(backend): preserve config patch semantics

* refactor(enhance): clarify config transform names
This commit is contained in:
Tunglies
2026-05-26 10:47:03 +00:00
committed by GitHub
parent a287d13b4d
commit 761209bbbc
11 changed files with 198 additions and 157 deletions
+22 -7
View File
@@ -3,7 +3,7 @@ use anyhow::{Context as _, Result, anyhow, bail};
use clash_verge_logging::{Type, logging};
use nanoid::nanoid;
use serde::{Serialize, de::DeserializeOwned};
use serde_yaml_ng::Mapping;
use serde_yaml_ng::{Mapping, Value};
#[cfg(target_os = "windows")]
use std::path::Path;
use std::{path::PathBuf, str::FromStr};
@@ -35,10 +35,10 @@ pub async fn read_mapping(path: &PathBuf) -> Result<Mapping> {
val.apply_merge()
.with_context(|| format!("failed to apply merge \"{}\"", path.display()))?;
Ok(val
.as_mapping()
.ok_or_else(|| anyhow!("failed to transform to yaml mapping \"{}\"", path.display()))?
.to_owned())
match val {
Value::Mapping(map) => Ok(map),
_ => Err(anyhow!("failed to transform to yaml mapping \"{}\"", path.display())),
}
}
Err(err) => {
let error_msg = format!("YAML syntax error in {}: {}", path.display(), err);
@@ -66,10 +66,9 @@ pub async fn save_yaml<T: Serialize + Sync>(path: &PathBuf, data: &T, prefix: Op
None => data_str,
};
let path_str = path.as_os_str().to_string_lossy().to_string();
tokio::fs::write(path, yaml_str.as_bytes())
.await
.with_context(|| format!("failed to save file \"{path_str}\""))?;
.with_context(|| format!("failed to save file \"{}\"", path.display()))?;
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
Ok(())
}
@@ -203,6 +202,22 @@ pub fn open_file(path: PathBuf) -> Result<()> {
Ok(())
}
pub fn open_latest_log(path: PathBuf) -> Result<()> {
#[cfg(target_os = "windows")]
let path = snapshot_path(&path)?;
open_file(path)
}
pub fn open_app_latest_log() -> Result<()> {
let path = crate::utils::dirs::app_latest_log()?;
open_latest_log(path)
}
pub fn open_core_latest_log() -> Result<()> {
let path = crate::utils::dirs::clash_latest_log()?;
open_latest_log(path)
}
#[cfg(target_os = "linux")]
pub fn linux_elevator() -> String {
use std::process::Command;