bevy_persistent_windows/
plugins.rs

1//! Plugins.
2
3use crate::prelude::*;
4
5/// Persistent windows plugin.
6///
7/// Responsible for restoring window states before the application is run
8/// and synchronizing windows with their states during the run.
9///
10/// # Panics
11///
12/// - Panics if it's added to the [App]
13///   before [WinitPlugin](bevy::winit::WinitPlugin),
14///   which is in the [DefaultPlugins].
15pub struct PersistentWindowsPlugin;
16
17impl Plugin for PersistentWindowsPlugin {
18    fn build(&self, app: &mut App) {
19        let mut persistent_windows =
20            app.world_mut().query::<(&mut Window, &Persistent<WindowState>)>();
21
22        for (mut window, state) in persistent_windows.iter_mut(app.world_mut()) {
23            utils::apply_state_to_window(&mut window, state);
24        }
25
26        app.add_systems(Startup, auto_scale);
27        app.add_systems(
28            PreUpdate,
29            (
30                on_persistent_window_moved,
31                on_persistent_window_resized,
32                on_persistent_window_scale_factor_changed,
33            ),
34        );
35        app.add_systems(PostUpdate, on_persistent_window_state_changed);
36    }
37}