[fix] update data lost between page and stutter caused by periodly checking game stats in sync mode

This commit is contained in:
2025-11-09 00:55:19 +08:00
parent 812bc64b6f
commit 0f938f6f3e
10 changed files with 190 additions and 94 deletions

View File

@@ -64,8 +64,8 @@ pub fn kill_game() -> Result<String, String> {
}
#[tauri::command]
pub fn check_process_running(process_name: &str) -> Result<bool, String> {
Ok(common::check_process_running(process_name))
pub async fn check_process_running(process_name: &str) -> Result<bool, String> {
Ok(common::check_process_running_async(process_name).await)
}
#[tauri::command]

View File

@@ -120,6 +120,41 @@ pub fn check_process_running(name: &str) -> bool {
}
}
// 异步版本的进程检测函数
pub async fn check_process_running_async(name: &str) -> bool {
use tokio::process::Command;
// 使用tasklist命令检查进程是否存在
#[cfg(windows)]
{
let mut cmd = Command::new("tasklist");
cmd.args(&["/FI", &format!("IMAGENAME eq {}", name)]);
cmd.creation_flags(CREATE_NO_WINDOW);
match cmd.output().await {
Ok(output) => {
let stdout = String::from_utf8_lossy(&output.stdout);
// 检查输出中是否包含进程名(排除表头)
stdout.contains(name) && stdout.contains("exe")
}
Err(_) => false,
}
}
#[cfg(not(windows))]
{
// 对于非Windows系统可以使用pgrep命令
let mut cmd = Command::new("pgrep");
cmd.arg("-f");
cmd.arg(name);
match cmd.output().await {
Ok(output) => !output.stdout.is_empty(),
Err(_) => false,
}
}
}
mod tests {
#[test]
fn test_open_path() {

View File

@@ -52,7 +52,7 @@
},
"productName": "CS工具箱",
"mainBinaryName": "cstb",
"version": "0.0.6-beta.9",
"version": "0.0.6-beta.8",
"identifier": "upup.cool",
"plugins": {
"deep-link": {