diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c78cc6b5..01ab09df1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,6 +140,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 directly, including getting a reference to the underlying winit Window. - `Modal` is a new layer widget that presents a single widget as a modal session. +- `App::prevent_shutdown()` returns a guard that prevents the application from + closing automatically when the final window is closed. [139]: https://github.com/khonsulabs/cushy/issues/139 diff --git a/Cargo.lock b/Cargo.lock index c6229aca1..f08fb23a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,7 +124,7 @@ checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" [[package]] name = "appit" version = "0.3.2" -source = "git+https://github.com/khonsulabs/appit#93479b81112dfeef2b1646c5050c9fbd305c3288" +source = "git+https://github.com/khonsulabs/appit#331bfdd3534a2f6a7c44f24017b4d52aee40da5b" dependencies = [ "winit", ] diff --git a/src/app.rs b/src/app.rs index 8ccfcf9fd..bf3f7249c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -352,8 +352,25 @@ impl App { pub fn monitors(&self) -> Option { self.app.as_ref().and_then(kludgine::app::App::monitors) } + + /// Creates a guard that prevents this app from shutting down. + /// + /// If the app is not currently running, this function returns None. + /// + /// Once a guard is allocated the app will not be closed automatically when + /// the final window is closed. If the final shutdown guard is dropped while + /// no windows are open, the app will be closed. + #[allow(clippy::missing_panics_doc, clippy::must_use_candidate)] + pub fn prevent_shutdown(&self) -> Option { + self.app + .as_ref() + .and_then(kludgine::app::App::prevent_shutdown) + } } +/// A guard preventing an [`App`] from shutting down. +pub type ShutdownGuard = kludgine::app::ShutdownGuard; + impl Application for App { fn cushy(&self) -> &Cushy { &self.cushy diff --git a/src/lib.rs b/src/lib.rs index 02e121d15..182d16ed7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,9 @@ use std::ops::{Add, AddAssign, Sub, SubAssign}; #[cfg(feature = "tokio")] pub use app::TokioRuntime; -pub use app::{App, AppRuntime, Application, Cushy, DefaultRuntime, Open, PendingApp, Run}; +pub use app::{ + App, AppRuntime, Application, Cushy, DefaultRuntime, Open, PendingApp, Run, ShutdownGuard, +}; /// A macro to create a `main()` function with less boilerplate. /// /// When creating applications that support multiple windows, this attribute