hints_json and improved plaintext
This commit is contained in:
parent
59efd6e20e
commit
62eb2bff11
@ -20,6 +20,14 @@ impl Notification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default action, as json string
|
||||||
|
pub fn default_action_json(&self) -> Value {
|
||||||
|
match self.default_action() {
|
||||||
|
None => serde_json::Value::from("None"),
|
||||||
|
Some(actn) => serde_json::Value::String(actn.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hints, as json
|
// Hints, as json
|
||||||
pub fn hints_json(&self) -> Value {
|
pub fn hints_json(&self) -> Value {
|
||||||
if self.hints().is_empty() {
|
if self.hints().is_empty() {
|
||||||
@ -48,7 +56,7 @@ impl Notification {
|
|||||||
"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().map(|actn| actn.0),
|
"default_action": self.default_action_json(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
use crate::notification::Notification;
|
use crate::notification::Notification;
|
||||||
|
|
||||||
impl Notification {
|
impl Notification {
|
||||||
// Plain string format, useful for printing
|
// Actions, plain text format
|
||||||
pub fn plain(&self) -> String {
|
pub fn actions_plain(&self) -> String {
|
||||||
// Actions
|
if self.actions().is_empty() {
|
||||||
let actions: String = if self.actions().is_empty() {
|
|
||||||
"None".to_string()
|
"None".to_string()
|
||||||
} else {
|
} else {
|
||||||
self.actions()
|
self.actions()
|
||||||
@ -15,14 +14,20 @@ impl Notification {
|
|||||||
acc.push_str(&format!("\n\t{id}: {label}"));
|
acc.push_str(&format!("\n\t{id}: {label}"));
|
||||||
acc
|
acc
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
// Default action
|
}
|
||||||
let default_action: String = match self.default_action() {
|
|
||||||
|
// Default action, as plain text
|
||||||
|
pub fn default_action_plain(&self) -> String {
|
||||||
|
match self.default_action() {
|
||||||
None => "None".to_string(),
|
None => "None".to_string(),
|
||||||
Some(actn) => actn.0,
|
Some(actn) => actn.0,
|
||||||
};
|
}
|
||||||
// Hints
|
}
|
||||||
let hints: String = if self.hints().is_empty() {
|
|
||||||
|
// Hints, as plain text
|
||||||
|
pub fn hints_plain(&self) -> String {
|
||||||
|
if self.hints().is_empty() {
|
||||||
"None".to_string()
|
"None".to_string()
|
||||||
} else {
|
} else {
|
||||||
self.hints()
|
self.hints()
|
||||||
@ -31,20 +36,22 @@ impl Notification {
|
|||||||
acc.push_str(&format!("\n\t{}: {}", key, **value));
|
acc.push_str(&format!("\n\t{}: {}", key, **value));
|
||||||
acc
|
acc
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return the notification as a plain string
|
// Return the notification as a plain string
|
||||||
|
pub fn plain(&self) -> String {
|
||||||
let plain_string: String = format!("App Name: {}\nReplace ID: {}\nIcon: {}\nSummary: {}\nBody: {}\nActions: {}\nHints: {}\nExpiration Timeout: {}\nUrgency: {}\nDefault Action: {}",
|
let plain_string: String = format!("App Name: {}\nReplace ID: {}\nIcon: {}\nSummary: {}\nBody: {}\nActions: {}\nHints: {}\nExpiration Timeout: {}\nUrgency: {}\nDefault Action: {}",
|
||||||
&self.app_name(),
|
&self.app_name(),
|
||||||
&self.replace_id(),
|
&self.replace_id(),
|
||||||
&self.icon(),
|
&self.icon(),
|
||||||
&self.summary(),
|
&self.summary(),
|
||||||
&self.body(),
|
&self.body(),
|
||||||
actions,
|
&self.actions_plain(),
|
||||||
hints,
|
&self.hints_plain(),
|
||||||
&self.expir_timeout(),
|
&self.expir_timeout(),
|
||||||
&self.urgency(),
|
&self.urgency(),
|
||||||
default_action,
|
&self.default_action_plain(),
|
||||||
);
|
);
|
||||||
plain_string
|
plain_string
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user