From ae43e5cae4af47d3da193e27545bc431d73700c4 Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Wed, 1 May 2024 11:39:09 +0800 Subject: [PATCH] fix: change script execution path --- src-tauri/src/enhance/tun.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/enhance/tun.rs b/src-tauri/src/enhance/tun.rs index ba587486..2cd4e115 100644 --- a/src-tauri/src/enhance/tun.rs +++ b/src-tauri/src/enhance/tun.rs @@ -42,8 +42,19 @@ pub fn use_tun(mut config: Mapping, enable: bool) -> Mapping { 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"), + match Command::new("bash") + .args([script]) + .current_dir(resource_dir) + .status() + { + Ok(status) => { + if status.success() { + log::info!(target: "app", "set system dns successfully"); + } else { + let code = status.code().unwrap_or(-1); + log::error!(target: "app", "set system dns failed: {code}"); + } + } Err(err) => { log::error!(target: "app", "set system dns failed: {err}"); } @@ -59,8 +70,19 @@ pub fn use_tun(mut config: Mapping, enable: bool) -> Mapping { 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"), + match Command::new("bash") + .args([script]) + .current_dir(resource_dir) + .status() + { + Ok(status) => { + if status.success() { + log::info!(target: "app", "unset system dns successfully"); + } else { + let code = status.code().unwrap_or(-1); + log::error!(target: "app", "unset system dns failed: {code}"); + } + } Err(err) => { log::error!(target: "app", "unset system dns failed: {err}"); }