From 2c765700a1e09b567cfada30195895c7572a4858 Mon Sep 17 00:00:00 2001 From: pan93412 Date: Tue, 27 Jun 2023 22:07:58 +0800 Subject: [PATCH] refactor(core): :bug: Use AtomicBool for READY https://stackoverflow.com/a/72369696/12652912 --- src/main.rs | 4 ++-- src/ui/first_run/main.rs | 4 ++-- src/ui/main/mod.rs | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9679c2..3db7318 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,13 +27,13 @@ pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const APP_DEBUG: bool = cfg!(debug_assertions); /// Sets to `true` when the `App` component is ready (fully initialized) -pub static mut READY: bool = false; +pub static READY: AtomicBool = AtomicBool::new(false); // TODO: get rid of using this function in all the components' events // e.g. by converting preferences pages into Relm4 Components /// Check if the app is ready pub fn is_ready() -> bool { - unsafe { READY } + READY.load(Ordering::Relaxed) } lazy_static::lazy_static! { diff --git a/src/ui/first_run/main.rs b/src/ui/first_run/main.rs index 2e8abec..7cb874d 100644 --- a/src/ui/first_run/main.rs +++ b/src/ui/first_run/main.rs @@ -174,10 +174,10 @@ impl SimpleComponent for FirstRunApp { unsafe { MAIN_WINDOW = Some(widgets.window.clone()); - - crate::READY = true; } + crate::READY.store(true, Ordering::Relaxed); + tracing::info!("First run window initialized. App is ready"); ComponentParts { model, widgets } // will return soon diff --git a/src/ui/main/mod.rs b/src/ui/main/mod.rs index 6f2b9fe..5950376 100644 --- a/src/ui/main/mod.rs +++ b/src/ui/main/mod.rs @@ -873,9 +873,7 @@ impl SimpleComponent for App { }); // Mark app as loaded - unsafe { - crate::READY = true; - } + crate::READY.store(true, Ordering::Relaxed); tracing::info!("App is ready"); });