ui: add notification `play_sound`, `sound_file` conf settings
parent
c695d7a8e2
commit
bd8424c1f8
|
@ -40,8 +40,9 @@ impl fmt::Display for XDGNotifications {
|
||||||
|
|
||||||
impl Component for XDGNotifications {
|
impl Component for XDGNotifications {
|
||||||
fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
|
fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
|
||||||
fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool {
|
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
||||||
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
|
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
|
||||||
|
let settings = &context.runtime_settings.notifications;
|
||||||
let mut notification = notify_rust::Notification::new();
|
let mut notification = notify_rust::Notification::new();
|
||||||
notification
|
notification
|
||||||
.appname("meli")
|
.appname("meli")
|
||||||
|
@ -49,6 +50,23 @@ impl Component for XDGNotifications {
|
||||||
.summary(title.as_ref().map(String::as_str).unwrap_or("meli"))
|
.summary(title.as_ref().map(String::as_str).unwrap_or("meli"))
|
||||||
.body(&escape_str(body))
|
.body(&escape_str(body))
|
||||||
.icon("dialog-information");
|
.icon("dialog-information");
|
||||||
|
match kind {
|
||||||
|
Some(NotificationType::NewMail) => {
|
||||||
|
notification.hint(notify_rust::hints::NotificationHint::Category(
|
||||||
|
"email".to_owned(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if settings.play_sound.is_true() {
|
||||||
|
if let Some(ref sound_path) = settings.sound_file {
|
||||||
|
notification.hint(notify_rust::hints::NotificationHint::SoundFile(
|
||||||
|
sound_path.to_owned(),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
notification.sound_name("message-new-email");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notification.show().unwrap();
|
notification.show().unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,6 +470,10 @@ mod default_vals {
|
||||||
pub(in crate::conf) fn none<T>() -> Option<T> {
|
pub(in crate::conf) fn none<T>() -> Option<T> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::conf) fn internal_value_false() -> super::ToggleFlag {
|
||||||
|
super::ToggleFlag::InternalVal(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for IndexStyle {
|
impl<'de> Deserialize<'de> for IndexStyle {
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use super::default_vals::internal_value_false;
|
||||||
|
use super::toggleflag_de;
|
||||||
|
|
||||||
fn none() -> Option<String> {
|
fn none() -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -30,4 +33,8 @@ pub struct NotificationsSettings {
|
||||||
/// Default: None
|
/// Default: None
|
||||||
#[serde(default = "none")]
|
#[serde(default = "none")]
|
||||||
pub script: Option<String>,
|
pub script: Option<String>,
|
||||||
|
#[serde(deserialize_with = "toggleflag_de", default = "internal_value_false")]
|
||||||
|
pub play_sound: super::ToggleFlag,
|
||||||
|
#[serde(default = "none")]
|
||||||
|
pub sound_file: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue