mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: verge
This commit is contained in:
@@ -70,8 +70,8 @@ impl Core {
|
||||
let clash = self.clash.lock();
|
||||
let verge = self.verge.lock();
|
||||
|
||||
let silent_start = verge.config.enable_silent_start.clone();
|
||||
let auto_launch = verge.config.enable_auto_launch.clone();
|
||||
let silent_start = verge.enable_silent_start.clone();
|
||||
let auto_launch = verge.enable_auto_launch.clone();
|
||||
|
||||
// silent start
|
||||
if silent_start.unwrap_or(false) {
|
||||
@@ -143,7 +143,7 @@ impl Core {
|
||||
}
|
||||
|
||||
/// Patch Verge
|
||||
pub fn patch_verge(&self, patch: VergeConfig, app_handle: &AppHandle) -> Result<()> {
|
||||
pub fn patch_verge(&self, patch: Verge, app_handle: &AppHandle) -> Result<()> {
|
||||
let tun_mode = patch.enable_tun_mode.clone();
|
||||
let auto_launch = patch.enable_auto_launch.clone();
|
||||
let system_proxy = patch.enable_system_proxy.clone();
|
||||
@@ -195,8 +195,8 @@ impl Core {
|
||||
let verge = self.verge.lock();
|
||||
let tray = app_handle.tray_handle();
|
||||
|
||||
let system_proxy = verge.config.enable_system_proxy.as_ref();
|
||||
let tun_mode = verge.config.enable_tun_mode.as_ref();
|
||||
let system_proxy = verge.enable_system_proxy.as_ref();
|
||||
let tun_mode = verge.enable_tun_mode.as_ref();
|
||||
|
||||
tray
|
||||
.get_item("system_proxy")
|
||||
@@ -235,7 +235,7 @@ impl Core {
|
||||
|
||||
let config = {
|
||||
let verge = self.verge.lock();
|
||||
let tun_mode = verge.config.enable_tun_mode.unwrap_or(false);
|
||||
let tun_mode = verge.enable_tun_mode.unwrap_or(false);
|
||||
Clash::_tun_mode(config, tun_mode)
|
||||
};
|
||||
|
||||
@@ -277,7 +277,7 @@ impl Core {
|
||||
|
||||
let tun_mode = {
|
||||
let verge = self.verge.lock();
|
||||
verge.config.enable_tun_mode.unwrap_or(false)
|
||||
verge.enable_tun_mode.unwrap_or(false)
|
||||
};
|
||||
|
||||
let info = {
|
||||
|
||||
@@ -34,14 +34,14 @@ impl Sysopt {
|
||||
/// init the sysproxy
|
||||
pub fn init_sysproxy(&mut self, port: Option<String>, verge: &Verge) {
|
||||
if let Some(port) = port {
|
||||
let enable = verge.config.enable_system_proxy.clone().unwrap_or(false);
|
||||
let enable = verge.enable_system_proxy.clone().unwrap_or(false);
|
||||
|
||||
self.old_sysproxy = match SysProxyConfig::get_sys() {
|
||||
Ok(proxy) => Some(proxy),
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
let bypass = verge.config.system_proxy_bypass.clone();
|
||||
let bypass = verge.system_proxy_bypass.clone();
|
||||
let sysproxy = SysProxyConfig::new(enable, port, bypass);
|
||||
|
||||
if enable {
|
||||
@@ -173,9 +173,9 @@ impl Sysopt {
|
||||
|
||||
let verge = Verge::new();
|
||||
|
||||
let enable_proxy = verge.config.enable_system_proxy.unwrap_or(false);
|
||||
let enable_guard = verge.config.enable_proxy_guard.unwrap_or(false);
|
||||
let guard_duration = verge.config.proxy_guard_duration.unwrap_or(10);
|
||||
let enable_proxy = verge.enable_system_proxy.unwrap_or(false);
|
||||
let enable_guard = verge.enable_proxy_guard.unwrap_or(false);
|
||||
let guard_duration = verge.proxy_guard_duration.unwrap_or(10);
|
||||
|
||||
// update duration
|
||||
wait_secs = guard_duration;
|
||||
@@ -191,7 +191,7 @@ impl Sysopt {
|
||||
|
||||
match &clash.info.port {
|
||||
Some(port) => {
|
||||
let bypass = verge.config.system_proxy_bypass.clone();
|
||||
let bypass = verge.system_proxy_bypass.clone();
|
||||
let sysproxy = SysProxyConfig::new(true, port.clone(), bypass);
|
||||
|
||||
log_if_err!(sysproxy.set_sys());
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use crate::log_if_err;
|
||||
use crate::utils::{config, dirs};
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// ### `verge.yaml` schema
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct VergeConfig {
|
||||
pub struct Verge {
|
||||
// i18n
|
||||
pub language: Option<String>,
|
||||
|
||||
@@ -60,9 +59,9 @@ pub struct VergeTheme {
|
||||
pub css_injection: Option<String>,
|
||||
}
|
||||
|
||||
impl VergeConfig {
|
||||
impl Verge {
|
||||
pub fn new() -> Self {
|
||||
config::read_yaml::<VergeConfig>(dirs::verge_path())
|
||||
config::read_yaml::<Verge>(dirs::verge_path())
|
||||
}
|
||||
|
||||
/// Save Verge App Config
|
||||
@@ -73,75 +72,54 @@ impl VergeConfig {
|
||||
Some("# The Config for Clash Verge App\n\n"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Verge App abilities
|
||||
#[derive(Debug)]
|
||||
pub struct Verge {
|
||||
/// manage the verge config
|
||||
pub config: VergeConfig,
|
||||
}
|
||||
|
||||
impl Default for Verge {
|
||||
fn default() -> Self {
|
||||
Verge::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Verge {
|
||||
pub fn new() -> Self {
|
||||
Verge {
|
||||
config: VergeConfig::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// patch verge config
|
||||
/// only save to file
|
||||
pub fn patch_config(&mut self, patch: VergeConfig) -> Result<()> {
|
||||
pub fn patch_config(&mut self, patch: Verge) -> Result<()> {
|
||||
// only change it
|
||||
if patch.language.is_some() {
|
||||
self.config.language = patch.language;
|
||||
self.language = patch.language;
|
||||
}
|
||||
if patch.theme_mode.is_some() {
|
||||
self.config.theme_mode = patch.theme_mode;
|
||||
self.theme_mode = patch.theme_mode;
|
||||
}
|
||||
if patch.theme_blur.is_some() {
|
||||
self.config.theme_blur = patch.theme_blur;
|
||||
self.theme_blur = patch.theme_blur;
|
||||
}
|
||||
if patch.theme_setting.is_some() {
|
||||
self.config.theme_setting = patch.theme_setting;
|
||||
self.theme_setting = patch.theme_setting;
|
||||
}
|
||||
if patch.traffic_graph.is_some() {
|
||||
self.config.traffic_graph = patch.traffic_graph;
|
||||
self.traffic_graph = patch.traffic_graph;
|
||||
}
|
||||
|
||||
// system setting
|
||||
if patch.enable_silent_start.is_some() {
|
||||
self.config.enable_silent_start = patch.enable_silent_start;
|
||||
self.enable_silent_start = patch.enable_silent_start;
|
||||
}
|
||||
if patch.enable_auto_launch.is_some() {
|
||||
self.config.enable_auto_launch = patch.enable_auto_launch;
|
||||
self.enable_auto_launch = patch.enable_auto_launch;
|
||||
}
|
||||
|
||||
// proxy
|
||||
if patch.enable_system_proxy.is_some() {
|
||||
self.config.enable_system_proxy = patch.enable_system_proxy;
|
||||
self.enable_system_proxy = patch.enable_system_proxy;
|
||||
}
|
||||
if patch.system_proxy_bypass.is_some() {
|
||||
self.config.system_proxy_bypass = patch.system_proxy_bypass;
|
||||
self.system_proxy_bypass = patch.system_proxy_bypass;
|
||||
}
|
||||
if patch.enable_proxy_guard.is_some() {
|
||||
self.config.enable_proxy_guard = patch.enable_proxy_guard;
|
||||
self.enable_proxy_guard = patch.enable_proxy_guard;
|
||||
}
|
||||
if patch.proxy_guard_duration.is_some() {
|
||||
self.config.proxy_guard_duration = patch.proxy_guard_duration;
|
||||
self.proxy_guard_duration = patch.proxy_guard_duration;
|
||||
}
|
||||
|
||||
// tun mode
|
||||
if patch.enable_tun_mode.is_some() {
|
||||
self.config.enable_tun_mode = patch.enable_tun_mode;
|
||||
self.enable_tun_mode = patch.enable_tun_mode;
|
||||
}
|
||||
|
||||
self.config.save_file()
|
||||
self.save_file()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user