refactor: rename profiles & command state

This commit is contained in:
GyDi
2022-01-21 02:57:15 +08:00
parent 47155a4a29
commit 8d7ab9d05e
5 changed files with 29 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
use super::{ProfilesConfig, Verge};
use super::{Profiles, Verge};
use crate::utils::{config, dirs};
use serde::{Deserialize, Serialize};
use serde_yaml::{Mapping, Value};
@@ -139,7 +139,7 @@ impl Clash {
/// restart clash sidecar
/// should reactivate profile after restart
pub fn restart_sidecar(&mut self, profiles: &mut ProfilesConfig) -> Result<(), String> {
pub fn restart_sidecar(&mut self, profiles: &mut Profiles) -> Result<(), String> {
self.update_config();
self.drop_sidecar()?;
self.run_sidecar()?;
@@ -171,7 +171,7 @@ impl Clash {
&mut self,
patch: Mapping,
verge: &mut Verge,
profiles: &mut ProfilesConfig,
profiles: &mut Profiles,
) -> Result<(), String> {
for (key, value) in patch.iter() {
let value = value.clone();

View File

@@ -11,7 +11,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
/// Define the `profiles.yaml` schema
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct ProfilesConfig {
pub struct Profiles {
/// current profile's name
pub current: Option<usize>,
@@ -63,10 +63,10 @@ pub struct ProfileResponse {
static PROFILE_YAML: &str = "profiles.yaml";
static PROFILE_TEMP: &str = "clash-verge-runtime.yaml";
impl ProfilesConfig {
impl Profiles {
/// read the config from the file
pub fn read_file() -> Self {
config::read_yaml::<ProfilesConfig>(dirs::app_home_dir().join(PROFILE_YAML))
config::read_yaml::<Profiles>(dirs::app_home_dir().join(PROFILE_YAML))
}
/// save the config to the file
@@ -99,7 +99,7 @@ impl ProfilesConfig {
File::create(path).unwrap().write(file_data).unwrap();
// update `profiles.yaml`
let data = ProfilesConfig::read_file();
let data = Profiles::read_file();
let mut items = data.items.unwrap_or(vec![]);
let now = SystemTime::now()