use std::collections::{btree_map::Range, HashMap}; use zbus::{message::Body, Result}; use zvariant::OwnedValue; pub struct Notification { // A notificaion object app_name: String, // The application that sent the notification replace_id: u32, // (Optional) ID of an existing notification to be updated, replaced by this icon: String, // See icon specifications: https://specifications.freedesktop.org/notification-spec/latest/icons-and-images.html summary: String, // Notification title body: String, // Notification content/body actions: Vec, // Action requests that can be sent back to the client - hints: HashMap, // Extra useful data - notif type, urgency, sound file, icon data, etc. expir_timeout: i32, // Seconds till this notif expires. Optional } impl Notification { pub fn urgency(&self) -> String { // Obtain urgency match self.hints.get("urgency") { Some(value) => { // Attempt to convert OwnedValue to u8 match u8::try_from(value) { Ok(0) => "Low".to_string(), Ok(1) => "Normal".to_string(), Ok(2) => "Critical".to_string(), _ => "Other".to_string(), // There are no accepted values other that these 3 } } None => "Unknown".to_string(), // This possibly never occurs, or something might be wrong } } pub fn actions(&self) -> HashMap { let mut acts: HashMap; for i in Range(self.actions.len()) { } } } pub fn to_notif(msg_body: &Body) -> Result { // Convert the DBus message body into Notification let (app_name, replace_id, icon, summary, body, actions, hints, expir_timeout) = msg_body.deserialize()?; // Deserialized into a tuple Ok(Notification { // Make a Notification object from the obtained tuple app_name, replace_id, icon, summary, body, actions, hints, expir_timeout, }) } pub fn print_notif(notif: &Notification) { println!("App Name: {0}", notif.app_name); println!("Replace ID: {0}", notif.replace_id); println!("Icon: {0}", notif.icon); println!("Summary: {0}", notif.summary); println!("Body: {0}", notif.body); println!("Actions: {0:?}", notif.actions); println!("Hints:"); for (key, value) in ¬if.hints { println!(" {key}: {value:?}"); } println!("Expiration Timeout: {0} seconds", notif.expir_timeout); }