conditional inclusion of actions in json
This commit is contained in:
parent
62eb2bff11
commit
d2562a7d57
@ -46,17 +46,25 @@ impl Notification {
|
|||||||
|
|
||||||
// The notification as a json object
|
// The notification as a json object
|
||||||
pub fn json(&self) -> Value {
|
pub fn json(&self) -> Value {
|
||||||
json!({
|
// Initialize
|
||||||
|
let mut notif_json: Value = json!({
|
||||||
"app_name": &self.app_name(),
|
"app_name": &self.app_name(),
|
||||||
"replace_id": &self.replace_id(),
|
"replace_id": &self.replace_id(),
|
||||||
"icon": &self.icon(),
|
"icon": &self.icon(),
|
||||||
"summary": &self.summary(),
|
"summary": &self.summary(),
|
||||||
"body": &self.body(),
|
"body": &self.body(),
|
||||||
"actions": &self.actions_json(),
|
|
||||||
"hints": &self.hints_json(),
|
"hints": &self.hints_json(),
|
||||||
"expiration_timeout": self.expir_timeout(),
|
"expiration_timeout": self.expir_timeout(),
|
||||||
"urgency": self.urgency(),
|
"urgency": self.urgency(),
|
||||||
"default_action": self.default_action_json(),
|
});
|
||||||
})
|
|
||||||
|
// Conditionally add the Actions fields
|
||||||
|
if let Value::Object(ref mut map) = notif_json {
|
||||||
|
if !self.actions().is_empty() {
|
||||||
|
map.insert("actions".to_string(), self.actions_json());
|
||||||
|
map.insert("default_action".to_string(), self.default_action_json());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notif_json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
src/formats/rson.rs
Normal file
0
src/formats/rson.rs
Normal file
@ -1,10 +1,10 @@
|
|||||||
use serde::Serialize;
|
// use serde::Serialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use zbus::{message::Body, Result};
|
use zbus::{message::Body, Result};
|
||||||
use zvariant::OwnedValue;
|
use zvariant::OwnedValue;
|
||||||
|
|
||||||
// A notificaion object
|
// A notificaion object
|
||||||
#[derive(Serialize)] // To help with json
|
// #[derive(Serialize)] // To help with json
|
||||||
pub struct Notification {
|
pub struct Notification {
|
||||||
// The application that sent the notification
|
// The application that sent the notification
|
||||||
app_name: String,
|
app_name: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user