diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 1f13a7c..d2b0bab 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -202,11 +202,13 @@ pub fn get_clash_info(clash_state: State<'_, ClashState>) -> Result, + verge_state: State<'_, VergeState>, profiles_state: State<'_, ProfilesState>, ) -> Result<(), String> { let mut clash = clash_state.0.lock().unwrap(); + let mut verge = verge_state.0.lock().unwrap(); let mut profiles = profiles_state.0.lock().unwrap(); - clash.patch_config(payload, &mut profiles) + clash.patch_config(payload, &mut verge, &mut profiles) } /// get the system proxy diff --git a/src-tauri/src/core/clash.rs b/src-tauri/src/core/clash.rs index e212cbd..8b74cc6 100644 --- a/src-tauri/src/core/clash.rs +++ b/src-tauri/src/core/clash.rs @@ -1,4 +1,4 @@ -use super::ProfilesConfig; +use super::{ProfilesConfig, Verge}; use crate::utils::{config, dirs}; use serde::{Deserialize, Serialize}; use serde_yaml::{Mapping, Value}; @@ -170,6 +170,7 @@ impl Clash { pub fn patch_config( &mut self, patch: Mapping, + verge: &mut Verge, profiles: &mut ProfilesConfig, ) -> Result<(), String> { for (key, value) in patch.iter() { @@ -179,12 +180,25 @@ impl Clash { // restart the clash if key_str == "mixed-port" { self.restart_sidecar(profiles)?; + + let port = if value.is_number() { + match value.as_i64().clone() { + Some(num) => Some(format!("{num}")), + None => None, + } + } else { + match value.as_str().clone() { + Some(num) => Some(num.into()), + None => None, + } + }; + verge.init_sysproxy(port); } if self.config.contains_key(key) { - self.config[key] = value.clone(); + self.config[key] = value; } else { - self.config.insert(key.clone(), value.clone()); + self.config.insert(key.clone(), value); } } self.save_config() diff --git a/src-tauri/src/core/verge.rs b/src-tauri/src/core/verge.rs index eab6350..c75d406 100644 --- a/src-tauri/src/core/verge.rs +++ b/src-tauri/src/core/verge.rs @@ -161,6 +161,24 @@ impl Verge { } } + // fn guard_thread(&mut self) -> Result<(), String> { + // let sysproxy = self.cur_sysproxy.clone(); + + // use std::{thread, time}; + // tauri::async_runtime::spawn(async move { + // if let Some(sysproxy) = sysproxy { + // sysproxy.set_sys(); + // } + + // let ten_millis = time::Duration::from_millis(10); + // let now = time::Instant::now(); + + // thread::sleep(ten_millis); + // }); + + // Ok(()) + // } + /// patch verge config /// There should be only one update at a time here /// so call the save_file at the end is savely