Skip to content

Commit

Permalink
App::prevent_shutdown()
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Sep 12, 2024
1 parent 8d082ab commit 0979003
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0979003

Please sign in to comment.