feat: add system notification when timers finish

This commit is contained in:
Stevan Freeborn
2026-07-22 22:36:41 -05:00
parent f2da97f216
commit 7adb766926
3 changed files with 778 additions and 6 deletions
+28 -2
View File
@@ -6,12 +6,19 @@ use std::{
};
use crossterm::{
ExecutableCommand, event::{self, Event, KeyCode, KeyModifiers}, terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
ExecutableCommand,
event::{self, Event, KeyCode, KeyModifiers},
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
};
use figlet_rs::Toilet;
use notify_rust::Notification;
use ratatui::{
Terminal, backend::CrosstermBackend, layout::{Alignment, Constraint, Direction, Layout}, style::{Color, Style}, widgets::{Block, Borders, Clear, Paragraph},
Terminal,
backend::CrosstermBackend,
layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Style},
widgets::{Block, Borders, Clear, Paragraph},
};
const SECONDS_PER_MIN: i64 = 60;
@@ -23,6 +30,19 @@ enum TimerState {
Paused,
}
fn send_desktop_notification(title: &str, body: &str) {
let title = title.to_string();
let body = body.to_string();
std::thread::spawn(move || {
let _ = Notification::new()
.summary(&title)
.body(&body)
.appname("termato")
.show();
});
}
struct Termato {
work_mins: i64,
break_mins: i64,
@@ -81,6 +101,12 @@ impl Termato {
self.time_remaining_in_sec -= 1;
if self.time_remaining_in_sec == 0 {
if self.state == TimerState::Work {
send_desktop_notification("Work Done", "Time to take a break.");
} else {
send_desktop_notification("Break Over", "Time to focus.");
}
self.toggle_mode();
}
}