Skip to content

Commit c39811d

Browse files
committed
fix: optimize rclone update flows
1 parent d221c92 commit c39811d

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

src-tauri/src/cmd/os_operate.rs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
77
use tauri::{AppHandle, State};
88

99
use crate::cmd::openlist_core::OPENLIST_CORE_PROCESS_ID;
10+
use crate::cmd::rclone_mount::stop_all_rclone_mounts;
1011
use crate::core::process_manager::PROCESS_MANAGER;
1112
use crate::object::structs::AppState;
1213
use crate::utils::github_proxy::apply_github_proxy;
@@ -25,8 +26,6 @@ pub struct VersionCache {
2526
pub last_rclone_check_time: SystemTime,
2627
}
2728

28-
const RCLONE_BACKEND_PROCESS_ID: &str = "rclone_backend";
29-
3029
fn normalize_path(path: &str) -> String {
3130
#[cfg(target_os = "windows")]
3231
{
@@ -249,23 +248,19 @@ pub async fn update_tool_version(
249248
state: State<'_, AppState>,
250249
) -> Result<String, String> {
251250
log::info!("Updating {tool} to version {version}");
252-
253-
let process_id = match tool.as_str() {
254-
"openlist" => OPENLIST_CORE_PROCESS_ID,
255-
"rclone" => RCLONE_BACKEND_PROCESS_ID,
256-
_ => return Err("Unsupported tool".to_string()),
257-
};
258-
259-
let was_running = PROCESS_MANAGER.is_running(process_id);
260-
261-
if was_running {
262-
log::info!("Stopping {tool} process");
263-
PROCESS_MANAGER
264-
.stop(process_id)
265-
.map_err(|e| format!("Failed to stop process: {e}"))?;
266-
log::info!("Successfully stopped {tool} process");
251+
if tool.as_str() == "openlist" {
252+
let process_id = OPENLIST_CORE_PROCESS_ID;
253+
let was_running = PROCESS_MANAGER.is_running(process_id);
254+
if was_running {
255+
log::info!("Stopping {tool} process");
256+
PROCESS_MANAGER
257+
.stop(process_id)
258+
.map_err(|e| format!("Failed to stop process: {e}"))?;
259+
log::info!("Successfully stopped {tool} process");
260+
}
261+
} else {
262+
stop_all_rclone_mounts().await?;
267263
}
268-
269264
let gh_proxy = state
270265
.get_settings()
271266
.and_then(|settings| settings.app.gh_proxy.clone());
@@ -280,27 +275,10 @@ pub async fn update_tool_version(
280275
match result {
281276
Ok(_) => {
282277
log::info!("Successfully downloaded and replaced {tool} binary");
283-
284-
if was_running {
285-
log::info!("Starting {tool} process");
286-
PROCESS_MANAGER
287-
.start(process_id)
288-
.map_err(|e| format!("Failed to start {tool} process: {e}"))?;
289-
log::info!("Successfully restarted {tool} process");
290-
}
291-
292278
Ok(format!("Successfully updated {tool} to {version}"))
293279
}
294280
Err(e) => {
295281
log::error!("Failed to update {tool} binary: {e}");
296-
297-
if was_running {
298-
log::info!(
299-
"Attempting to restart {tool} with previous binary after update failure"
300-
);
301-
let _ = PROCESS_MANAGER.start(process_id);
302-
}
303-
304282
Err(format!("Failed to update {tool} to {version}: {e}"))
305283
}
306284
}

src-tauri/src/cmd/rclone_mount.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,15 @@ pub async fn get_mount_info_list(
295295

296296
Ok(mount_infos)
297297
}
298+
299+
pub async fn stop_all_rclone_mounts() -> Result<(), String> {
300+
let process_list = PROCESS_MANAGER.list();
301+
for process in process_list {
302+
if process.id.starts_with("rclone_mount_") {
303+
if process.is_running {
304+
PROCESS_MANAGER.stop(&process.id)?;
305+
}
306+
}
307+
}
308+
Ok(())
309+
}

0 commit comments

Comments
 (0)