#[cfg(not(target_arch = "wasm32"))]
mod native;
#[cfg(target_arch = "wasm32")]
mod web;
use super::{DialogBackend, DialogReply, FileDialog};
use std::sync::Arc;
#[derive(Clone, Copy, Debug, Default)]
pub struct SystemDialogs;
impl DialogBackend for SystemDialogs {
fn launch(
&mut self,
dialog: &FileDialog,
parent: Option<&Arc<winit::window::Window>>,
reply: DialogReply,
) {
#[cfg(not(target_arch = "wasm32"))]
native::launch(dialog, parent, reply);
#[cfg(target_arch = "wasm32")]
{
let _ = parent;
web::launch(dialog, reply);
}
}
}
fn configure(dialog: &FileDialog) -> rfd::AsyncFileDialog {
let mut builder = rfd::AsyncFileDialog::new();
if let Some(title) = dialog.title_text() {
builder = builder.set_title(title);
}
if let Some(directory) = dialog.start_directory() {
builder = builder.set_directory(directory);
}
if let Some(name) = dialog.default_file_name() {
builder = builder.set_file_name(name);
}
for filter in dialog.filters() {
builder = builder.add_filter(filter.name(), filter.extensions());
}
builder
}