pub struct SettingsPlugin {
pub app_name: String,
}Expand description
Plugin to orchestrate loading and saving settings.
You are required to provide a unique application name, so that your settings don’t overwrite those of other apps. To ensure global uniqueness, it is recommended to use a reverse domain name, e.g. “com.example.myapp”. The plugin will create a directory with that name in the appropriate filesystem location (depending on platform) for app settings. For platforms without filesystems, other storage mechanisms will be used.
If you are do not have a domain name and cannot afford one, use a reverse domain based on the URL of your repo (GitHub, GitLab, Codeberg and so on).
Adding this plugin causes an immediate load of settings (from either the filesystem or browser local storage, depending on platform).
When using this plugin, care must be taken to ensure that plugins execute in the proper order. Loading settings causes registered settings to be inserted into the world as bevy resources. You cannot access these values before they are loaded, but you may want to use the loaded values when configuring other plugins. For this reason, it’s generally a good idea to initialize and load settings before other plugins. The settings plugin does not depend on any other plugins.
In many cases, you may want to introduce additional “glue” plugins that copy setting
properties after they are loaded. For example, the
WindowPlugin plugin knows
nothing about settings, but if you want the window size and position to persist between runs
you can add an additional plugin which copies the window settings from the resource to the
actual window entity.
Saving of settings is not automatic; the recommended practice is to issue a
SaveSettingsDeferred command after modifying a settings resource. This will wait for
a short interval and then spawn an i/o task to write out the changed settings file. You can
also issue a SaveSettingsSync::IfChanged command immediately before exiting the app.
Note that on some platforms, depending on how the user exits (such as invoking Command-Q on
MacOS) there may be no opportunity to intercept the app exit event, so the most reliable
approach is to use both techniques: deferred save and save-on-exit.
Saving is crash-resistant: if the app crashes in the middle of a save, the settings file will not be corrupted (it writes to a temporary file first, then uses atomic operations to replace the previous file).
Fields§
§app_name: StringThe unique name of the application.
Implementations§
Trait Implementations§
Source§impl Plugin for SettingsPlugin
impl Plugin for SettingsPlugin
Source§fn ready(&self, _app: &App) -> bool
fn ready(&self, _app: &App) -> bool
finish should be called.Source§fn finish(&self, _app: &mut App)
fn finish(&self, _app: &mut App)
App, once all plugins registered are ready. This can
be useful for plugins that depends on another plugin asynchronous setup, like the renderer.Source§fn cleanup(&self, _app: &mut App)
fn cleanup(&self, _app: &mut App)
Auto Trait Implementations§
impl Freeze for SettingsPlugin
impl RefUnwindSafe for SettingsPlugin
impl Send for SettingsPlugin
impl Sync for SettingsPlugin
impl Unpin for SettingsPlugin
impl UnsafeUnpin for SettingsPlugin
impl UnwindSafe for SettingsPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.