Make dbus dependency optional
Put dbus dependency behing `dbus-notifications` feature.memfd
parent
faa12a2d41
commit
1ac3a7a903
|
@ -50,8 +50,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -88,6 +88,12 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
|
@ -171,7 +177,7 @@ version = "2.33.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
]
|
||||
|
@ -326,9 +332,9 @@ checksum = "72aa14c04dfae8dd7d8a2b1cb7ca2152618cd01336dbfe704b8dcbf8d41dbd69"
|
|||
|
||||
[[package]]
|
||||
name = "dbus"
|
||||
version = "0.6.5"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48b5f0f36f1eebe901b0e6bee369a77ed3396334bf3f09abd46454a576f71819"
|
||||
checksum = "5cd9e78c210146a1860f897db03412fd5091fd73100778e43ee255cca252cf32"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libdbus-sys",
|
||||
|
@ -497,7 +503,7 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"fsevent-sys",
|
||||
]
|
||||
|
||||
|
@ -516,7 +522,7 @@ version = "0.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"fuchsia-zircon-sys",
|
||||
]
|
||||
|
||||
|
@ -582,8 +588,8 @@ checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39"
|
|||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -687,7 +693,7 @@ version = "0.7.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"inotify-sys",
|
||||
"libc",
|
||||
]
|
||||
|
@ -900,7 +906,7 @@ version = "0.6.1"
|
|||
dependencies = [
|
||||
"async-task",
|
||||
"bincode",
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"crossbeam",
|
||||
"futures",
|
||||
"indexmap",
|
||||
|
@ -913,7 +919,7 @@ dependencies = [
|
|||
"num_cpus",
|
||||
"pcre2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"quote 1.0.6",
|
||||
"rmp",
|
||||
"rmp-serde",
|
||||
"rmpv",
|
||||
|
@ -925,7 +931,7 @@ dependencies = [
|
|||
"smallvec",
|
||||
"structopt",
|
||||
"svg",
|
||||
"syn",
|
||||
"syn 1.0.31",
|
||||
"termion",
|
||||
"toml",
|
||||
"unicode-segmentation",
|
||||
|
@ -941,7 +947,7 @@ dependencies = [
|
|||
"async-stream",
|
||||
"base64 0.12.3",
|
||||
"bincode",
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"crossbeam",
|
||||
"data-encoding",
|
||||
"encoding",
|
||||
|
@ -1087,7 +1093,7 @@ version = "0.17.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
|
@ -1117,7 +1123,7 @@ version = "4.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"filetime",
|
||||
"fsevent",
|
||||
"fsevent-sys",
|
||||
|
@ -1131,12 +1137,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "notify-rust"
|
||||
version = "3.6.3"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8da29142be3f71b2165a6b3991c26045b674edbf04cdfc42f323094fc3e4b5a"
|
||||
checksum = "144acee6a0543dc74893e4b8a33936b5b0a94cc2d4ab024afd0c6daff7afc3c0"
|
||||
dependencies = [
|
||||
"dbus",
|
||||
"mac-notification-sys",
|
||||
"winrt-notification",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1215,7 +1222,7 @@ version = "0.10.29"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cee6d85f4cb4c4f59a6a85d5b68a233d280c82e29e822913b9c8b129fbf20bdd"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"lazy_static",
|
||||
|
@ -1287,8 +1294,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "10b4b44893d3c370407a1d6a5cfde7c41ae0478e31c516c85f67eb3adc51be6d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1317,8 +1324,8 @@ checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
|
|||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
|
@ -1329,8 +1336,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
"syn-mid",
|
||||
"version_check",
|
||||
]
|
||||
|
@ -1353,9 +1360,15 @@ version = "1.0.18"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
"unicode-xid 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.6"
|
||||
|
@ -1480,7 +1493,7 @@ version = "0.24.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c78c3275d9d6eb684d2db4b2388546b32fdae0586c20a82f3905d21ea78b9ef"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"fallible-iterator",
|
||||
"fallible-streaming-iterator",
|
||||
"libsqlite3-sys",
|
||||
|
@ -1553,7 +1566,7 @@ version = "0.4.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.2.1",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
|
@ -1610,8 +1623,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1737,8 +1750,24 @@ dependencies = [
|
|||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ca6e4730f517e041e547ffe23d29daab8de6b73af4b6ae2a002108169f5e7da"
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3384590878eb0cab3b128e844412e2d010821e7e091211b9d87324173ada7db8"
|
||||
dependencies = [
|
||||
"quote 0.3.15",
|
||||
"syn 0.11.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1747,6 +1776,17 @@ version = "0.8.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b65a64d32a41db2a8081aa03c1ccca26f246ff681add693f8b01307b137da79"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.11.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||
dependencies = [
|
||||
"quote 0.3.15",
|
||||
"synom",
|
||||
"unicode-xid 0.0.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.31"
|
||||
|
@ -1754,8 +1794,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
"quote 1.0.6",
|
||||
"unicode-xid 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1765,8 +1805,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synom"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
dependencies = [
|
||||
"unicode-xid 0.0.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1859,8 +1908,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1894,6 +1943,12 @@ version = "0.1.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.0"
|
||||
|
@ -2004,6 +2059,28 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "winrt"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e30cba82e22b083dc5a422c2ee77e20dc7927271a0dc981360c57c1453cb48d"
|
||||
dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winrt-notification"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c31a65da50d792c6f9bd2e3216249566c4fb1d2d34f9b7d2d66d2e93f62a242"
|
||||
dependencies = [
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"winapi 0.3.8",
|
||||
"winrt",
|
||||
"xml-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ws2_32-sys"
|
||||
version = "0.2.1"
|
||||
|
@ -2025,3 +2102,12 @@ name = "xdg-utils"
|
|||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b4aa07a8b3ab25251dbe6448f6af84ec842d1965a038cf422f97f2a6b76ae3e"
|
||||
|
||||
[[package]]
|
||||
name = "xml-rs"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1945e12e16b951721d7976520b0832496ef79c31602c7a29d950de79ba74621"
|
||||
dependencies = [
|
||||
"bitflags 0.9.1",
|
||||
]
|
||||
|
|
|
@ -41,7 +41,7 @@ indexmap = { version = "^1.5", features = ["serde-1", ] }
|
|||
linkify = "0.4.0"
|
||||
xdg-utils = "0.3.0"
|
||||
notify = "4.0.1" # >:c
|
||||
notify-rust = "^3" # >:c
|
||||
notify-rust = { version = "^4", optional = true }
|
||||
termion = "1.5.1"
|
||||
bincode = "1.2.0"
|
||||
uuid = { version = "0.8.1", features = ["serde", "v4"] }
|
||||
|
@ -73,12 +73,13 @@ debug = false
|
|||
members = ["melib", "tools", ]
|
||||
|
||||
[features]
|
||||
default = ["sqlite3", "notmuch", "regexp", "smtp"]
|
||||
default = ["sqlite3", "notmuch", "regexp", "smtp", "dbus-notifications"]
|
||||
notmuch = ["melib/notmuch_backend", ]
|
||||
jmap = ["melib/jmap_backend",]
|
||||
sqlite3 = ["melib/sqlite3"]
|
||||
smtp = ["melib/smtp"]
|
||||
regexp = ["pcre2"]
|
||||
dbus-notifications = ["notify-rust",]
|
||||
cli-docs = []
|
||||
svgscreenshot = ["svg_crate"]
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ is on the roadmap.
|
|||
|
||||
Some functionality is held behind "feature gates", or compile-time flags. The following list explains each feature's purpose:
|
||||
|
||||
- `dbus-notifications` enables showing notifications using `dbus`.
|
||||
- `notmuch` provides support for using a notmuch database as a mail backend
|
||||
- `jmap` provides support for connecting to a jmap server and use it as a mail backend
|
||||
- `sqlite3` provides support for builting fast search indexes in local sqlite3 databases
|
||||
|
|
|
@ -677,7 +677,7 @@ Go to next page.
|
|||
.Sh NOTIFICATIONS
|
||||
.Bl -tag -width 36n
|
||||
.It Ic enable Ar boolean
|
||||
Enable freedesktop-spec notifications.
|
||||
Enable notifications.
|
||||
.\" default value
|
||||
.Pq Em true
|
||||
.It Ic script Ar String
|
||||
|
|
12
src/bin.rs
12
src/bin.rs
|
@ -30,7 +30,6 @@
|
|||
use std::alloc::System;
|
||||
use std::collections::VecDeque;
|
||||
use std::path::PathBuf;
|
||||
extern crate notify_rust;
|
||||
extern crate xdg_utils;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
@ -336,9 +335,14 @@ fn run_app(opt: Opt) -> Result<()> {
|
|||
let status_bar = Box::new(StatusBar::new(window));
|
||||
state.register_component(status_bar);
|
||||
|
||||
let xdg_notifications = Box::new(components::notifications::XDGNotifications::new());
|
||||
state.register_component(xdg_notifications);
|
||||
state.register_component(Box::new(components::notifications::NotificationFilter {}));
|
||||
#[cfg(feature = "dbus-notifications")]
|
||||
{
|
||||
let dbus_notifications = Box::new(components::notifications::DbusNotifications::new());
|
||||
state.register_component(dbus_notifications);
|
||||
}
|
||||
state.register_component(Box::new(
|
||||
components::notifications::NotificationCommand::new(),
|
||||
));
|
||||
}
|
||||
let enter_command_mode: Key = state
|
||||
.context
|
||||
|
|
|
@ -22,69 +22,76 @@
|
|||
/*!
|
||||
Notification handling components.
|
||||
*/
|
||||
use crate::types::RateLimit;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Passes notifications to the OS using the XDG specifications.
|
||||
#[derive(Debug)]
|
||||
pub struct XDGNotifications {
|
||||
rate_limit: RateLimit,
|
||||
}
|
||||
#[cfg(feature = "dbus-notifications")]
|
||||
pub use dbus::*;
|
||||
|
||||
impl fmt::Display for XDGNotifications {
|
||||
#[cfg(feature = "dbus-notifications")]
|
||||
mod dbus {
|
||||
use super::*;
|
||||
use crate::types::RateLimit;
|
||||
|
||||
/// Passes notifications to the OS using Dbus
|
||||
#[derive(Debug)]
|
||||
pub struct DbusNotifications {
|
||||
rate_limit: RateLimit,
|
||||
}
|
||||
|
||||
impl fmt::Display for DbusNotifications {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl XDGNotifications {
|
||||
impl DbusNotifications {
|
||||
pub fn new() -> Self {
|
||||
XDGNotifications {
|
||||
DbusNotifications {
|
||||
rate_limit: RateLimit::new(1000, 1000),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
|
||||
if !self.rate_limit.tick() {
|
||||
return true;
|
||||
}
|
||||
|
||||
let settings = &context.runtime_settings.notifications;
|
||||
impl Component for DbusNotifications {
|
||||
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 !context.settings.notifications.enable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
|
||||
if !self.rate_limit.tick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let settings = &context.settings.notifications;
|
||||
let mut notification = notify_rust::Notification::new();
|
||||
notification
|
||||
.appname("meli")
|
||||
.icon("mail-message-new")
|
||||
.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(),
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
.body(&escape_str(body));
|
||||
if *kind == Some(NotificationType::NEWMAIL) {
|
||||
notification.hint(notify_rust::Hint::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(),
|
||||
));
|
||||
notification.hint(notify_rust::Hint::SoundFile(sound_path.to_owned()));
|
||||
} else {
|
||||
notification.sound_name("message-new-email");
|
||||
}
|
||||
} else {
|
||||
notification.hint(notify_rust::Hint::SuppressSound(true));
|
||||
}
|
||||
|
||||
notification.show().unwrap();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn set_dirty(&mut self, _value: bool) {}
|
||||
|
||||
fn is_dirty(&self) -> bool {
|
||||
|
@ -94,10 +101,11 @@ impl Component for XDGNotifications {
|
|||
fn id(&self) -> ComponentId {
|
||||
ComponentId::nil()
|
||||
}
|
||||
fn set_id(&mut self, _id: ComponentId) {}
|
||||
}
|
||||
|
||||
fn escape_str(s: &str) -> String {
|
||||
fn set_id(&mut self, _id: ComponentId) {}
|
||||
}
|
||||
|
||||
fn escape_str(s: &str) -> String {
|
||||
let mut ret: String = String::with_capacity(s.len());
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
|
@ -122,47 +130,37 @@ fn escape_str(s: &str) -> String {
|
|||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_escape_str() {
|
||||
if std::env::var("DISPLAY").is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
let title: &str = "& > Title τίτλος";
|
||||
let body: &str = "& > Body σώμα";
|
||||
notify_rust::Notification::new()
|
||||
.appname("meli")
|
||||
.icon("mail-message-new")
|
||||
.summary(title)
|
||||
.body(&escape_str(body))
|
||||
.icon("dialog-information")
|
||||
.show()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Passes notifications to the OS using the XDG specifications.
|
||||
/// Passes notifications to a user defined shell command
|
||||
#[derive(Debug)]
|
||||
pub struct NotificationFilter {}
|
||||
pub struct NotificationCommand {}
|
||||
|
||||
impl fmt::Display for NotificationFilter {
|
||||
impl NotificationCommand {
|
||||
pub fn new() -> Self {
|
||||
NotificationCommand {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for NotificationCommand {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "")
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for NotificationFilter {
|
||||
impl Component for NotificationCommand {
|
||||
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 !context.settings.notifications.enable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
|
||||
if let Some(ref bin) = context.runtime_settings.notifications.script {
|
||||
if let Some(ref bin) = context.settings.notifications.script {
|
||||
match Command::new(bin)
|
||||
.arg(&kind.map(|k| k.to_string()).unwrap_or_default())
|
||||
.arg(title.as_ref().map(String::as_str).unwrap_or("meli"))
|
||||
.arg(body)
|
||||
.stdin(Stdio::piped())
|
||||
|
@ -177,14 +175,13 @@ impl Component for NotificationFilter {
|
|||
format!("Could not run notification script: {}.", err.to_string()),
|
||||
ERROR,
|
||||
);
|
||||
debug!("{:?}", err);
|
||||
debug!("Could not run notification script: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match kind {
|
||||
Some(NotificationType::NewMail) => {
|
||||
if let Some(ref path) = context.runtime_settings.notifications.xbiff_file_path {
|
||||
if *kind == Some(NotificationType::NEWMAIL) {
|
||||
if let Some(ref path) = context.settings.notifications.xbiff_file_path {
|
||||
let mut file = std::fs::OpenOptions::new().append(true) /* writes will append to a file instead of overwriting previous contents */
|
||||
.create(true) /* a new file will be created if the file does not yet already exist.*/
|
||||
.open(path).unwrap();
|
||||
|
@ -195,8 +192,6 @@ impl Component for NotificationFilter {
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
|
@ -851,7 +851,7 @@ impl Account {
|
|||
self.name,
|
||||
self.mailbox_entries[&mailbox_hash].name()
|
||||
),
|
||||
Some(crate::types::NotificationType::NewMail),
|
||||
Some(crate::types::NotificationType::NEWMAIL),
|
||||
));
|
||||
}
|
||||
RefreshEventKind::Remove(env_hash) => {
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use super::default_vals::{internal_value_false, none};
|
||||
use super::default_vals::{internal_value_false, none, true_val};
|
||||
|
||||
/// Settings for the notifications function.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NotificationsSettings {
|
||||
/// Enable notifications.
|
||||
/// Default: True
|
||||
#[serde(default = "true_val")]
|
||||
pub enable: bool,
|
||||
/// A command to pipe notifications through
|
||||
/// Default: None
|
||||
#[serde(default = "none")]
|
||||
|
@ -43,6 +47,7 @@ pub struct NotificationsSettings {
|
|||
impl Default for NotificationsSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enable: true,
|
||||
script: None,
|
||||
xbiff_file_path: None,
|
||||
play_sound: super::ToggleFlag::InternalVal(false),
|
||||
|
|
|
@ -135,6 +135,10 @@ impl Default for ListingSettingsOverride {
|
|||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NotificationsSettingsOverride {
|
||||
#[doc = " Enable notifications."]
|
||||
#[doc = " Default: True"]
|
||||
#[serde(default)]
|
||||
pub enable: Option<bool>,
|
||||
#[doc = " A command to pipe notifications through"]
|
||||
#[doc = " Default: None"]
|
||||
#[serde(default)]
|
||||
|
@ -155,6 +159,7 @@ pub struct NotificationsSettingsOverride {
|
|||
impl Default for NotificationsSettingsOverride {
|
||||
fn default() -> Self {
|
||||
NotificationsSettingsOverride {
|
||||
enable: None,
|
||||
script: None,
|
||||
xbiff_file_path: None,
|
||||
play_sound: None,
|
||||
|
|
|
@ -24,7 +24,6 @@ extern crate melib;
|
|||
use melib::*;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
extern crate notify_rust;
|
||||
extern crate xdg_utils;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
|
18
src/types.rs
18
src/types.rs
|
@ -89,11 +89,25 @@ pub enum ForkType {
|
|||
NewDraft(File, std::process::Child),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum NotificationType {
|
||||
INFO,
|
||||
ERROR,
|
||||
NewMail,
|
||||
NEWMAIL,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for NotificationType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match *self {
|
||||
NotificationType::INFO => "info",
|
||||
NotificationType::ERROR => "error",
|
||||
NotificationType::NEWMAIL => "new-mail",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in New Issue