Mountain/ApplicationState/State/FeatureState/Decorations/
DecorationsState.rs1use std::{
2 collections::HashMap,
3 sync::{Arc, Mutex as StandardMutex},
4};
5
6use serde_json::Value;
7
8use crate::dev_log;
9
10#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
12pub struct DecorationData {
13 pub Badge:Option<String>,
15 pub Tooltip:Option<String>,
17 pub Color:Option<String>,
20 pub Propagate:Option<bool>,
22}
23
24#[derive(Clone)]
27pub struct DecorationsState {
28 Entries:Arc<StandardMutex<HashMap<String, Value>>>,
29}
30
31impl Default for DecorationsState {
32 fn default() -> Self {
33 dev_log!("decorations", "[DecorationsState] Initializing default decorations state...");
34 Self { Entries:Arc::new(StandardMutex::new(HashMap::new())) }
35 }
36}
37
38impl DecorationsState {
39 pub fn GetDecoration(&self, Uri:&str) -> Option<Value> {
41 self.Entries.lock().ok().and_then(|Guard| Guard.get(Uri).cloned())
42 }
43
44 pub fn SetDecoration(&self, Uri:&str, Decoration:Value) {
46 if let Ok(mut Guard) = self.Entries.lock() {
47 Guard.insert(Uri.to_owned(), Decoration);
48 dev_log!("decorations", "[DecorationsState] Decoration set for: {}", Uri);
49 }
50 }
51
52 pub fn ClearDecoration(&self, Uri:&str) {
54 if let Ok(mut Guard) = self.Entries.lock() {
55 Guard.remove(Uri);
56 dev_log!("decorations", "[DecorationsState] Decoration cleared for: {}", Uri);
57 }
58 }
59
60 pub fn GetAll(&self) -> HashMap<String, Value> {
62 self.Entries.lock().ok().map(|Guard| Guard.clone()).unwrap_or_default()
63 }
64}