From 220a49469252a0acbc9eeb3418ce97e70ec2ff93 Mon Sep 17 00:00:00 2001 From: GyDi Date: Wed, 2 Mar 2022 01:13:31 +0800 Subject: [PATCH] chore: adjust log field --- src-tauri/src/core/clash.rs | 4 ++-- src-tauri/src/core/verge.rs | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/core/clash.rs b/src-tauri/src/core/clash.rs index 811890b..0105f4f 100644 --- a/src-tauri/src/core/clash.rs +++ b/src-tauri/src/core/clash.rs @@ -128,8 +128,8 @@ impl Clash { tauri::async_runtime::spawn(async move { while let Some(event) = rx.recv().await { match event { - CommandEvent::Stdout(line) => log::info!("[stdout]: {}", line), - CommandEvent::Stderr(err) => log::error!("[stderr]: {}", err), + CommandEvent::Stdout(line) => log::info!("[clash]: {}", line), + CommandEvent::Stderr(err) => log::error!("[clash]: {}", err), _ => {} } } diff --git a/src-tauri/src/core/verge.rs b/src-tauri/src/core/verge.rs index 67f85c4..01fad60 100644 --- a/src-tauri/src/core/verge.rs +++ b/src-tauri/src/core/verge.rs @@ -1,5 +1,6 @@ use crate::{ core::Clash, + log_if_err, utils::{config, dirs, sysopt::SysProxyConfig}, }; use anyhow::{bail, Result}; @@ -58,13 +59,18 @@ impl VergeConfig { /// Verge App abilities #[derive(Debug)] pub struct Verge { + /// manage the verge config pub config: VergeConfig, - pub old_sysproxy: Option, - + /// current system proxy setting pub cur_sysproxy: Option, - pub auto_launch: Option, + /// record the original system proxy + /// recover it when exit + old_sysproxy: Option, + + /// helps to auto launch the app + auto_launch: Option, /// record whether the guard async is running or not guard_state: Arc>, @@ -282,7 +288,7 @@ impl Verge { loop { sleep(Duration::from_secs(wait_secs)).await; - log::debug!("[Guard]: heartbeat detection"); + log::debug!("guard heartbeat detection"); let verge = Verge::new(); @@ -298,7 +304,7 @@ impl Verge { break; } - log::info!("[Guard]: try to guard proxy"); + log::info!("try to guard proxy"); let clash = Clash::new(); @@ -307,12 +313,9 @@ impl Verge { let bypass = verge.config.system_proxy_bypass.clone(); let sysproxy = SysProxyConfig::new(true, port.clone(), bypass); - if let Err(err) = sysproxy.set_sys() { - log::error!("[Guard]: {err}"); - log::error!("[Guard]: fail to set system proxy"); - } + log_if_err!(sysproxy.set_sys()); } - None => log::error!("[Guard]: fail to parse clash port"), + None => log::error!("fail to parse clash port"), } }