Files
clash-verge-rev/src-tauri/src/core/verge.rs
T

122 lines
2.8 KiB
Rust
Raw Normal View History

2022-04-20 01:44:47 +08:00
use crate::utils::{config, dirs};
2022-04-20 11:17:54 +08:00
use anyhow::Result;
2021-12-14 15:55:29 +08:00
use serde::{Deserialize, Serialize};
/// ### `verge.yaml` schema
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
2022-04-20 11:17:54 +08:00
pub struct Verge {
/// app listening port
/// for app singleton
pub app_singleton_port: Option<u16>,
2022-03-12 23:07:45 +08:00
// i18n
pub language: Option<String>,
2021-12-19 23:56:16 +08:00
/// `light` or `dark`
pub theme_mode: Option<String>,
2022-01-12 02:27:29 +08:00
/// enable blur mode
/// maybe be able to set the alpha
pub theme_blur: Option<bool>,
2022-02-19 18:14:40 +08:00
/// enable traffic graph default is true
pub traffic_graph: Option<bool>,
2022-02-25 02:09:39 +08:00
/// clash tun mode
pub enable_tun_mode: Option<bool>,
2022-04-24 21:00:17 +08:00
/// windows service mode
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_service_mode: Option<bool>,
2021-12-19 23:56:16 +08:00
/// can the app auto startup
pub enable_auto_launch: Option<bool>,
2021-12-19 23:56:16 +08:00
2022-03-26 18:56:16 +08:00
/// not show the window on launch
pub enable_silent_start: Option<bool>,
2021-12-19 23:56:16 +08:00
/// set system proxy
pub enable_system_proxy: Option<bool>,
2021-12-27 02:29:28 +08:00
2022-02-20 18:53:21 +08:00
/// enable proxy guard
pub enable_proxy_guard: Option<bool>,
2021-12-27 02:29:28 +08:00
/// set system proxy bypass
pub system_proxy_bypass: Option<String>,
2022-02-20 20:11:39 +08:00
/// proxy guard duration
pub proxy_guard_duration: Option<u64>,
2022-03-31 23:11:50 +08:00
/// theme setting
pub theme_setting: Option<VergeTheme>,
2022-05-16 01:52:50 +08:00
2022-08-06 21:56:54 +08:00
/// web ui list
pub web_ui_list: Option<Vec<String>>,
2022-05-16 01:52:50 +08:00
/// clash core path
#[serde(skip_serializing_if = "Option::is_none")]
pub clash_core: Option<String>,
2022-03-31 23:11:50 +08:00
}
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct VergeTheme {
pub primary_color: Option<String>,
pub secondary_color: Option<String>,
2022-03-31 23:34:36 +08:00
pub primary_text: Option<String>,
pub secondary_text: Option<String>,
2022-03-31 23:11:50 +08:00
pub info_color: Option<String>,
pub error_color: Option<String>,
pub warning_color: Option<String>,
pub success_color: Option<String>,
pub font_family: Option<String>,
2022-04-01 02:08:42 +08:00
pub css_injection: Option<String>,
2021-12-14 15:55:29 +08:00
}
2022-01-07 23:29:20 +08:00
2022-04-20 11:17:54 +08:00
impl Verge {
2022-01-07 23:29:20 +08:00
pub fn new() -> Self {
2022-04-20 11:17:54 +08:00
config::read_yaml::<Verge>(dirs::verge_path())
2022-01-07 23:29:20 +08:00
}
/// Save Verge App Config
2022-02-28 01:34:25 +08:00
pub fn save_file(&self) -> Result<()> {
2022-01-07 23:29:20 +08:00
config::save_yaml(
2022-02-28 01:34:25 +08:00
dirs::verge_path(),
2022-01-07 23:29:20 +08:00
self,
Some("# The Config for Clash Verge App\n\n"),
)
}
2022-01-11 02:24:43 +08:00
/// patch verge config
2022-04-20 01:44:47 +08:00
/// only save to file
2022-04-20 11:17:54 +08:00
pub fn patch_config(&mut self, patch: Verge) -> Result<()> {
2022-08-06 21:56:54 +08:00
macro_rules! patch {
($key: tt) => {
if patch.$key.is_some() {
self.$key = patch.$key;
}
};
2022-05-16 01:52:50 +08:00
}
2022-01-11 02:24:43 +08:00
2022-08-06 21:56:54 +08:00
patch!(language);
patch!(theme_mode);
patch!(theme_blur);
patch!(traffic_graph);
2022-01-11 02:24:43 +08:00
2022-08-06 21:56:54 +08:00
patch!(enable_tun_mode);
patch!(enable_service_mode);
patch!(enable_auto_launch);
patch!(enable_silent_start);
patch!(enable_system_proxy);
patch!(enable_proxy_guard);
patch!(system_proxy_bypass);
patch!(proxy_guard_duration);
2022-02-20 18:53:21 +08:00
2022-08-06 21:56:54 +08:00
patch!(theme_setting);
patch!(web_ui_list);
patch!(clash_core);
2022-02-25 02:09:39 +08:00
2022-04-20 11:17:54 +08:00
self.save_file()
2022-01-11 02:24:43 +08:00
}
2022-02-20 18:53:21 +08:00
}