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
16 pub Tooltip:Option<String>,
18
19 pub Color:Option<String>,
22
23 pub Propagate:Option<bool>,
25}
26
27#[derive(Clone)]
30pub struct DecorationsState {
31 Entries:Arc<StandardMutex<HashMap<String, Value>>>,
32}
33
34impl Default for DecorationsState {
35 fn default() -> Self {
36 dev_log!("decorations", "[DecorationsState] Initializing default decorations state...");
37
38 Self { Entries:Arc::new(StandardMutex::new(HashMap::new())) }
39 }
40}
41
42impl DecorationsState {
43 pub fn GetDecoration(&self, Uri:&str) -> Option<Value> {
45 self.Entries.lock().ok().and_then(|Guard| Guard.get(Uri).cloned())
46 }
47
48 pub fn SetDecoration(&self, Uri:&str, Decoration:Value) {
50 if let Ok(mut Guard) = self.Entries.lock() {
51 Guard.insert(Uri.to_owned(), Decoration);
52
53 dev_log!("decorations", "[DecorationsState] Decoration set for: {}", Uri);
54 }
55 }
56
57 pub fn ClearDecoration(&self, Uri:&str) {
59 if let Ok(mut Guard) = self.Entries.lock() {
60 Guard.remove(Uri);
61
62 dev_log!("decorations", "[DecorationsState] Decoration cleared for: {}", Uri);
63 }
64 }
65
66 pub fn GetAll(&self) -> HashMap<String, Value> {
68 self.Entries.lock().ok().map(|Guard| Guard.clone()).unwrap_or_default()
69 }
70}