use bevy::{ prelude::*, window::{ PrimaryWindow, WindowMode, }, }; use bevy_persistent::prelude::*; use bevy_persistent_windows::prelude::*; use std::path::Path; fn main() { let mut app = App::new(); let window_plugin = WindowPlugin { primary_window: None, ..Default::default() }; app.add_plugins(DefaultPlugins.set(window_plugin).build()); let state_directory = dirs::data_dir() .map(|platform_data_dir| platform_data_dir.join("bevy-persistent-windows").join("state")) .unwrap_or(Path::new("session").join("data").join("state")) .join("primary"); app.world_mut().spawn(( PrimaryWindow, PersistentWindowBundle { window: Window { title: "I can be moved persistently.".to_owned(), ..Default::default() }, state: Persistent::::builder() .name("primary window state") .format(StorageFormat::Toml) .path(state_directory.join("primary-window.toml")) .default(WindowState::fullscreen()) .revertible(true) .revert_to_default_on_deserialization_errors(true) .build() .expect("failed to create the persistent primary window state"), }, )); app.add_plugins(PersistentWindowsPlugin); app.add_systems(Update, (fullscreen_toggle, movement)); app.run(); } fn fullscreen_toggle( keyboard_input: Res>, mut query: Query<&mut Persistent, With>, ) { if keyboard_input.just_pressed(KeyCode::Space) { let mut primary_window_state = query.get_single_mut().unwrap(); if primary_window_state.mode == WindowMode::Windowed { primary_window_state.mode = WindowMode::Fullscreen; } else { primary_window_state.mode = WindowMode::Windowed; } primary_window_state.persist().ok(); } } fn movement( time: Res