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

eframe web: Store app state to local storage when leaving site (#2927)

This commit is contained in:
Emil Ernerfeldt
2023-04-18 20:26:02 +02:00
committed by GitHub
parent 438f6eafc8
commit 0f9e1a3526
2 changed files with 30 additions and 15 deletions

View File

@@ -299,21 +299,23 @@ impl AppRunner {
.unwrap()
}
pub fn auto_save(&mut self) {
let now = now_sec();
let time_since_last_save = now - self.last_save_time;
pub fn auto_save_if_needed(&mut self) {
let time_since_last_save = now_sec() - self.last_save_time;
if time_since_last_save > self.app.auto_save_interval().as_secs_f64() {
if self.app.persist_egui_memory() {
save_memory(&self.egui_ctx);
}
if let Some(storage) = self.frame.storage_mut() {
self.app.save(storage);
}
self.last_save_time = now;
self.save();
}
}
pub fn save(&mut self) {
if self.app.persist_egui_memory() {
save_memory(&self.egui_ctx);
}
if let Some(storage) = self.frame.storage_mut() {
self.app.save(storage);
}
self.last_save_time = now_sec();
}
pub fn canvas_id(&self) -> &str {
self.painter.canvas_id()
}