use crate::popup::Popup; use crate::write_lock; use std::collections::HashMap; use std::sync::{Arc, RwLock, RwLockWriteGuard}; /// Global application state shared across all bars. /// /// Data that needs to be accessed from anywhere /// that is not otherwise accessible should be placed on here. #[derive(Debug)] pub struct GlobalState { popups: HashMap, Arc>>, } impl GlobalState { pub(crate) fn new() -> Self { Self { popups: HashMap::new(), } } pub fn popups(&self) -> &HashMap, Arc>> { &self.popups } pub fn popups_mut(&mut self) -> &mut HashMap, Arc>> { &mut self.popups } pub fn with_popup_mut(&self, monitor_name: &str, f: F) -> Option where F: FnOnce(RwLockWriteGuard) -> T, { let popup = self.popups().get(monitor_name); if let Some(popup) = popup { let popup = write_lock!(popup); Some(f(popup)) } else { None } } }