File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
use rfd:: AsyncFileDialog ;
2
2
use std:: {
3
3
path:: PathBuf ,
4
- sync:: { Arc , Weak } ,
4
+ sync:: {
5
+ atomic:: { AtomicBool , Ordering } ,
6
+ Arc , Weak ,
7
+ } ,
5
8
} ;
6
9
use winit:: window:: Window ;
7
10
@@ -12,16 +15,25 @@ pub struct FilePicker {
12
15
13
16
struct FilePickerData {
14
17
parent : Weak < Window > ,
18
+ picking : AtomicBool ,
15
19
}
16
20
17
21
impl FilePicker {
18
22
pub fn new ( parent : Weak < Window > ) -> Self {
19
23
Self {
20
- data : Arc :: new ( FilePickerData { parent } ) ,
24
+ data : Arc :: new ( FilePickerData {
25
+ parent,
26
+ picking : AtomicBool :: new ( false ) ,
27
+ } ) ,
21
28
}
22
29
}
23
30
24
31
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
+
25
37
let mut dialog = AsyncFileDialog :: new ( )
26
38
. add_filter ( "Flash Files" , & [ "swf" , "spl" , "ruf" ] )
27
39
. add_filter ( "All Files" , & [ "*" ] )
@@ -35,6 +47,8 @@ impl FilePicker {
35
47
dialog = dialog. set_parent ( & parent) ;
36
48
}
37
49
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
39
53
}
40
54
}
You can’t perform that action at this time.
0 commit comments