27 lines
806 B
Rust
Executable File
27 lines
806 B
Rust
Executable File
use crate::application::Application;
|
|
use crate::event::application::Event;
|
|
use crate::prelude::Platform;
|
|
|
|
/// Plugins are modular configurators for AbleTK applications.
|
|
pub trait Plugin {
|
|
fn apply(&self, app: Application) -> Application;
|
|
}
|
|
|
|
/// A plugin that automatically quits the app if all windows are destroyed, on
|
|
/// non-macOS platforms.
|
|
///
|
|
/// ## Platform-specific
|
|
/// - **macOS:** It is common for macOS apps to not quit if all windows are
|
|
/// destroyed, so this plugin does exactly that.
|
|
pub struct QuitPlugin;
|
|
|
|
impl Plugin for QuitPlugin {
|
|
fn apply(&self, app: Application) -> Application {
|
|
app.on_event(Event::AllWindowsClosed, |ctx| {
|
|
if Platform::target() != Platform::MacOS {
|
|
ctx.quit()
|
|
}
|
|
})
|
|
}
|
|
}
|