Use lib for notifications

Should help with #2, and maybe #1, at least if the comment by @hoodie in
https://github.com/hoodie/notify-rust/issues/10 comes to fruition.
Certainly a step up from running notify-send manually.
This commit is contained in:
Jon Gjengset 2017-03-02 14:28:29 -05:00
parent 2a14a41a30
commit 81d61ce82c
No known key found for this signature in database
GPG Key ID: D64AC9D67176DC71
3 changed files with 30 additions and 8 deletions

20
Cargo.lock generated
View File

@ -4,6 +4,7 @@ version = "0.1.0"
dependencies = [
"imap 0.0.6 (git+https://github.com/jonhoo/rust-imap.git?branch=idle)",
"mailparse 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"notify-rust 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"systray 0.1.1 (git+https://github.com/qdot/systray-rs.git?branch=linux-core)",
"toml 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -156,6 +157,15 @@ dependencies = [
"vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dbus"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.1"
@ -508,6 +518,14 @@ name = "nom"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "notify-rust"
version = "3.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dbus 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.37"
@ -940,6 +958,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
"checksum clang-sys 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f98f0715ff67f27ca6a2f8f0ffc2a56f8edbc7acd57489c29eadc3a15c4eafe"
"checksum clap 2.20.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7db281b0520e97fbd15cd615dcd8f8bcad0c26f5f7d5effe705f090f39e9a758"
"checksum dbus 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "58ec7b4cac6f79f36af1cd9cfdb9b935fc5a4e899f494ee03a3a6165f7d10b4b"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
@ -977,6 +996,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
"checksum notify-rust 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26508471f9e6ee12ebe949ece86ff01153e5d9a9ca331e0a6e9661502fb4e9a9"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum openssl 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "c4117b6244aac42ed0150a6019b4d953d28247c5dd6ae6f46ae469b5f2318733"
"checksum openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)" = "89c47ee94c352eea9ddaf8e364be7f978a3bb6d66d73176572484238dd5a5c3f"

View File

@ -22,3 +22,4 @@ systray = { git = "https://github.com/qdot/systray-rs.git", branch = "linux-core
mailparse = "0.5.1"
toml = "0.3.1"
xdg = "2.0.0"
notify-rust = "3.2.1"

View File

@ -4,6 +4,7 @@ extern crate imap;
extern crate openssl;
extern crate systray;
extern crate mailparse;
extern crate notify_rust;
use openssl::ssl::{SslContext, SslMethod};
use imap::client::Client;
@ -197,16 +198,16 @@ fn main() {
}
if !subjects.is_empty() {
use notify_rust::{Notification, NotificationHint};
let title = format!("@{} has new mail ({} unseen)", account, num_unseen);
let notification = format!("> {}", subjects.join("\n> "));
Command::new("/usr/bin/notify-send")
.arg("-i")
.arg("notification-message-email")
.arg("-c")
.arg("email")
.arg(title)
.arg(notification)
.status()
Notification::new()
.summary(&title)
.body(&notification)
.icon("notification-message-email")
.hint(NotificationHint::Category("email".to_owned()))
.timeout(-1)
.show()
.expect("failed to launch notify-send");
}