From 462fb05ea8617471ac73360d7304215f25231ef7 Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Mon, 11 Mar 2024 22:52:29 +0800 Subject: [PATCH] fix: Try to fix #577 again --- src-tauri/src/core/core.rs | 35 ----------------------------------- src-tauri/src/enhance/tun.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index 7d403e3..cf0cd84 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -105,24 +105,6 @@ impl CoreManager { sleep(Duration::from_millis(500)).await; } - #[cfg(target_os = "macos")] - { - let enable_tun = Config::verge().latest().enable_tun_mode.clone(); - let enable_tun = enable_tun.unwrap_or(false); - log::debug!(target: "app", "try to set system dns"); - if enable_tun { - let resource_dir = dirs::app_resources_dir()?; - let script = resource_dir.join("set_dns.sh"); - let script = script.to_string_lossy(); - match (|| Command::new("bash").args([script]).output())() { - Ok(_) => return Ok(()), - Err(err) => { - log::error!(target: "app", "{err}"); - } - } - } - } - #[cfg(target_os = "windows")] { use super::win_service; @@ -264,23 +246,6 @@ impl CoreManager { }); return Ok(()); } - #[cfg(target_os = "macos")] - { - let enable_tun = Config::verge().latest().enable_tun_mode.clone(); - let enable_tun = enable_tun.unwrap_or(false); - log::debug!(target: "app", "try to unset system dns"); - if enable_tun { - let resource_dir = dirs::app_resources_dir()?; - let script = resource_dir.join("unset_dns.sh"); - let script = script.to_string_lossy(); - match (|| Command::new("bash").args([script]).output())() { - Ok(_) => return Ok(()), - Err(err) => { - log::error!(target: "app", "{err}"); - } - } - } - } let mut sidecar = self.sidecar.lock(); if let Some(child) = sidecar.take() { diff --git a/src-tauri/src/enhance/tun.rs b/src-tauri/src/enhance/tun.rs index 5987088..ba58748 100644 --- a/src-tauri/src/enhance/tun.rs +++ b/src-tauri/src/enhance/tun.rs @@ -34,8 +34,38 @@ pub fn use_tun(mut config: Mapping, enable: bool) -> Mapping { revise!(config, "tun", tun_val); if enable { + #[cfg(target_os = "macos")] + { + use crate::utils::dirs; + use tauri::api::process::Command; + log::info!(target: "app", "try to set system dns"); + let resource_dir = dirs::app_resources_dir().unwrap(); + let script = resource_dir.join("set_dns.sh"); + let script = script.to_string_lossy(); + match Command::new("bash").args([script]).output() { + Ok(_) => log::info!(target: "app", "set system dns successfully"), + Err(err) => { + log::error!(target: "app", "set system dns failed: {err}"); + } + } + } use_dns_for_tun(config) } else { + #[cfg(target_os = "macos")] + { + use crate::utils::dirs; + use tauri::api::process::Command; + log::info!(target: "app", "try to unset system dns"); + let resource_dir = dirs::app_resources_dir().unwrap(); + let script = resource_dir.join("unset_dns.sh"); + let script = script.to_string_lossy(); + match Command::new("bash").args([script]).output() { + Ok(_) => log::info!(target: "app", "unset system dns successfully"), + Err(err) => { + log::error!(target: "app", "unset system dns failed: {err}"); + } + } + } config } }