1
0
mirror of https://github.com/lencx/ChatGPT.git synced 2024-10-01 01:06:13 -04:00

fix: windows path (#242)

This commit is contained in:
lencx 2023-01-24 16:24:49 +08:00
parent f1e528d3a7
commit 4a7ee4dcf5

View File

@ -66,20 +66,33 @@ pub fn user_script() -> String {
} }
pub fn open_file(path: PathBuf) { 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")] #[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")] #[cfg(target_os = "windows")]
Command::new("explorer") Command::new("explorer.exe")
.arg("/select,") .arg("/select,")
.arg(path) .arg(pathname)
.spawn() .spawn()
.unwrap(); .unwrap();
// https://askubuntu.com/a/31071 // https://askubuntu.com/a/31071
#[cfg(target_os = "linux")] #[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) { pub fn clear_conf(app: &tauri::AppHandle) {