Keep it to one notification per account
This commit is contained in:
parent
49ae811259
commit
5d5b230891
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "buzz"
|
name = "buzz"
|
||||||
version = "1.1.4"
|
version = "1.1.5"
|
||||||
|
|
||||||
description = "A simple system tray application for notifying about unseen e-mail"
|
description = "A simple system tray application for notifying about unseen e-mail"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -95,6 +95,7 @@ impl<T: Read + Write + imap::extensions::idle::SetReadTimeout> Connection<T> {
|
||||||
) -> Result<(), imap::error::Error> {
|
) -> Result<(), imap::error::Error> {
|
||||||
// Keep track of all the e-mails we have already notified about
|
// Keep track of all the e-mails we have already notified about
|
||||||
let mut last_notified = 0;
|
let mut last_notified = 0;
|
||||||
|
let mut notification = None::<notify_rust::NotificationHandle>;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// check current state of inbox
|
// 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
|
// 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() {
|
for subject in subjects.values().rev() {
|
||||||
notification.push_str("> ");
|
body.push_str("> ");
|
||||||
notification.push_str(subject);
|
body.push_str(subject);
|
||||||
notification.push_str("\n");
|
body.push_str("\n");
|
||||||
}
|
}
|
||||||
let notification = notification.trim_end();
|
let body = body.trim_end();
|
||||||
|
|
||||||
println!("! {}", title);
|
println!("! {}", title);
|
||||||
println!("{}", notification);
|
println!("{}", body);
|
||||||
Notification::new()
|
if let Some(mut n) = notification.take() {
|
||||||
.summary(&title)
|
n.summary(&title)
|
||||||
.body(&format!("{}", askama_escape::escape(notification)))
|
.body(&format!("{}", askama_escape::escape(body)));
|
||||||
.icon("notification-message-email")
|
n.update();
|
||||||
.hint(NotificationHint::Category("email".to_owned()))
|
} else {
|
||||||
.timeout(-1)
|
notification = Some(
|
||||||
.show()
|
Notification::new()
|
||||||
.expect("failed to launch notify-send");
|
.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();
|
tx.send((account, num_unseen)).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue