Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add methods and implement traits for FilePath and SafeFilePath #1727

Merged
merged 9 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changes/fs-dialog-file-path-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"fs": patch
"dialog": patch
---

Add utility methods on `FilePath` and `SafeFilePath` enums which are:

- `path`
- `simplified`
- `into_path`
6 changes: 6 additions & 0 deletions .changes/fs-dialog-file-path-traits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"fs": patch
"dialog": patch
---

Implement `Serialize`, `Deserialize`, `From`, `TryFrom` and `FromStr` traits for `FilePath` and `SafeFilePath` enums.
6 changes: 6 additions & 0 deletions .changes/fs-dialog-non-exhaustive-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"fs": patch
"dialog": patch
---

Mark `Error` enum as `#[non_exhuastive]`.
6 changes: 6 additions & 0 deletions .changes/fs-dialog-safe-file-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"fs": patch
"dialog": patch
---

Add `SafeFilePath` enum.
134 changes: 106 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resolver = "2"
[workspace.dependencies]
serde = { version = "1", features = ["derive"] }
log = "0.4"
tauri = { version = "2.0.0-rc.8", default-features = false }
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "feat/serialize-safe-pathbuf", default-features = false }
tauri-build = "2.0.0-rc.7"
tauri-plugin = "2.0.0-rc.7"
tauri-utils = "2.0.0-rc.7"
Expand Down
1 change: 0 additions & 1 deletion plugins/dialog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ serde_json = { workspace = true }
tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
dunce = { workspace = true }
url = { workspace = true }
tauri-plugin-fs = { path = "../fs", version = "2.0.0-rc.1" }

Expand Down
10 changes: 5 additions & 5 deletions plugins/dialog/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub(crate) async fn open<R: Runtime>(
let folders = dialog_builder.blocking_pick_folders();
if let Some(folders) = &folders {
for folder in folders {
if let Ok(path) = folder.path() {
if let Ok(path) = folder.clone().into_path() {
if let Some(s) = window.try_fs_scope() {
s.allow_directory(path, options.recursive);
}
Expand All @@ -149,7 +149,7 @@ pub(crate) async fn open<R: Runtime>(
} else {
let folder = dialog_builder.blocking_pick_folder();
if let Some(folder) = &folder {
if let Ok(path) = folder.path() {
if let Ok(path) = folder.clone().into_path() {
if let Some(s) = window.try_fs_scope() {
s.allow_directory(path, options.recursive);
}
Expand All @@ -164,7 +164,7 @@ pub(crate) async fn open<R: Runtime>(
let files = dialog_builder.blocking_pick_files();
if let Some(files) = &files {
for file in files {
if let Ok(path) = file.path() {
if let Ok(path) = file.clone().into_path() {
if let Some(s) = window.try_fs_scope() {
s.allow_file(&path);
}
Expand All @@ -178,7 +178,7 @@ pub(crate) async fn open<R: Runtime>(
let file = dialog_builder.blocking_pick_file();

if let Some(file) = &file {
if let Ok(path) = file.path() {
if let Ok(path) = file.clone().into_path() {
if let Some(s) = window.try_fs_scope() {
s.allow_file(&path);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ pub(crate) async fn save<R: Runtime>(

let path = dialog_builder.blocking_save_file();
if let Some(p) = &path {
if let Ok(path) = p.path() {
if let Ok(path) = p.clone().into_path() {
if let Some(s) = window.try_fs_scope() {
s.allow_file(&path);
}
Expand Down
Loading
Loading