Skip to content

Commit 799732a

Browse files
authored
Add desktop notifications on pomodoro timer end (#9)
1 parent efe2d1a commit 799732a

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
299299
}
300300

301301
if pomo.tick_1s() {
302+
pomo.notify();
302303
pomo.play_notification();
303304
// Restore volume after a delay (notification lasts ~1.5s)
304305
let vol_handle = radio.volume_handle();

src/pomodoro.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ impl Pomodoro {
8282
(secs / 60, secs % 60)
8383
}
8484

85+
pub fn notify(&self) {
86+
let (title, body) = match self.mode {
87+
Mode::Focus => ("Time to focus", "Focus session started. Let's go."),
88+
Mode::Break => ("Take a break", "Break time. Step away for a bit."),
89+
};
90+
thread::spawn(move || {
91+
#[cfg(target_os = "macos")]
92+
{
93+
let script = format!(
94+
"display notification \"{}\" with title \"{}\"",
95+
body, title
96+
);
97+
let _ = std::process::Command::new("osascript")
98+
.args(["-e", &script])
99+
.output();
100+
}
101+
#[cfg(target_os = "linux")]
102+
{
103+
let _ = std::process::Command::new("notify-send")
104+
.args([title, body])
105+
.output();
106+
}
107+
});
108+
}
109+
85110
pub fn play_notification(&self) {
86111
let is_focus = matches!(self.mode, Mode::Focus);
87112
thread::spawn(move || {

0 commit comments

Comments
 (0)