Skip to content

Commit 713224c

Browse files
committed
desktop: Allow only one file picker open at a time
1 parent be8be12 commit 713224c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

desktop/src/gui/picker.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use rfd::AsyncFileDialog;
22
use std::{
33
path::PathBuf,
4-
sync::{Arc, Weak},
4+
sync::{
5+
atomic::{AtomicBool, Ordering},
6+
Arc, Weak,
7+
},
58
};
69
use winit::window::Window;
710

@@ -12,16 +15,25 @@ pub struct FilePicker {
1215

1316
struct FilePickerData {
1417
parent: Weak<Window>,
18+
picking: AtomicBool,
1519
}
1620

1721
impl FilePicker {
1822
pub fn new(parent: Weak<Window>) -> Self {
1923
Self {
20-
data: Arc::new(FilePickerData { parent }),
24+
data: Arc::new(FilePickerData {
25+
parent,
26+
picking: AtomicBool::new(false),
27+
}),
2128
}
2229
}
2330

2431
pub async fn pick_file(&self, dir: Option<PathBuf>) -> Option<PathBuf> {
32+
if self.data.picking.swap(true, Ordering::SeqCst) {
33+
// Already picking
34+
return None;
35+
}
36+
2537
let mut dialog = AsyncFileDialog::new()
2638
.add_filter("Flash Files", &["swf", "spl", "ruf"])
2739
.add_filter("All Files", &["*"])
@@ -35,6 +47,8 @@ impl FilePicker {
3547
dialog = dialog.set_parent(&parent);
3648
}
3749

38-
dialog.pick_file().await.map(|h| h.into())
50+
let result = dialog.pick_file().await.map(|h| h.into());
51+
self.data.picking.store(false, Ordering::SeqCst);
52+
result
3953
}
4054
}

0 commit comments

Comments
 (0)