use egui's save method

This commit is contained in:
Simon Gardling
2022-05-23 12:25:23 -04:00
parent c65c1ea33f
commit 4d272c3d41

View File

@@ -99,9 +99,6 @@ pub struct MathApp {
/// Stores settings (pretty self-explanatory) /// Stores settings (pretty self-explanatory)
settings: AppSettings, settings: AppSettings,
#[cfg(target_arch = "wasm32")]
since_last_save: Instant,
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@@ -259,8 +256,6 @@ impl MathApp {
text: data.text, text: data.text,
opened: Opened::default(), opened: Opened::default(),
settings: Default::default(), settings: Default::default(),
#[cfg(target_arch = "wasm32")]
since_last_save: Instant::now(),
} }
} }
@@ -615,19 +610,17 @@ impl App for MathApp {
// Calculate and store the last time it took to draw the frame // Calculate and store the last time it took to draw the frame
self.last_info.1 = start.map(|a| format!("Took: {:?}", a.elapsed())); self.last_info.1 = start.map(|a| format!("Took: {:?}", a.elapsed()));
}
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
{ fn save(&mut self, _: &mut dyn eframe::Storage) {
if self.since_last_save.elapsed().as_millis() > 10000 {
self.since_last_save = Instant::now();
if let Ok(Some(local_storage)) = web_sys::window() if let Ok(Some(local_storage)) = web_sys::window()
.expect("Could not get web_sys window") .expect("Could not get web_sys window")
.local_storage() .local_storage()
{ {
tracing::info!("Setting current functions"); tracing::info!("Saving function data");
let hash: crate::misc::HashBytes = unsafe { let hash: crate::misc::HashBytes =
std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) unsafe { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) };
};
let saved_data = &crate::misc::hashed_storage_create( let saved_data = &crate::misc::hashed_storage_create(
hash, hash,
bincode::serialize(&self.functions).unwrap().as_slice(), bincode::serialize(&self.functions).unwrap().as_slice(),
@@ -641,5 +634,3 @@ impl App for MathApp {
} }
} }
} }
}
}