Skip to content

Commit

Permalink
Add a new is_busy value with Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
TaQuangKhoi committed Aug 15, 2024
1 parent 9f408c8 commit dde5cea
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
17 changes: 8 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use egui::Align2;
use egui_toast::{Toasts};
use std::{
sync::{Arc, Mutex},
time::Duration,
};
use std::sync::{Arc, Mutex};

/// We derive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(serde::Deserialize, serde::Serialize)]
Expand All @@ -15,8 +12,9 @@ pub struct TwoDBApp {
#[serde(skip)] // This how you opt-out of serialization of a field
value: f32,

pub(crate) is_busy: bool, // This field is for Spinner
pub is_busy_old: bool, // This field is for Spinner

pub is_busy: Arc<Mutex<bool>>,
pub field: Arc<Mutex<i128>>,
}

Expand All @@ -26,7 +24,8 @@ impl Default for TwoDBApp {
// Example stuff:
label: "Hello World! 2".to_owned(),
value: 2.6,
is_busy: false,
is_busy_old: false,
is_busy: Arc::new(Mutex::new(false)),
field: Arc::new(Mutex::new(0)),
}
}
Expand All @@ -42,7 +41,7 @@ impl TwoDBApp {
// Note that you must enable the `persistence` feature for this to work.
if let Some(storage) = cc.storage {
let mut app: TwoDBApp = eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
app.is_busy = false;
app.is_busy_old = false;
return app;
}

Expand Down Expand Up @@ -79,7 +78,7 @@ impl eframe::App for TwoDBApp {
self.render_get_empty_tables_button(ui);
});

if self.is_busy.eq(&true) {
if self.is_busy_old.eq(&true) {
ui.add(egui::Spinner::new());
}

Expand Down Expand Up @@ -128,7 +127,7 @@ impl eframe::App for TwoDBApp {

/// Called by the framework to save state before shutdown.
fn save(&mut self, storage: &mut dyn eframe::Storage) {
self.is_busy = false;
self.is_busy_old = false;
eframe::set_value(storage, eframe::APP_KEY, self);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/update_clean_tables_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::working_database::update_clean_tables;
impl TwoDBApp {
pub fn render_clean_tables_button(&mut self, ui: &mut Ui) {
if ui.button("Update Clean Tables").clicked() {
self.is_busy = true;
self.is_busy_old = true;
ui.close_menu();
self.button_get_clean_tables_event();
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/update_empty_tables_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::working_database::update_empty_tables;
impl TwoDBApp {
pub fn render_get_empty_tables_button(&mut self, ui: &mut Ui) {
if ui.button("Update Empty Tables").clicked() {
self.is_busy = true;
self.is_busy_old = true;
ui.close_menu();
self.get_empty_tables_event();
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/update_self_referencing_tables_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::working_database::update_table_self_references;
impl TwoDBApp {
pub fn render_update_self_referencing_tables_button(&mut self, ui: &mut Ui) {
if ui.button("Update Self Referencing Tables").clicked() {
self.is_busy = true;
self.is_busy_old = true;
ui.close_menu();
self.button_update_self_referencing_tables_event();
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/update_tables_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::working_database::{update_all_tables};
impl TwoDBApp {
pub fn render_update_tables_button(&mut self, ui: &mut egui::Ui) {
if ui.button("Update Tables").clicked() {
self.is_busy = true;
self.is_busy_old = true;
ui.close_menu();
self.button_update_tables_event();
}
Expand Down

0 comments on commit dde5cea

Please sign in to comment.