Implement toast notification on macOS and Linux

This commit is contained in:
Rekai Musuka
2020-05-24 19:27:46 -05:00
parent bc9080fe2f
commit b1b469f91f
3 changed files with 165 additions and 0 deletions

View File

@@ -137,6 +137,8 @@ pub mod pomodoro {
self.next();
self.alert.play();
Self::notify(&self.state);
match self.state {
State::Work => {
Self::send_to_clock(&tx, self.state, config.work_time);
@@ -167,6 +169,40 @@ pub mod pomodoro {
tx.send(status).unwrap();
}
#[cfg(any(target_os = "macos", target_os = "linux"))]
fn notify(state: &State) {
let mut toast = notify_rust::Notification::new();
match state {
State::Work => {
toast
.summary("Time to Work!")
.body("Remember to stay focused!")
.show()
.unwrap();
}
State::ShortBreak | State::LongBreak => {
toast
.summary("Break Time!")
.body("Enjoy your well deserved rest!")
.show()
.unwrap();
}
State::Inactive => {
toast
.summary("Pomodoro Cycle Complete.")
.body("Now waiting for user input....")
.show()
.unwrap();
}
}
}
#[cfg(target_os = "windows")]
fn notify(state: &State) {
unimplemented!();
}
}
#[derive(Copy, Clone, Debug)]