Skip to main content

zoi_core/
offline.rs

1use std::sync::{OnceLock, RwLock};
2
3/// Returns the global store for the offline mode flag.
4fn offline_mode_store() -> &'static RwLock<bool> {
5    static OFFLINE_MODE: OnceLock<RwLock<bool>> = OnceLock::new();
6    OFFLINE_MODE.get_or_init(|| RwLock::new(false))
7}
8
9/// Sets the global offline mode.
10pub fn set_offline(offline: bool) {
11    if let Ok(mut guard) = offline_mode_store().write() {
12        *guard = offline;
13    }
14}
15
16/// Returns true if Zoi is in offline mode.
17pub fn is_offline() -> bool {
18    offline_mode_store().read().is_ok_and(|g| *g)
19}