ui: add notification `play_sound`, `sound_file` conf settings

embed
Manos Pitsidianakis 2019-09-15 23:36:30 +03:00
parent c695d7a8e2
commit bd8424c1f8
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 30 additions and 1 deletions

View File

@ -40,8 +40,9 @@ impl fmt::Display for XDGNotifications {
impl Component for XDGNotifications {
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 {
let settings = &context.runtime_settings.notifications;
let mut notification = notify_rust::Notification::new();
notification
.appname("meli")
@ -49,6 +50,23 @@ impl Component for XDGNotifications {
.summary(title.as_ref().map(String::as_str).unwrap_or("meli"))
.body(&escape_str(body))
.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();
}

View File

@ -470,6 +470,10 @@ mod default_vals {
pub(in crate::conf) fn none<T>() -> Option<T> {
None
}
pub(in crate::conf) fn internal_value_false() -> super::ToggleFlag {
super::ToggleFlag::InternalVal(false)
}
}
impl<'de> Deserialize<'de> for IndexStyle {

View File

@ -19,6 +19,9 @@
* 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> {
None
}
@ -30,4 +33,8 @@ pub struct NotificationsSettings {
/// Default: None
#[serde(default = "none")]
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>,
}