From da8ed1ac5a0268770b7ab5138f3e8ef16785acf1 Mon Sep 17 00:00:00 2001 From: huzibaca Date: Wed, 23 Oct 2024 04:46:47 +0800 Subject: [PATCH] fix: failed to install service on macos --- src-tauri/src/core/service.rs | 8 +++++--- src-tauri/src/utils/init.rs | 2 +- src-tauri/src/utils/resolve.rs | 12 ++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 66dd1936..d4d5a93a 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -138,12 +138,14 @@ pub async fn reinstall_service() -> Result<()> { bail!(format!("uninstaller not found: {uninstall_path:?}")); } - let install_shell: String = install_path.to_string_lossy().replace(" ", "\\ "); - let uninstall_shell: String = uninstall_path.to_string_lossy().replace(" ", "\\ "); + let install_shell: String = install_path.to_string_lossy().into_owned(); + let uninstall_shell: String = uninstall_path.to_string_lossy().into_owned(); let command = format!( - r#"do shell script "sudo {uninstall_shell} && sudo {install_shell}" with administrator privileges"# + r#"do shell script "sudo '{uninstall_shell}' && sudo '{install_shell}'" with administrator privileges"# ); + log::debug!(target: "app", "command: {}", command); + let status = StdCommand::new("osascript") .args(vec!["-e", &command]) .status()?; diff --git a/src-tauri/src/utils/init.rs b/src-tauri/src/utils/init.rs index 609012af..1cb509ea 100644 --- a/src-tauri/src/utils/init.rs +++ b/src-tauri/src/utils/init.rs @@ -206,7 +206,7 @@ pub fn init_resources() -> Result<()> { let src_path = res_dir.join(file); let dest_path = app_dir.join(file); let test_dest_path = test_dir.join(file); - log::info!(target: "app", "src_path: {src_path:?}, dest_path: {dest_path:?}"); + log::debug!(target: "app", "src_path: {src_path:?}, dest_path: {dest_path:?}"); let handle_copy = |dest: &PathBuf| { match fs::copy(&src_path, dest) { diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index 28b6adc9..055905b1 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -54,8 +54,16 @@ pub async fn resolve_setup(app: &mut App) { log_err!(Config::init_config().await); if service::check_service().await.is_err() { - log_err!(service::reinstall_service().await); - std::thread::sleep(std::time::Duration::from_millis(1000)); + match service::reinstall_service().await { + Ok(_) => { + log::info!(target:"app", "install service susccess."); + std::thread::sleep(std::time::Duration::from_millis(1000)); + } + Err(e) => { + log::error!(target: "app", "{e:?}"); + app.app_handle().exit(-1); + } + } } log::trace!(target: "app", "launch core");