2024-09-16 20:51:27 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use zbus::{message::Body, Result};
|
|
|
|
use zvariant::OwnedValue;
|
|
|
|
|
|
|
|
pub struct Notification {
|
|
|
|
app_name: String,
|
|
|
|
replace_id: u32,
|
|
|
|
icon: String,
|
|
|
|
summary: String,
|
|
|
|
body: String,
|
|
|
|
actions: Vec<String>,
|
|
|
|
hints: HashMap<String, OwnedValue>,
|
|
|
|
expir_timeout: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Notification {
|
|
|
|
pub fn urgency(&self) -> String {
|
|
|
|
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(),
|
|
|
|
_ => "Unknown".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => "Unknown".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_notif(msg_body: &Body) -> Result<Notification> {
|
|
|
|
let (app_name, replace_id, icon, summary, body, actions, hints, expir_timeout) =
|
|
|
|
msg_body.deserialize()?;
|
|
|
|
Ok(Notification {
|
|
|
|
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:?}");
|
|
|
|
}
|
2024-09-16 21:28:58 +00:00
|
|
|
println!("Expiration Timeout: {0} seconds", notif.expir_timeout);
|
2024-09-16 20:51:27 +00:00
|
|
|
}
|