diff --git a/src/main.rs b/src/main.rs index 2eace02..88c7ed8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use chrono::Local; use std::cell::Cell; use std::rc::Rc; +use gtk::gio::{Notification, NotificationPriority}; use gtk::glib; use gtk::glib::clone; use gtk::prelude::*; @@ -19,9 +20,9 @@ const DUR_MIN: f64 = 1.0; const INTERVAL_SEC: u32 = 1; fn main() -> glib::ExitCode { - let application = gtk::Application::builder().application_id(APP_ID).build(); - application.connect_activate(build_ui); - application.run() + let app = gtk::Application::builder().application_id(APP_ID).build(); + app.connect_activate(move |app| build_ui(app)); + app.run() } fn build_ui(app: >k::Application) { @@ -74,22 +75,27 @@ fn build_ui(app: >k::Application) { window.set_child(Some(&container)); window.present(); - // we are using a closure to capture the label (else we could also use a normal function) - let tick = move || { + let tick = clone!(@strong app => move || { if running.get() { progress += ((INTERVAL_SEC as f64) / 60.0) / DUR_MIN; progress_bar.set_fraction(progress); } if progress > 1.0 { - // todo + eprintln!("Time over."); + + // TODO: Notification does not show up + let notification = Notification::new("Alert"); + notification.set_body(Some("Time is over")); + notification.set_priority(NotificationPriority::Urgent); + app.send_notification(Some(APP_ID), ¬ification); } let time = current_time(); label.set_text(&time); // we could return glib::ControlFlow::Break to stop our clock after this tick glib::ControlFlow::Continue - }; + }); // executes the closure once every `INTERVAL_SEC` seconds glib::timeout_add_seconds_local(INTERVAL_SEC, tick);