add notification filter

concerns #64
embed
Manos Pitsidianakis 2019-03-02 21:40:57 +02:00
parent 712652a4c8
commit 1bb1cf7aac
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 74 additions and 0 deletions

View File

@ -75,6 +75,7 @@ fn main() {
let xdg_notifications =
Entity::from(Box::new(ui::components::notifications::XDGNotifications {}));
state.register_entity(xdg_notifications);
state.register_entity(Entity::from(Box::new(ui::components::notifications::NotificationFilter {})));
/* Keep track of the input mode. See ui::UIMode for details */
'main: loop {

View File

@ -23,6 +23,7 @@
Notification handling components.
*/
use notify_rust::Notification as notify_Notification;
use std::process::{Command, Stdio};
use super::*;
@ -104,3 +105,37 @@ mod tests {
.unwrap();
}
}
/// Passes notifications to the OS using the XDG specifications.
#[derive(Debug)]
pub struct NotificationFilter {}
impl fmt::Display for NotificationFilter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO display subject/info
write!(f, "")
}
}
impl Component for NotificationFilter {
fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
if let UIEventType::Notification(ref title, ref body) = event.event_type {
if let Some(ref bin) = context.runtime_settings.notifications.script {
if let Err(v) = Command::new(bin)
.arg(title
.as_ref()
.map(|v| v.as_str())
.unwrap_or("Event"))
.arg(body)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn() {
eprintln!("{:?}",v);
}
}
}
false
}
fn set_dirty(&mut self) {}
}

View File

@ -25,6 +25,7 @@ extern crate xdg;
extern crate bincode;
pub mod pager;
pub mod notifications;
pub mod accounts;
pub use self::accounts::Account;
@ -33,6 +34,7 @@ use self::config::{Config, File, FileFormat};
use melib::conf::AccountSettings;
use melib::error::*;
use pager::PagerSettings;
use self::notifications::NotificationsSettings;
use self::serde::{de, Deserialize, Deserializer};
use std::collections::HashMap;
@ -110,6 +112,7 @@ impl FileAccount {
struct FileSettings {
accounts: HashMap<String, FileAccount>,
pager: PagerSettings,
notifications: NotificationsSettings,
}
#[derive(Debug, Clone, Default)]
@ -134,6 +137,7 @@ impl AccountConf {
pub struct Settings {
pub accounts: HashMap<String, AccountConf>,
pub pager: PagerSettings,
pub notifications: NotificationsSettings,
}
impl FileSettings {
@ -179,6 +183,7 @@ impl Settings {
Settings {
accounts: s,
pager: fs.pager,
notifications: fs.notifications,
}
}
}

View File

@ -0,0 +1,33 @@
/*
* meli - notifications conf module
*
* Copyright 2018 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
fn none() -> Option<String> {
None
}
/// Settings for the notifications function.
#[derive(Debug, Deserialize, Clone, Default)]
pub struct NotificationsSettings {
/// A command to pipe notifications through
/// Default: None
#[serde(default = "none")]
pub script: Option<String>,
}