diff --git a/src/formats/serde.rs b/src/formats/serde.rs index f18df96..72f164f 100644 --- a/src/formats/serde.rs +++ b/src/formats/serde.rs @@ -20,6 +20,24 @@ where map.serialize(serializer) } +pub fn serialize_hints(hints: &HashMap, serializer: Serializer) -> Result +{ + let mut hint_map = serde_json::Map::new(); + + for hint in hints { + if let (hint_name, hint_val) = hint { + let mut h = serde_json::Map::new(); + let sig = hint_val.value_signature(); + let val = hint_val.try_clone(); + h.insert(sig.to_string(), serde_json::Value::String(val)); + + hint_map.insert(hint_name.clone(), serde_json::Value::Object(h.clone())); + } + } + + hint_map.serialize(serializer) +} + /* pub fn serialize_hints(hints: &HashMap, serializer: S) -> Result where diff --git a/src/notification.rs b/src/notification.rs index 4c56bec..2b73ef2 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -1,4 +1,4 @@ -use crate::formats::serde::serialize_actions; //,serialize_hints}; +use crate::formats::serde::{serialize_actions,serialize_hints}; use serde::Serialize; use std::collections::HashMap; use zbus::{message::Body, Result}; @@ -21,7 +21,7 @@ pub struct Notification { #[serde(serialize_with = "serialize_actions")] actions: Vec, // Useful extra data - notif type, urgency, notif sound, icon data, etc. - //#[serde(serialize_with = "serialize_hints")] + #[serde(serialize_with = "serialize_hints")] hints: HashMap, // Seconds till this notif expires. Optional expir_timeout: i32,