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::{HandleError, HasDisplayHandle, HasWindowHandle};
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("Handle error: {0}")]
20    Handle(HandleError),
21    #[error("Could not initialize COM")]
22    CouldNotInitializeCOM,
23}
24
25#[cfg(any(target_os = "windows", target_os = "macos"))]
26#[derive(Debug, Clone, Copy)]
27pub enum BlockingDialogLevel {
28    Info,
29    Warning,
30    Error,
31}
32
33#[cfg(any(target_os = "windows", target_os = "macos"))]
34#[derive(Debug, Clone)]
35pub struct BlockingAlertDialog<'a, W: HasWindowHandle + HasDisplayHandle> {
36    pub window: W,
37    pub title: &'a str,
38    pub message: &'a str,
39    pub level: BlockingDialogLevel,
40}
41
42#[cfg(any(target_os = "windows", target_os = "macos"))]
43#[derive(Debug, Clone)]
44pub struct BlockingConfirmDialog<'a, W: HasWindowHandle + HasDisplayHandle> {
45    pub window: W,
46    pub title: &'a str,
47    pub message: &'a str,
48    pub level: BlockingDialogLevel,
49}
50
51#[derive(Debug, Clone)]
52pub struct BlockingPickFilesDialogFilter<'a> {
53    pub name: &'a str,
54    pub extensions: &'a [&'a str],
55}
56
57#[derive(Debug, Clone)]
58pub struct BlockingPickFilesDialog<'a, W: HasWindowHandle + HasDisplayHandle> {
59    pub window: W,
60    pub title: &'a str,
61    pub multiple: bool,
62    pub filter: &'a [BlockingPickFilesDialogFilter<'a>],
63}
64
65#[derive(Debug, Clone)]
66pub struct BlockingPickDirectoryDialog<'a, W: HasWindowHandle + HasDisplayHandle> {
67    pub window: W,
68    pub title: &'a str,
69}
70
71#[derive(Debug, Clone)]
72pub struct BlockingSaveFileDialog<'a, W: HasWindowHandle + HasDisplayHandle> {
73    pub window: W,
74    pub title: &'a str,
75    pub default_filename: Option<&'a str>,
76    pub filter: &'a [BlockingPickFilesDialogFilter<'a>],
77}