Przeglądaj źródła

fix: Try to fix #577 again

MystiPanda 1 rok temu
rodzic
commit
462fb05ea8
2 zmienionych plików z 30 dodań i 35 usunięć
  1. 0 35
      src-tauri/src/core/core.rs
  2. 30 0
      src-tauri/src/enhance/tun.rs

+ 0 - 35
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() {

+ 30 - 0
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
     }
 }