use crate::picker::led_color::LedColor; use super::mqtt::MqttConnection; use once_cell::sync::OnceCell; use paris::info; pub struct Manager { mqtt: MqttConnection, } impl Manager { pub fn global() -> &'static Self { static RPC_MANAGER: OnceCell = OnceCell::new(); RPC_MANAGER.get_or_init(|| Manager::new()) } pub fn new() -> Self { let mut mqtt = MqttConnection::new(); mqtt.initialize(); Self { mqtt } } pub async fn publish_led_colors(&self, colors: &Vec) -> anyhow::Result<()> { let payload = colors .iter() .map(|c| c.get_rgb().clone()) .flatten() .collect::>(); self.mqtt .client .publish( "screen-bg-light/desktop/colors", rumqttc::QoS::AtMostOnce, false, payload, ) .await .map_err(|error| anyhow::anyhow!("mqtt publish failed. {}", error)) } }