Skip to content

Commit 231f21e

Browse files
lucasfernogSir-Thom
authored andcommitted
fix(dialog): update asset protocol scope on directory open, closes tauri-apps#1553 (tauri-apps#1769)
1 parent 4b1494a commit 231f21e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.changes/dialog-asset-scope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dialog": patch
3+
---
4+
5+
Update Tauri scopes (asset protocol) when using the `open()` command to select directories.

plugins/dialog/src/commands.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,17 @@ pub(crate) async fn open<R: Runtime>(
132132
let res = if options.directory {
133133
#[cfg(desktop)]
134134
{
135+
let tauri_scope = window.state::<tauri::scope::Scopes>();
136+
135137
if options.multiple {
136138
let folders = dialog_builder.blocking_pick_folders();
137139
if let Some(folders) = &folders {
138140
for folder in folders {
139141
if let Ok(path) = folder.clone().into_path() {
140142
if let Some(s) = window.try_fs_scope() {
141-
s.allow_directory(path, options.recursive);
143+
s.allow_directory(&path, options.recursive);
142144
}
145+
tauri_scope.allow_directory(&path, options.directory)?;
143146
}
144147
}
145148
}
@@ -151,8 +154,9 @@ pub(crate) async fn open<R: Runtime>(
151154
if let Some(folder) = &folder {
152155
if let Ok(path) = folder.clone().into_path() {
153156
if let Some(s) = window.try_fs_scope() {
154-
s.allow_directory(path, options.recursive);
157+
s.allow_directory(&path, options.recursive);
155158
}
159+
tauri_scope.allow_directory(&path, options.directory)?;
156160
}
157161
}
158162
OpenResponse::Folder(folder.map(|p| p.simplified()))
@@ -161,6 +165,8 @@ pub(crate) async fn open<R: Runtime>(
161165
#[cfg(mobile)]
162166
return Err(crate::Error::FolderPickerNotImplemented);
163167
} else if options.multiple {
168+
let tauri_scope = window.state::<tauri::scope::Scopes>();
169+
164170
let files = dialog_builder.blocking_pick_files();
165171
if let Some(files) = &files {
166172
for file in files {
@@ -169,20 +175,21 @@ pub(crate) async fn open<R: Runtime>(
169175
s.allow_file(&path);
170176
}
171177

172-
window.state::<tauri::scope::Scopes>().allow_file(&path)?;
178+
tauri_scope.allow_file(&path)?;
173179
}
174180
}
175181
}
176182
OpenResponse::Files(files.map(|files| files.into_iter().map(|f| f.simplified()).collect()))
177183
} else {
184+
let tauri_scope = window.state::<tauri::scope::Scopes>();
178185
let file = dialog_builder.blocking_pick_file();
179186

180187
if let Some(file) = &file {
181188
if let Ok(path) = file.clone().into_path() {
182189
if let Some(s) = window.try_fs_scope() {
183190
s.allow_file(&path);
184191
}
185-
window.state::<tauri::scope::Scopes>().allow_file(&path)?;
192+
tauri_scope.allow_file(&path)?;
186193
}
187194
}
188195
OpenResponse::File(file.map(|f| f.simplified()))
@@ -216,13 +223,15 @@ pub(crate) async fn save<R: Runtime>(
216223
dialog_builder = dialog_builder.add_filter(filter.name, &extensions);
217224
}
218225

226+
let tauri_scope = window.state::<tauri::scope::Scopes>();
227+
219228
let path = dialog_builder.blocking_save_file();
220229
if let Some(p) = &path {
221230
if let Ok(path) = p.clone().into_path() {
222231
if let Some(s) = window.try_fs_scope() {
223232
s.allow_file(&path);
224233
}
225-
window.state::<tauri::scope::Scopes>().allow_file(&path)?;
234+
tauri_scope.allow_file(&path)?;
226235
}
227236
}
228237

0 commit comments

Comments
 (0)