Keep it to one notification per account

This commit is contained in:
Jon Gjengset 2019-02-16 16:22:26 -05:00
parent 49ae811259
commit 5d5b230891
No known key found for this signature in database
GPG Key ID: D64AC9D67176DC71
2 changed files with 24 additions and 15 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "buzz"
version = "1.1.4"
version = "1.1.5"
description = "A simple system tray application for notifying about unseen e-mail"
readme = "README.md"

View File

@ -95,6 +95,7 @@ impl<T: Read + Write + imap::extensions::idle::SetReadTimeout> Connection<T> {
) -> Result<(), imap::error::Error> {
// Keep track of all the e-mails we have already notified about
let mut last_notified = 0;
let mut notification = None::<notify_rust::NotificationHandle>;
loop {
// check current state of inbox
@ -165,24 +166,32 @@ impl<T: Read + Write + imap::extensions::idle::SetReadTimeout> Connection<T> {
);
// we want the n newest e-mail in reverse chronological order
let mut notification = String::new();
let mut body = String::new();
for subject in subjects.values().rev() {
notification.push_str("> ");
notification.push_str(subject);
notification.push_str("\n");
body.push_str("> ");
body.push_str(subject);
body.push_str("\n");
}
let notification = notification.trim_end();
let body = body.trim_end();
println!("! {}", title);
println!("{}", notification);
Notification::new()
.summary(&title)
.body(&format!("{}", askama_escape::escape(notification)))
.icon("notification-message-email")
.hint(NotificationHint::Category("email".to_owned()))
.timeout(-1)
.show()
.expect("failed to launch notify-send");
println!("{}", body);
if let Some(mut n) = notification.take() {
n.summary(&title)
.body(&format!("{}", askama_escape::escape(body)));
n.update();
} else {
notification = Some(
Notification::new()
.summary(&title)
.body(&format!("{}", askama_escape::escape(body)))
.icon("notification-message-email")
.hint(NotificationHint::Category("email.arrived".to_owned()))
.id(42) // for some reason, just updating isn't enough for dunst
.show()
.expect("failed to launch notify-send"),
);
}
}
tx.send((account, num_unseen)).unwrap();