Add a configuration variable to display a notification at the be… (#345)

This commit is contained in:
Roey Darwish Dror
2020-02-27 13:30:55 +02:00
committed by GitHub
parent 738d70c91d
commit 2392124f71
3 changed files with 35 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ struct Terminal {
prefix: String,
term: Term,
set_title: bool,
desktop_notification: bool,
}
impl Terminal {
@@ -46,9 +47,14 @@ impl Terminal {
.map(|prefix| format!("({}) ", prefix))
.unwrap_or_else(|_| String::new()),
set_title: true,
desktop_notification: false,
}
}
fn set_desktop_notifications(&mut self, desktop_notifications: bool) {
self.desktop_notification = desktop_notifications
}
fn set_title(&mut self, set_title: bool) {
self.set_title = set_title
}
@@ -58,6 +64,20 @@ impl Terminal {
self.term
.set_title(format!("{}Topgrade - {}", self.prefix, message.as_ref()));
}
#[cfg(target_os = "macos")]
{
if self.desktop_notification {
Notification::new()
.summary("Topgrade")
.body(message.as_ref())
.appname("topgrade")
.timeout(5)
.show()
.ok();
}
}
let now = Local::now();
let message = format!(
"{}{:02}:{:02}:{:02} - {}",
@@ -225,3 +245,10 @@ pub fn get_char() -> char {
pub fn set_title(set_title: bool) {
TERMINAL.lock().unwrap().set_title(set_title);
}
pub fn set_desktop_notifications(desktop_notifications: bool) {
TERMINAL
.lock()
.unwrap()
.set_desktop_notifications(desktop_notifications);
}