From ac5fb1948aad618021285d54ff079ba1414ea201 Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Mon, 11 Mar 2024 22:03:45 +0800 Subject: [PATCH] fix: Try to fix #577 --- scripts/check.mjs | 12 ++++++++++++ src-tauri/src/core/core.rs | 11 +++++++---- src-tauri/src/core/script/set_dns.sh | 5 ----- src-tauri/src/core/script/unset_dns.sh | 5 ----- 4 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 src-tauri/src/core/script/set_dns.sh delete mode 100644 src-tauri/src/core/script/unset_dns.sh diff --git a/scripts/check.mjs b/scripts/check.mjs index 2c0b493..e33dc10 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -370,6 +370,16 @@ const resolveUninstall = () => file: "uninstall-service.exe", downloadURL: `${SERVICE_URL}/uninstall-service.exe`, }); +const resolveSetDnsScript = () => + resolveResource({ + file: "set_dns.sh", + downloadURL: `https://github.com/clash-verge-rev/set-dns-script/releases/download/script/set_dns.sh`, + }); +const resolveUnSetDnsScript = () => + resolveResource({ + file: "unset_dns.sh", + downloadURL: `https://github.com/clash-verge-rev/set-dns-script/releases/download/script/unset_dns.sh`, + }); const resolveMmdb = () => resolveResource({ file: "Country.mmdb", @@ -409,6 +419,8 @@ const tasks = [ { name: "service", func: resolveService, retry: 5, winOnly: true }, { name: "install", func: resolveInstall, retry: 5, winOnly: true }, { name: "uninstall", func: resolveUninstall, retry: 5, winOnly: true }, + { name: "set_dns_script", fun: resolveSetDnsScript, retry: 5 }, + { name: "unset_dns_script", fun: resolveUnSetDnsScript, retry: 5 }, { name: "mmdb", func: resolveMmdb, retry: 5 }, { name: "geosite", func: resolveGeosite, retry: 5 }, { name: "geoip", func: resolveGeoIP, retry: 5 }, diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index add23be..f2af349 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -111,8 +111,10 @@ impl CoreManager { let enable_tun = enable_tun.unwrap_or(false); log::debug!(target: "app", "try to set system dns"); if enable_tun { - let script = include_str!("./script/set_dns.sh"); - match (|| async { Command::new("bash").args([script]).output() })().await { + 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}"); @@ -262,14 +264,15 @@ 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 script = include_str!("./script/unset_dns.sh"); + 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) => { diff --git a/src-tauri/src/core/script/set_dns.sh b/src-tauri/src/core/script/set_dns.sh deleted file mode 100644 index 25e81cc..0000000 --- a/src-tauri/src/core/script/set_dns.sh +++ /dev/null @@ -1,5 +0,0 @@ -nic=$(route -n get default | grep "interface" | awk '{print $2}') - -hardware_port=$(networksetup -listallhardwareports | awk -v dev="$nic" '/Hardware Port/{port=$3} /Device:/{if ($2 == dev) {print port; exit}}') - -networksetup -setdnsservers $hardware_port 223.5.5.5 \ No newline at end of file diff --git a/src-tauri/src/core/script/unset_dns.sh b/src-tauri/src/core/script/unset_dns.sh deleted file mode 100644 index e06ea93..0000000 --- a/src-tauri/src/core/script/unset_dns.sh +++ /dev/null @@ -1,5 +0,0 @@ -nic=$(route -n get default | grep "interface" | awk '{print $2}') - -hardware_port=$(networksetup -listallhardwareports | awk -v dev="$nic" '/Hardware Port/{port=$3} /Device:/{if ($2 == dev) {print port; exit}}') - -networksetup -setdnsservers $hardware_port Empty \ No newline at end of file