1use serde::{Deserialize, Serialize};
2use std::sync::{OnceLock, RwLock};
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct UpdateConfig {
7 #[serde(default = "default_enabled")]
8 pub force_update_gate: bool,
9}
10
11impl Default for UpdateConfig {
12 fn default() -> Self {
13 Self {
14 force_update_gate: true,
15 }
16 }
17}
18
19fn default_enabled() -> bool {
20 true
21}
22
23fn config_store() -> &'static RwLock<UpdateConfig> {
24 static UPDATE_CONFIG: OnceLock<RwLock<UpdateConfig>> = OnceLock::new();
25 UPDATE_CONFIG.get_or_init(|| RwLock::new(UpdateConfig::default()))
26}
27
28pub fn update_config() -> UpdateConfig {
29 config_store()
30 .read()
31 .unwrap_or_else(|err| err.into_inner())
32 .clone()
33}
34
35pub fn configure_update(config: UpdateConfig) {
36 *config_store()
37 .write()
38 .unwrap_or_else(|err| err.into_inner()) = config;
39}