use egui's save method
This commit is contained in:
@@ -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,31 +610,27 @@ 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 let Ok(Some(local_storage)) = web_sys::window()
|
||||||
|
.expect("Could not get web_sys window")
|
||||||
|
.local_storage()
|
||||||
{
|
{
|
||||||
if self.since_last_save.elapsed().as_millis() > 10000 {
|
tracing::info!("Saving function data");
|
||||||
self.since_last_save = Instant::now();
|
let hash: crate::misc::HashBytes =
|
||||||
if let Ok(Some(local_storage)) = web_sys::window()
|
unsafe { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) };
|
||||||
.expect("Could not get web_sys window")
|
let saved_data = &crate::misc::hashed_storage_create(
|
||||||
.local_storage()
|
hash,
|
||||||
{
|
bincode::serialize(&self.functions).unwrap().as_slice(),
|
||||||
tracing::info!("Setting current functions");
|
);
|
||||||
let hash: crate::misc::HashBytes = unsafe {
|
// tracing::info!("Bytes: {}", saved_data.len());
|
||||||
std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT)
|
local_storage
|
||||||
};
|
.set_item(FUNC_NAME, saved_data)
|
||||||
let saved_data = &crate::misc::hashed_storage_create(
|
.expect("failed to set local function storage");
|
||||||
hash,
|
} else {
|
||||||
bincode::serialize(&self.functions).unwrap().as_slice(),
|
panic!("unable to get local storage")
|
||||||
);
|
|
||||||
// tracing::info!("Bytes: {}", saved_data.len());
|
|
||||||
local_storage
|
|
||||||
.set_item(FUNC_NAME, saved_data)
|
|
||||||
.expect("failed to set local function storage");
|
|
||||||
} else {
|
|
||||||
panic!("unable to get local storage")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user