From 5098f14aabeae8ab5553a3edc154080d30b38a53 Mon Sep 17 00:00:00 2001 From: GyDi Date: Tue, 22 Nov 2022 20:46:46 +0800 Subject: [PATCH] fix: service mode error and fallback to sidecar --- src-tauri/src/core/core.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index 4829c6c..830e51b 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -107,16 +107,18 @@ impl CoreManager { if enable { // 服务模式启动失败就直接运行sidecar - match { - log::debug!(target: "app", "try to run core in service mode"); + log::debug!(target: "app", "try to run core in service mode"); + + match (|| async { win_service::check_service().await?; win_service::run_core_by_service(&config_path).await - } { + })() + .await + { Ok(_) => return Ok(()), Err(err) => { // 修改这个值,免得stop出错 *self.use_service_mode.lock() = false; - log::error!(target: "app", "{err}"); } } @@ -141,7 +143,7 @@ impl CoreManager { let (mut rx, cmd_child) = cmd.args(args).spawn()?; // 将pid写入文件中 - crate::log_err!({ + crate::log_err!((|| { let pid = cmd_child.pid(); let path = dirs::clash_pid_path()?; fs::File::create(path) @@ -149,7 +151,7 @@ impl CoreManager { .write(format!("{pid}").as_bytes()) .context("failed to write pid to the file")?; >::Ok(()) - }); + })()); let mut sidecar = self.sidecar.lock(); *sidecar = Some(cmd_child);