From 4a7ee4dcf5fe4e0fc8ffd4c6df3d70523100824e Mon Sep 17 00:00:00 2001 From: lencx Date: Tue, 24 Jan 2023 16:24:49 +0800 Subject: [PATCH] fix: windows path (#242) --- src-tauri/src/utils.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 9945bcd..8afe5bb 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -66,20 +66,33 @@ pub fn user_script() -> String { } pub fn open_file(path: PathBuf) { - info!("open_file: {}", path.to_string_lossy()); + let pathname = convert_path(path.to_str().unwrap()); + info!("open_file: {}", pathname); #[cfg(target_os = "macos")] - Command::new("open").arg("-R").arg(path).spawn().unwrap(); + Command::new("open") + .arg("-R") + .arg(pathname) + .spawn() + .unwrap(); #[cfg(target_os = "windows")] - Command::new("explorer") + Command::new("explorer.exe") .arg("/select,") - .arg(path) + .arg(pathname) .spawn() .unwrap(); // https://askubuntu.com/a/31071 #[cfg(target_os = "linux")] - Command::new("xdg-open").arg(path).spawn().unwrap(); + Command::new("xdg-open").arg(pathname).spawn().unwrap(); +} + +pub fn convert_path(path_str: &str) -> String { + if cfg!(target_os = "windows") { + path_str.replace('/', "\\") + } else { + String::from(path_str) + } } pub fn clear_conf(app: &tauri::AppHandle) {