Commit 00ea80dc authored by Yanko Kaneti's avatar Yanko Kaneti

timer: remove timeout on widget disposal

parent 14005c78
...@@ -80,6 +80,7 @@ public class Face : Gtk.Stack, Clocks.Clock { ...@@ -80,6 +80,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
private GLib.Settings settings; private GLib.Settings settings;
private double span; private double span;
private GLib.Timer timer; private GLib.Timer timer;
private uint timeout_id;
private Utils.Bell bell; private Utils.Bell bell;
private GLib.Notification notification; private GLib.Notification notification;
[GtkChild] [GtkChild]
...@@ -121,6 +122,14 @@ public class Face : Gtk.Stack, Clocks.Clock { ...@@ -121,6 +122,14 @@ public class Face : Gtk.Stack, Clocks.Clock {
span = 0; span = 0;
timer = new GLib.Timer (); timer = new GLib.Timer ();
timeout_id = 0;
destroy.connect(() => {
if (timeout_id != 0) {
GLib.Source.remove(timeout_id);
timeout_id = 0;
}
});
bell = new Utils.Bell ("complete"); bell = new Utils.Bell ("complete");
notification = new GLib.Notification (_("Time is up!")); notification = new GLib.Notification (_("Time is up!"));
notification.set_body (_("Timer countdown finished")); notification.set_body (_("Timer countdown finished"));
...@@ -254,14 +263,16 @@ public class Face : Gtk.Stack, Clocks.Clock { ...@@ -254,14 +263,16 @@ public class Face : Gtk.Stack, Clocks.Clock {
state = State.RUNNING; state = State.RUNNING;
timer.start (); timer.start ();
GLib.Timeout.add(40, () => { timeout_id = GLib.Timeout.add(40, () => {
if (state != State.RUNNING) { if (state != State.RUNNING) {
timeout_id = 0;
return false; return false;
} }
var e = timer.elapsed (); var e = timer.elapsed ();
if (e >= span) { if (e >= span) {
reset (); reset ();
ring (); ring ();
timeout_id = 0;
return false; return false;
} }
update_countdown (e); update_countdown (e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment