From e7d210e03a7a7b1ba10018f4c9829f07ca7ea51b Mon Sep 17 00:00:00 2001 From: RustDesk <71636191+rustdesk@users.noreply.github.com> Date: Tue, 18 Feb 2025 16:07:45 +0800 Subject: [PATCH] Add Status --- src/config.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/config.rs b/src/config.rs index d58ade9..ce4e89d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -53,6 +53,7 @@ lazy_static::lazy_static! { static ref CONFIG: RwLock = RwLock::new(Config::load()); static ref CONFIG2: RwLock = RwLock::new(Config2::load()); static ref LOCAL_CONFIG: RwLock = RwLock::new(LocalConfig::load()); + static ref STATUS: RwLock = RwLock::new(Status::load()); static ref TRUSTED_DEVICES: RwLock<(Vec, bool)> = Default::default(); static ref ONLINE: Mutex> = Default::default(); pub static ref PROD_RENDEZVOUS_SERVER: RwLock = RwLock::new("".to_owned()); @@ -2429,6 +2430,42 @@ pub fn common_store(config: &T, suffix: &str) { Config::store_(config, suffix); } +#[derive(Debug, Default, Serialize, Deserialize, Clone)] +pub struct Status { + #[serde(default, deserialize_with = "deserialize_hashmap_string_string")] + values: HashMap, +} + +impl Status { + fn load() -> Status { + Config::load_::("_status") + } + + fn store(&self) { + Config::store_(self, "_status"); + } + + pub fn get(k: &str) -> String { + STATUS + .read() + .unwrap() + .values + .get(k) + .cloned() + .unwrap_or_default() + } + + pub fn set(k: &str, v: String) { + if Self::get(k) == v { + return; + } + + let mut st = STATUS.write().unwrap(); + st.values.insert(k.to_owned(), v); + st.store(); + } +} + #[cfg(test)] mod tests { use super::*;