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