[gnome-clocks: 2/3] timer: remove timeout on widget disposal



commit 00ea80dcf5ec0bf34a2bafde850bea3955a1d059
Author: Yanko Kaneti <yaneti declera com>
Date:   Sun Oct 28 15:17:56 2018 +0200

    timer: remove timeout on widget disposal

 src/timer.vala | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/src/timer.vala b/src/timer.vala
index 73ea374..5846479 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -80,6 +80,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
     private GLib.Settings settings;
     private double span;
     private GLib.Timer timer;
+    private uint timeout_id;
     private Utils.Bell bell;
     private GLib.Notification notification;
     [GtkChild]
@@ -121,6 +122,14 @@ public class Face : Gtk.Stack, Clocks.Clock {
         span = 0;
         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");
         notification = new GLib.Notification (_("Time is up!"));
         notification.set_body (_("Timer countdown finished"));
@@ -254,14 +263,16 @@ public class Face : Gtk.Stack, Clocks.Clock {
 
         state = State.RUNNING;
         timer.start ();
-        GLib.Timeout.add(40, () => {
+        timeout_id = GLib.Timeout.add(40, () => {
            if (state != State.RUNNING) {
+                timeout_id = 0;
                 return false;
             }
             var e = timer.elapsed ();
             if (e >= span) {
                 reset ();
                 ring ();
+                timeout_id = 0;
                 return false;
             }
             update_countdown (e);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]