feat: Remove UNC prefix in paths returned to the frontend (#1168)

* feat: Remove UNC prefix in paths returned to the frontend

* that one doesn't count

* map instead of mut

* revert accidental ipc::response change

* move dunce to workspace root
pull/1217/head
Fabian-Lars 1 year ago committed by GitHub
parent 6698774f3f
commit bb51a41d67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,7 @@
---
dialog: patch
fs: patch
store: patch
---
**Breaking Change:** All apis that return paths to the frontend will now remove the `\\?\` UNC prefix on Windows.

2
Cargo.lock generated

@ -6227,6 +6227,7 @@ dependencies = [
name = "tauri-plugin-dialog"
version = "2.0.0-beta.4"
dependencies = [
"dunce",
"log",
"raw-window-handle 0.6.0",
"rfd",
@ -6464,6 +6465,7 @@ dependencies = [
name = "tauri-plugin-store"
version = "2.0.0-beta.4"
dependencies = [
"dunce",
"log",
"serde",
"serde_json",

@ -17,6 +17,7 @@ serde_json = "1"
thiserror = "1"
url = "2"
schemars = "0.8"
dunce = "1"
[workspace.package]
edition = "2021"

@ -23,6 +23,7 @@ serde_json = { workspace = true }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
dunce = { workspace = true }
tauri-plugin-fs = { path = "../fs", version = "2.0.0-beta.4" }
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]

@ -129,7 +129,12 @@ pub(crate) async fn open<R: Runtime>(
}
}
}
OpenResponse::Folders(folders)
OpenResponse::Folders(folders.map(|folders| {
folders
.iter()
.map(|p| dunce::simplified(p).to_path_buf())
.collect()
}))
} else {
let folder = dialog_builder.blocking_pick_folder();
if let Some(path) = &folder {
@ -137,7 +142,7 @@ pub(crate) async fn open<R: Runtime>(
s.allow_directory(path, options.recursive);
}
}
OpenResponse::Folder(folder)
OpenResponse::Folder(folder.map(|p| dunce::simplified(&p).to_path_buf()))
}
}
#[cfg(mobile)]
@ -154,7 +159,15 @@ pub(crate) async fn open<R: Runtime>(
.allow_file(&file.path)?;
}
}
OpenResponse::Files(files)
OpenResponse::Files(files.map(|files| {
files
.into_iter()
.map(|mut f| {
f.path = dunce::simplified(&f.path).to_path_buf();
f
})
.collect()
}))
} else {
let file = dialog_builder.blocking_pick_file();
if let Some(file) = &file {
@ -165,7 +178,10 @@ pub(crate) async fn open<R: Runtime>(
.state::<tauri::scope::Scopes>()
.allow_file(&file.path)?;
}
OpenResponse::File(file)
OpenResponse::File(file.map(|mut f| {
f.path = dunce::simplified(&f.path).to_path_buf();
f
}))
};
Ok(res)
}
@ -208,7 +224,7 @@ pub(crate) async fn save<R: Runtime>(
window.state::<tauri::scope::Scopes>().allow_file(p)?;
}
Ok(path)
Ok(path.map(|p| dunce::simplified(&p).to_path_buf()))
}
}

@ -22,3 +22,4 @@ serde_json = { workspace = true }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
dunce = { workspace = true }

@ -58,7 +58,8 @@ impl<R: Runtime> StoreBuilder<R> {
/// ```
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self {
path: path.as_ref().to_path_buf(),
// Since Store.path is only exposed to the user in emit calls we may as well simplify it here already.
path: dunce::simplified(path.as_ref()).to_path_buf(),
defaults: None,
cache: Default::default(),
serialize: default_serialize,

Loading…
Cancel
Save