summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bin.rs1
-rw-r--r--ui/src/components/notifications.rs35
-rw-r--r--ui/src/conf.rs5
-rw-r--r--ui/src/conf/notifications.rs33
4 files changed, 74 insertions, 0 deletions
diff --git a/src/bin.rs b/src/bin.rs
index fb0071d1..a0e8edd5 100644
--- a/src/bin.rs
+++ b/src/bin.rs
@@ -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 {
diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs
index 7fd846ed..cb73d0f5 100644
--- a/ui/src/components/notifications.rs
+++ b/ui/src/components/notifications.rs
@@ -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) {}
+}
diff --git a/ui/src/conf.rs b/ui/src/conf.rs
index 7e6a1c26..81e5f223 100644
--- a/ui/src/conf.rs
+++ b/ui/src/conf.rs
@@ -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,
}
}
}
diff --git a/ui/src/conf/notifications.rs b/ui/src/conf/notifications.rs
new file mode 100644
index 00000000..96c75499
--- /dev/null
+++ b/ui/src/conf/notifications.rs
@@ -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>,
+}