App::prevent_shutdown()

This commit is contained in:
Jonathan Johnson 2024-09-12 07:40:59 -07:00
parent 8d082ab77f
commit 09790039af
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
4 changed files with 23 additions and 2 deletions

View file

@ -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

2
Cargo.lock generated
View file

@ -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",
]

View file

@ -352,8 +352,25 @@ impl App {
pub fn monitors(&self) -> Option<Monitors> {
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<ShutdownGuard> {
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<WindowCommand>;
impl Application for App {
fn cushy(&self) -> &Cushy {
&self.cushy

View file

@ -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