Skip to content

Commit

Permalink
Improve local data saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan committed Sep 20, 2023
1 parent 02c8e39 commit c5696e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
21 changes: 10 additions & 11 deletions four-bar-ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(crate) struct App {
syn: syn::Synthesis,
bp: blueprint::BluePrint,
plotter: plotter::Plotter,
save_cfg: bool,
#[serde(skip)]
toasts: egui_toast::Toasts,
#[serde(skip)]
Expand Down Expand Up @@ -122,13 +123,11 @@ impl App {
ui.heading("License");
ui.label("This software is under AGPL v3 license.");
ui.label("The commercial usages under server or client side are not allowed.");
if cfg!(target_arch = "wasm32") {
ui.separator();
ui.heading("Web Storage");
ui.label("The Web version disabled local storage by default.");
ui.label("Check \"Save local data\" to turn it on.");
}
ui.colored_label(Color32::GREEN, "Enjoy this app!");
ui.separator();
ui.heading("Local Storage");
ui.label("The local storage is disabled by default.");
let text = WidgetText::from("Save local data").color(Color32::GREEN);
ui.checkbox(&mut self.save_cfg, text);
ui.allocate_space(ui.available_size());
});
self.welcome_off = !welcome;
Expand Down Expand Up @@ -206,10 +205,10 @@ impl eframe::App for App {
}

fn save(&mut self, storage: &mut dyn eframe::Storage) {
#[cfg(target_arch = "wasm32")]
if !self.link.cfg.web_data {
return;
if self.save_cfg {
eframe::set_value(storage, eframe::APP_KEY, self);
} else {
storage.set_string(eframe::APP_KEY, String::new());
}
eframe::set_value(storage, eframe::APP_KEY, self);
}
}
21 changes: 1 addition & 20 deletions four-bar-ui/src/app/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ pub(crate) struct Cfg {
pub(crate) int: f64,
// resolution
pub(crate) res: usize,
#[cfg(target_arch = "wasm32")]
pub(crate) web_data: bool,
}

impl Default for Cfg {
fn default() -> Self {
Self {
int: 1.,
res: 360,
#[cfg(target_arch = "wasm32")]
web_data: false,
}
Self { int: 1., res: 360 }
}
}

Expand All @@ -47,18 +40,6 @@ impl Linkages {
if nonzero_i(ui, "Curve resolution: ", &mut self.cfg.res, 1).changed() {
self.projs.request_cache();
}
#[cfg(target_arch = "wasm32")]
if ui
.checkbox(&mut self.cfg.web_data, "Save local data")
.clicked()
&& !self.cfg.web_data
{
#[wasm_bindgen::prelude::wasm_bindgen]
extern "C" {
fn clear_storage();
}
clear_storage();
}
ui.horizontal(|ui| {
ui.group(|ui| {
ui.label("Theme");
Expand Down

0 comments on commit c5696e6

Please sign in to comment.