feat: optimize rclone backend status check method

This commit is contained in:
Kuingsmile
2025-07-23 11:38:06 +08:00
parent a6c83fe289
commit 9277c9380c
3 changed files with 52 additions and 10 deletions

34
src-tauri/Cargo.lock generated
View File

@@ -2601,6 +2601,15 @@ dependencies = [
"version_check",
]
[[package]]
name = "ntapi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4"
dependencies = [
"winapi",
]
[[package]]
name = "num-conv"
version = "0.1.0"
@@ -2790,6 +2799,16 @@ dependencies = [
"objc2-core-foundation",
]
[[package]]
name = "objc2-io-kit"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71c1c64d6120e51cd86033f67176b1cb66780c2efe34dec55176f77befd93c0a"
dependencies = [
"libc",
"objc2-core-foundation",
]
[[package]]
name = "objc2-io-surface"
version = "0.3.1"
@@ -2917,6 +2936,7 @@ dependencies = [
"runas",
"serde",
"serde_json",
"sysinfo",
"tar",
"tauri",
"tauri-build",
@@ -4492,6 +4512,20 @@ dependencies = [
"syn 2.0.104",
]
[[package]]
name = "sysinfo"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "252800745060e7b9ffb7b2badbd8b31cfa4aa2e61af879d0a3bf2a317c20217d"
dependencies = [
"libc",
"memchr",
"ntapi",
"objc2-core-foundation",
"objc2-io-kit",
"windows",
]
[[package]]
name = "system-configuration"
version = "0.6.1"

View File

@@ -45,6 +45,7 @@ zip = "4.2.0"
tar = "0.4.44"
flate2 = "1.1.2"
regex = "1.11.1"
sysinfo = "0.36.1"
[target.'cfg(windows)'.dependencies]
runas = "=1.2.0"

View File

@@ -1,6 +1,5 @@
use std::time::Duration;
use reqwest::{self, Client};
use reqwest;
use sysinfo::System;
use tauri::State;
use crate::cmd::http_api::{get_process_list, start_process};
@@ -108,13 +107,21 @@ pub async fn get_rclone_backend_status(_state: State<'_, AppState>) -> Result<bo
}
async fn is_rclone_running() -> bool {
let client = Client::new();
log::info!("Checking if Rclone is running...");
let mut system = System::new_all();
system.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
let response = client
.get(format!("{RCLONE_API_BASE}/"))
.timeout(Duration::from_secs(3))
.send()
.await;
for (_pid, process) in system.processes() {
let process_name = process.name().to_string_lossy().to_lowercase();
response.is_ok()
if process_name.contains("rclone") {
let cmd_args = process.cmd();
if cmd_args.iter().any(|arg| arg == "rcd") {
return true;
}
}
}
log::info!("Rclone is not running");
false
}