abletk/src/plugin.rs

35 lines
1.1 KiB
Rust
Executable File

/*
* Copyright (C) 2022 Umut İnan Erdoğan <umutinanerdogan@pm.me>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
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::AllWindowsDestroyed, |ctx| {
if Platform::target() != Platform::MacOS {
ctx.quit()
}
})
}
}