Skip to main content

blocking_dialog/
lib.rs

1// SPDX-FileCopyrightText: 2026 Manuel Quarneti <mq1@ik.me>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4#[cfg_attr(target_os = "macos", path = "macos/mod.rs")]
5#[cfg_attr(target_os = "linux", path = "linux/mod.rs")]
6#[cfg_attr(target_os = "windows", path = "windows/mod.rs")]
7mod os_dialog;
8
9use raw_window_handle::WindowHandle;
10use std::io;
11use thiserror::Error;
12
13#[derive(Error, Debug)]
14pub enum BlockingDialogError {
15    #[error("The dialog is not running on the main thread")]
16    NotOnMainThread,
17    #[error("IO error: {0}")]
18    Io(#[from] io::Error),
19    #[error("Unsupported windowing system")]
20    UnsupportedWindowingSystem,
21}
22
23#[derive(Debug, Clone, Copy)]
24pub enum BlockingDialogLevel {
25    Info,
26    Warning,
27    Error,
28}
29
30#[derive(Debug, Clone)]
31pub struct BlockingAlertDialog<'a> {
32    pub window: WindowHandle<'a>,
33    pub title: &'a str,
34    pub message: &'a str,
35    pub level: BlockingDialogLevel,
36}
37
38#[derive(Debug, Clone)]
39pub struct BlockingConfirmDialog<'a> {
40    pub window: WindowHandle<'a>,
41    pub title: &'a str,
42    pub message: &'a str,
43    pub level: BlockingDialogLevel,
44}
45
46#[derive(Debug, Clone)]
47pub struct BlockingPickFilesDialogFilter<'a> {
48    name: &'a str,
49    extensions: &'a [&'a str],
50}
51
52#[derive(Debug, Clone)]
53pub struct BlockingPickFilesDialog<'a> {
54    pub window: WindowHandle<'a>,
55    pub title: &'a str,
56    pub multiple: bool,
57    pub filter: &'a [BlockingPickFilesDialogFilter<'a>],
58}