[gnome-boxes/release-gnome-3-36-2: 8/10] notification: Keep track of source IDs



commit f14a05e4fcbcdb0fadb6041d2bd523e86e6e348f
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Mar 26 12:53:32 2020 +0100

    notification: Keep track of source IDs

 src/notification.vala | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/notification.vala b/src/notification.vala
index 32c5228a..627f4953 100644
--- a/src/notification.vala
+++ b/src/notification.vala
@@ -20,6 +20,8 @@
     [GtkChild]
     private Gtk.Button close_button;
 
+    private uint notification_timeout_id = 0;
+
     public Notification (string             message,
                          MessageType        message_type,
                          string?            ok_label,
@@ -31,10 +33,12 @@ public Notification (string             message,
          * lets use the respective property setter method.
          */
         set_reveal_child (true);
-        uint notification_timeout_id = 0;
 
         this.timeout = timeout;
+
         notification_timeout_id = Timeout.add_seconds (this.timeout, () => {
+            notification_timeout_id = 0;
+
             dismissed ();
             return Source.REMOVE;
         });
@@ -43,7 +47,11 @@ public Notification (string             message,
             if (dismiss_func != null)
                 dismiss_func ();
             set_reveal_child(false);
-            Source.remove(notification_timeout_id);
+
+            if (notification_timeout_id != 0) {
+                Source.remove (notification_timeout_id);
+                notification_timeout_id = 0;
+            }
         });
 
         message_label.label = message;
@@ -55,7 +63,11 @@ public Notification (string             message,
                 if (ok_func != null)
                     ok_func ();
                 set_reveal_child(false);
-                Source.remove(notification_timeout_id);
+
+                if (notification_timeout_id != 0) {
+                    Source.remove(notification_timeout_id);
+                    notification_timeout_id = 0;
+                }
             });
 
             ok_button.show_all ();


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