Skip to content

Commit 089fa6a

Browse files
committed
fix: optimize rclone mount process
1 parent af9ddf1 commit 089fa6a

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src-tauri/src/cmd/rclone_mount.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::collections::HashMap;
22
use std::fs;
33
use std::path::Path;
4-
use std::time::Duration;
54

65
use serde::{Deserialize, Serialize};
76
use serde_json::{Value, json};
87
use tauri::State;
98
use tokio::task::JoinSet;
10-
use tokio::time::timeout;
9+
use tokio::time::{Duration, sleep, timeout};
1110

1211
use crate::conf::rclone_config::{RcloneConfigFile, WebDavRemoteConfig, reveal_password};
1312
use crate::core::process_manager::{PROCESS_MANAGER, ProcessConfig, ProcessInfo};
@@ -153,7 +152,7 @@ pub async fn rclone_delete_remote(
153152
}
154153

155154
#[tauri::command]
156-
pub async fn create_rclone_mount_remote_process(
155+
pub async fn mount_remote(
157156
config: MountProcessInput,
158157
state: State<'_, AppState>,
159158
) -> Result<ProcessInfo, String> {
@@ -202,11 +201,10 @@ pub async fn create_rclone_mount_remote_process(
202201
};
203202

204203
if PROCESS_MANAGER.is_registered(&config.id) {
205-
let info = PROCESS_MANAGER.get_status(&config.id)?;
206-
if !info.is_running {
207-
return PROCESS_MANAGER.start(&config.id);
208-
}
209-
return Ok(info);
204+
let _ = PROCESS_MANAGER.stop(&config.id);
205+
sleep(Duration::from_millis(500)).await;
206+
let _ = PROCESS_MANAGER.remove(&config.id);
207+
sleep(Duration::from_millis(500)).await;
210208
}
211209

212210
PROCESS_MANAGER.register_and_start(process_config)

src-tauri/src/core/process_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl ProcessManager {
725725
pub fn remove(&self, id: &str) -> Result<(), String> {
726726
let mut processes = self.processes.write();
727727

728-
if let Some(_) = processes.remove(id) {
728+
if processes.remove(id).is_some() {
729729
drop(processes);
730730
self.persist_state();
731731
Ok(())

src-tauri/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use cmd::os_operate::{
2323
};
2424
use cmd::rclone_core::check_rclone_available;
2525
use cmd::rclone_mount::{
26-
check_mount_status, create_rclone_mount_remote_process, get_mount_info_list,
27-
rclone_create_remote, rclone_delete_remote, rclone_list_config, rclone_list_remotes,
28-
rclone_update_remote, unmount_remote,
26+
check_mount_status, get_mount_info_list, mount_remote, rclone_create_remote,
27+
rclone_delete_remote, rclone_list_config, rclone_list_remotes, rclone_update_remote,
28+
unmount_remote,
2929
};
3030
use cmd::updater::{get_current_version, is_auto_check_enabled, set_auto_check_enabled};
3131
use object::structs::*;
@@ -170,7 +170,7 @@ async fn auto_mount_rclone_remotes_on_login(app_handle: &tauri::AppHandle) -> Re
170170
name: id.clone(),
171171
args,
172172
};
173-
match create_rclone_mount_remote_process(create_remote_config, app_state.clone()).await {
173+
match mount_remote(create_remote_config, app_state.clone()).await {
174174
Ok(_) => {
175175
log::info!(
176176
"Rclone remote '{}' mounted successfully on login",
@@ -231,7 +231,7 @@ pub fn run() {
231231
rclone_update_remote,
232232
rclone_delete_remote,
233233
// Rclone mount process management
234-
create_rclone_mount_remote_process,
234+
mount_remote,
235235
unmount_remote,
236236
check_mount_status,
237237
get_mount_info_list,

src/api/tauri.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export class TauriAPI {
3434
mounts: {
3535
list: (): Promise<RcloneMountInfo[]> => invoke('get_mount_info_list'),
3636
check: (id: string, mp: string): Promise<boolean> => invoke('check_mount_status', { id, mountPoint: mp }),
37-
mount: (cfg: MountProcessInput): Promise<ProcessInfo> =>
38-
invoke('create_rclone_mount_remote_process', { config: cfg }),
37+
mount: (cfg: MountProcessInput): Promise<ProcessInfo> => invoke('mount_remote', { config: cfg }),
3938
unmount: (name: string): Promise<boolean> => invoke('unmount_remote', { name }),
4039
},
4140
}

0 commit comments

Comments
 (0)