1use super::config::{BehaviorConfig, Config};
2use once_cell::sync::OnceCell;
3use std::sync::RwLock;
4
5static CONFIG: OnceCell<RwLock<Config>> = OnceCell::new();
7
8pub fn init_config(config: Config) {
10 CONFIG.set(RwLock::new(config)).ok();
11}
12
13pub fn get_date_notation() -> String {
16 CONFIG.get().and_then(|c| c.read().ok()).map_or_else(
17 || "us".to_string(),
18 |c| c.behavior.default_date_notation.clone(),
19 )
20}
21
22pub fn get_behavior_config() -> BehaviorConfig {
24 CONFIG
25 .get()
26 .and_then(|c| c.read().ok())
27 .map(|c| c.behavior.clone())
28 .unwrap_or_default()
29}
30
31pub fn update_config(config: Config) {
33 if let Some(global) = CONFIG.get() {
34 if let Ok(mut c) = global.write() {
35 *c = config;
36 }
37 } else {
38 init_config(config);
39 }
40}