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

128
Cargo.lock generated
View File

@ -132,6 +132,12 @@ dependencies = [
"constant_time_eq",
]
[[package]]
name = "block"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
name = "byteorder"
version = "1.3.4"
@ -159,6 +165,17 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
dependencies = [
"num-integer",
"num-traits",
"time",
]
[[package]]
name = "clang-sys"
version = "0.29.3"
@ -320,6 +337,16 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "dbus"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48b5f0f36f1eebe901b0e6bee369a77ed3396334bf3f09abd46454a576f71819"
dependencies = [
"libc",
"libdbus-sys",
]
[[package]]
name = "directories"
version = "2.0.2"
@ -330,6 +357,17 @@ dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.8",
]
[[package]]
name = "dirs-sys"
version = "0.3.4"
@ -350,6 +388,7 @@ dependencies = [
"clap",
"crossterm",
"directories",
"notify-rust",
"rodio",
]
@ -476,6 +515,15 @@ version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f"
[[package]]
name = "libdbus-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0"
dependencies = [
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.5.2"
@ -504,6 +552,18 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "mac-notification-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dfb6b71a9a89cd38b395d994214297447e8e63b1ba5708a9a2b0b1048ceda76"
dependencies = [
"cc",
"chrono",
"dirs",
"objc-foundation",
]
[[package]]
name = "mach"
version = "0.3.2"
@ -513,6 +573,15 @@ dependencies = [
"libc",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
dependencies = [
"libc",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
@ -616,6 +685,26 @@ dependencies = [
"version_check",
]
[[package]]
name = "notify-rust"
version = "3.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8da29142be3f71b2165a6b3991c26045b674edbf04cdfc42f323094fc3e4b5a"
dependencies = [
"dbus",
"mac-notification-sys",
]
[[package]]
name = "num-integer"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.11"
@ -635,6 +724,35 @@ dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "ogg"
version = "0.7.0"
@ -888,6 +1006,16 @@ dependencies = [
"syn",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"winapi 0.3.8",
]
[[package]]
name = "tinyvec"
version = "0.3.3"

View File

@ -12,3 +12,4 @@ clap = "2.33.1"
directories = "2.0.2"
async-std = "1.5.0"
crossterm = "0.17.4"
notify-rust = "3.6.3"

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)]