-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to manually save state #5243
Comments
I've found an approach that seems to work, basically by making I think it'd make sense for this to potentially be integrated into egui/eframe, though. #[derive(Default)]
struct MainApp {
// ...
tasks: TaskList,
needs_save: bool,
}
impl eframe::App for MainApp {
// ...
fn auto_save_interval(&self) -> std::time::Duration {
if self.needs_save {
std::time::Duration::from_secs(0)
} else {
std::time::Duration::from_secs(30)
}
}
fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, eframe::APP_KEY, &self.tasks);
self.needs_save = false;
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
If I know a particular action changes something significant enough to warrant saving the state to disk, I want to be able to request a save (similar to how you can use
ctx.request_repaint()
and related functions if you know a repaint will be needed).Describe the solution you'd like
The idea that comes to mind is adding a
ctx.request_save()
or similar, which triggers the same behavior as if the autosave duration was reached.Describe alternatives you've considered
I tried storing the creation context passed to the
eframe::App
, but that caused ownership problems.I tried storing a reference to the
eframe::Storage
instead, and also ran into ownership problems.I can't even figure out a messy way to do it with existing functionality.(EDIT: I found a way to implement it. See #5243 (comment).)The text was updated successfully, but these errors were encountered: