1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

eframe: Add NativeOptions::persistence_path (#4423)

This allows customizing the persistence path in NativeOptions.
Previously, persistence wouldn't work with android because
directories-next doesn't support android so eframe would just fail to
find a place where it could store its config.

* Closes #4098 (android users can now specify a path that works with
android, by e.g. using app_dirs2, which supports android)
This commit is contained in:
lucasmerlin
2024-05-27 18:57:39 +02:00
committed by GitHub
parent 192a111272
commit 8553e738e0
5 changed files with 44 additions and 15 deletions

View File

@@ -150,6 +150,7 @@ pub trait App {
/// On web the state is stored to "Local Storage".
///
/// On native the path is picked using [`crate::storage_dir`].
/// The path can be customized via [`NativeOptions::persistence_path`].
fn save(&mut self, _storage: &mut dyn Storage) {}
/// Called once on shutdown, after [`Self::save`].
@@ -362,6 +363,10 @@ pub struct NativeOptions {
/// Controls whether or not the native window position and size will be
/// persisted (only if the "persistence" feature is enabled).
pub persist_window: bool,
/// The folder where `eframe` will store the app state. If not set, eframe will get the paths
/// from [directories_next].
pub persistence_path: Option<std::path::PathBuf>,
}
#[cfg(not(target_arch = "wasm32"))]
@@ -379,6 +384,8 @@ impl Clone for NativeOptions {
#[cfg(feature = "wgpu")]
wgpu_options: self.wgpu_options.clone(),
persistence_path: self.persistence_path.clone(),
..*self
}
}
@@ -418,6 +425,8 @@ impl Default for NativeOptions {
wgpu_options: egui_wgpu::WgpuConfiguration::default(),
persist_window: true,
persistence_path: None,
}
}
}