refactor(core): 🐛 Use AtomicBool for READY

https://stackoverflow.com/a/72369696/12652912
This commit is contained in:
pan93412 2023-06-27 22:07:58 +08:00
parent 3ba2beb37d
commit 2c765700a1
No known key found for this signature in database
GPG key ID: 42154B1B1CFE3377
3 changed files with 5 additions and 7 deletions

View file

@ -27,13 +27,13 @@ pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const APP_DEBUG: bool = cfg!(debug_assertions); pub const APP_DEBUG: bool = cfg!(debug_assertions);
/// Sets to `true` when the `App` component is ready (fully initialized) /// 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 // TODO: get rid of using this function in all the components' events
// e.g. by converting preferences pages into Relm4 Components // e.g. by converting preferences pages into Relm4 Components
/// Check if the app is ready /// Check if the app is ready
pub fn is_ready() -> bool { pub fn is_ready() -> bool {
unsafe { READY } READY.load(Ordering::Relaxed)
} }
lazy_static::lazy_static! { lazy_static::lazy_static! {

View file

@ -174,10 +174,10 @@ impl SimpleComponent for FirstRunApp {
unsafe { unsafe {
MAIN_WINDOW = Some(widgets.window.clone()); MAIN_WINDOW = Some(widgets.window.clone());
crate::READY = true;
} }
crate::READY.store(true, Ordering::Relaxed);
tracing::info!("First run window initialized. App is ready"); tracing::info!("First run window initialized. App is ready");
ComponentParts { model, widgets } // will return soon ComponentParts { model, widgets } // will return soon

View file

@ -873,9 +873,7 @@ impl SimpleComponent for App {
}); });
// Mark app as loaded // Mark app as loaded
unsafe { crate::READY.store(true, Ordering::Relaxed);
crate::READY = true;
}
tracing::info!("App is ready"); tracing::info!("App is ready");
}); });