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