rfd/
backend.rs

1use crate::FileHandle;
2use std::future::Future;
3use std::path::PathBuf;
4use std::pin::Pin;
5
6#[cfg(target_os = "linux")]
7mod gtk3;
8#[cfg(target_os = "macos")]
9mod macos;
10#[cfg(target_arch = "wasm32")]
11mod wasm;
12#[cfg(target_os = "windows")]
13mod win_cid;
14
15//
16// Sync
17//
18
19/// Dialog used to pick file/files
20pub trait FilePickerDialogImpl {
21    fn pick_file(self) -> Option<PathBuf>;
22    fn pick_files(self) -> Option<Vec<PathBuf>>;
23}
24
25/// Dialog used to save file
26pub trait FileSaveDialogImpl {
27    fn save_file(self) -> Option<PathBuf>;
28}
29
30/// Dialog used to pick folder
31pub trait FolderPickerDialogImpl {
32    fn pick_folder(self) -> Option<PathBuf>;
33}
34
35pub trait MessageDialogImpl {
36    fn show(self) -> bool;
37}
38
39//
40// Async
41//
42
43// Return type of async dialogs:
44#[cfg(not(target_arch = "wasm32"))]
45pub type DialogFutureType<T> = Pin<Box<dyn Future<Output = T> + Send>>;
46#[cfg(target_arch = "wasm32")]
47pub type DialogFutureType<T> = Pin<Box<dyn Future<Output = T>>>;
48
49/// Dialog used to pick file/files
50pub trait AsyncFilePickerDialogImpl {
51    fn pick_file_async(self) -> DialogFutureType<Option<FileHandle>>;
52    fn pick_files_async(self) -> DialogFutureType<Option<Vec<FileHandle>>>;
53}
54
55/// Dialog used to pick folder
56pub trait AsyncFolderPickerDialogImpl {
57    fn pick_folder_async(self) -> DialogFutureType<Option<FileHandle>>;
58}
59
60/// Dialog used to pick folder
61pub trait AsyncFileSaveDialogImpl {
62    fn save_file_async(self) -> DialogFutureType<Option<FileHandle>>;
63}
64
65pub trait AsyncMessageDialogImpl {
66    fn show_async(self) -> DialogFutureType<bool>;
67}