wip: add notification
This commit is contained in:
parent
2201e57ffb
commit
3f4d41958e
20
src/main.rs
20
src/main.rs
@ -8,6 +8,7 @@ use chrono::Local;
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use gtk::gio::{Notification, NotificationPriority};
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
use gtk::glib::clone;
|
use gtk::glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
@ -19,9 +20,9 @@ const DUR_MIN: f64 = 1.0;
|
|||||||
const INTERVAL_SEC: u32 = 1;
|
const INTERVAL_SEC: u32 = 1;
|
||||||
|
|
||||||
fn main() -> glib::ExitCode {
|
fn main() -> glib::ExitCode {
|
||||||
let application = gtk::Application::builder().application_id(APP_ID).build();
|
let app = gtk::Application::builder().application_id(APP_ID).build();
|
||||||
application.connect_activate(build_ui);
|
app.connect_activate(move |app| build_ui(app));
|
||||||
application.run()
|
app.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_ui(app: >k::Application) {
|
fn build_ui(app: >k::Application) {
|
||||||
@ -74,22 +75,27 @@ fn build_ui(app: >k::Application) {
|
|||||||
window.set_child(Some(&container));
|
window.set_child(Some(&container));
|
||||||
window.present();
|
window.present();
|
||||||
|
|
||||||
// we are using a closure to capture the label (else we could also use a normal function)
|
let tick = clone!(@strong app => move || {
|
||||||
let tick = move || {
|
|
||||||
if running.get() {
|
if running.get() {
|
||||||
progress += ((INTERVAL_SEC as f64) / 60.0) / DUR_MIN;
|
progress += ((INTERVAL_SEC as f64) / 60.0) / DUR_MIN;
|
||||||
progress_bar.set_fraction(progress);
|
progress_bar.set_fraction(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if progress > 1.0 {
|
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();
|
let time = current_time();
|
||||||
label.set_text(&time);
|
label.set_text(&time);
|
||||||
// we could return glib::ControlFlow::Break to stop our clock after this tick
|
// we could return glib::ControlFlow::Break to stop our clock after this tick
|
||||||
glib::ControlFlow::Continue
|
glib::ControlFlow::Continue
|
||||||
};
|
});
|
||||||
|
|
||||||
// executes the closure once every `INTERVAL_SEC` seconds
|
// executes the closure once every `INTERVAL_SEC` seconds
|
||||||
glib::timeout_add_seconds_local(INTERVAL_SEC, tick);
|
glib::timeout_add_seconds_local(INTERVAL_SEC, tick);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user