Add a facility for delaying quit until critical tasks finish

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Max Brunsfeld 2021-11-01 11:56:49 -07:00
parent 6e5ec2a00d
commit b8994c2a89
7 changed files with 70 additions and 4 deletions

View file

@ -265,6 +265,18 @@ impl App {
self
}
pub fn on_quit<F>(self, mut callback: F) -> Self
where
F: 'static + FnMut(&mut MutableAppContext),
{
let cx = self.0.clone();
self.0
.borrow_mut()
.foreground_platform
.on_quit(Box::new(move || callback(&mut *cx.borrow_mut())));
self
}
pub fn on_event<F>(self, mut callback: F) -> Self
where
F: 'static + FnMut(Event, &mut MutableAppContext) -> bool,