feat: manage clash config

This commit is contained in:
GyDi
2022-01-21 02:31:44 +08:00
parent 177c283011
commit 39bd9641f4
6 changed files with 122 additions and 85 deletions

View File

@@ -1,6 +1,4 @@
use crate::utils::dirs;
use serde::{de::DeserializeOwned, Serialize};
use serde_yaml::Mapping;
use std::{fs, path::PathBuf};
/// read data from yaml as struct T
@@ -32,17 +30,3 @@ pub fn save_yaml<T: Serialize>(
Err(_) => Err("can not convert the data to yaml".into()),
}
}
/// Get Clash Core Config `config.yaml`
pub fn read_clash() -> Mapping {
read_yaml::<Mapping>(dirs::app_home_dir().join("config.yaml"))
}
/// Save the clash core Config `config.yaml`
pub fn save_clash(config: &Mapping) -> Result<(), String> {
save_yaml(
dirs::app_home_dir().join("config.yaml"),
config,
Some("# Default Config For Clash Core\n\n"),
)
}