mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-31 03:02:08 +08:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user