From 5e418bd6e5e2a5d77757b402cbd52b4bfc3a9f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91=E5=85=88=E6=A3=AE?= Date: Thu, 28 Nov 2024 10:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=AD=E5=BC=80=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=90=8E=E6=88=90=E5=91=98=E5=88=97=E8=A1=A8=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=8D=A1=E6=AD=BB=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/member.vue | 9 ++++----- src-tauri/Cargo.lock | 6 ++++-- src-tauri/Cargo.toml | 1 + src-tauri/src/lib.rs | 8 +++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pages/member.vue b/pages/member.vue index cf6d653..522bcf4 100644 --- a/pages/member.vue +++ b/pages/member.vue @@ -134,6 +134,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window"; return ""; } if (member === "_EasytierGameCliFailedToConnect_") { + data.member = []; stopTimer(); const [error] = await ElConfirmDanger("连接已断开,是否重新尝试?", "警告", { confirmButtonText: "重试", @@ -145,7 +146,6 @@ import { getCurrentWindow } from "@tauri-apps/api/window"; const appWindow = getCurrentWindow(); await appWindow.close(); } - data.member = []; return; } const peerInfo = parsePeerInfo(member); @@ -161,10 +161,10 @@ import { getCurrentWindow } from "@tauri-apps/api/window"; startTimer(); }; - const startTimer = async () => { + const startTimer = () => { timer && clearTimeout(timer); - timer = setTimeout(async () => { - await listenOutput(); + timer = setTimeout(() => { + listenOutput(); }, 1000); }; @@ -175,7 +175,6 @@ import { getCurrentWindow } from "@tauri-apps/api/window"; onMounted(async () => { await listenOutput(); - await startTimer(); }); onBeforeUnmount(() => { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 81ac597..dace403 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1193,6 +1193,7 @@ dependencies = [ "tauri-plugin-shell", "tauri-plugin-single-instance", "tauri-plugin-window-state", + "tokio", "whoami", "windows 0.58.0", "zip", @@ -4782,15 +4783,16 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", "libc", "mio", "pin-project-lite", + "signal-hook-registry", "socket2", "windows-sys 0.52.0", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7fc0329..90e28f9 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -40,6 +40,7 @@ planif = { git = "https://github.com/mattrobineau/planif", tag = "1.0.1" } whoami = "1.5.2" tauri-plugin-fs = "2" tauri-plugin-clipboard-manager = "2.0.2" +tokio = { version = "1.41.1", features = ["process"] } # prost = "0.13" # prost-types = "0.13" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c3eb65c..8a62158 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -21,6 +21,8 @@ use windows::Win32::Foundation::VARIANT_BOOL; use windows::Win32::System::Com::*; use windows::Win32::System::TaskScheduler::*; +use tokio::process::Command as tokioCommand; + // 定义GitHub Release的结构体 #[derive(Debug, Deserialize)] pub struct Release { @@ -130,13 +132,13 @@ struct MyResponse { } #[tauri::command(rename_all = "snake_case")] -fn get_members_by_cli() -> String { +async fn get_members_by_cli() -> String { let cli_path = get_tool_exe_path(String::from("\\easytier\\easytier-cli.exe")); - match Command::new(&cli_path) + match tokioCommand::new(&cli_path) .arg("peer") .arg("list") .creation_flags(0x08000000) - .output() + .output().await { Ok(output) => { if output.status.success() {