diff --git a/crates/dialogs/src/lib.rs b/crates/dialogs/src/lib.rs index 7ba0e73a2..4c21b1852 100644 --- a/crates/dialogs/src/lib.rs +++ b/crates/dialogs/src/lib.rs @@ -289,12 +289,18 @@ pub struct Dialogs { open: Option>, answers: Vec<(T, Answer)>, show: Show, + hook: Option, } impl Dialogs { /// A dialog queue that calls `wake` when an answer arrives. pub fn new(wake: Wake) -> Self { - Self { wake, queue: VecDeque::new(), open: None, answers: Vec::new(), show: Show::Native } + Self { wake, queue: VecDeque::new(), open: None, answers: Vec::new(), show: Show::Native, hook: None } + } + + /// Runs `hook` around every native dialog's blocking show. + pub fn set_show_hook(&mut self, hook: ShowHook) { + self.hook = Some(hook); } /// Queues a file dialog. It shows at the next [`Self::show_pending`] once the dialogs asked @@ -328,7 +334,19 @@ impl Dialogs { // A panic while showing (rfd's own checks) must not unwind into winit's handler. let shown = match &mut self.show { Show::Override(answer_with) => catch_unwind(AssertUnwindSafe(|| reply.send(answer_with(&request)))).map(|()| None), - Show::Native => catch_unwind(AssertUnwindSafe(|| native::show(request, parent, reply))), + Show::Native => catch_unwind(AssertUnwindSafe(|| { + let (mut asked, mut shown) = (Some((request, reply)), None); + let mut run = || { + if let Some((request, reply)) = asked.take() { + shown = Some(native::show(request, parent, reply)); + } + }; + match &mut self.hook { + Some(hook) => hook(&mut run), + None => run(), + } + shown.flatten() + })), #[cfg(test)] Show::Custom(show) => catch_unwind(AssertUnwindSafe(|| show(request, reply))).map(|()| None), }; diff --git a/crates/dialogs/src/service.rs b/crates/dialogs/src/service.rs index 17d9d27c9..9ec9760ec 100644 --- a/crates/dialogs/src/service.rs +++ b/crates/dialogs/src/service.rs @@ -319,9 +319,9 @@ impl FilePanels { } /// Runs `hook` around every native dialog's blocking show, so the app can mark the wait as waiting for the user. - pub fn show_hook(self, hook: crate::ShowHook) -> Self { - let _ = hook; - todo!("q348") + pub fn show_hook(mut self, hook: crate::ShowHook) -> Self { + self.dialogs.set_show_hook(hook); + self } /// Sets whether the panels ask the Replace question when the native panel did not.