[gnome-maps] notificationManager: Only allow one notification



commit b5c8ea2572cc78cca2aee75703dfb6a7d3635b76
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Mon Feb 29 08:37:30 2016 +0100

    notificationManager: Only allow one notification
    
    Do not stack notification on each other. Only allow one at a time.
    Add the next one after the current one has transitioned away.
    
    Also add a timeout of 5 seconds before auto-dismiss a notification.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760252

 src/notificationManager.js |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/src/notificationManager.js b/src/notificationManager.js
index 15247c4..caec17f 100644
--- a/src/notificationManager.js
+++ b/src/notificationManager.js
@@ -21,34 +21,51 @@
  */
 
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 
 const Notification = imports.notification;
 
+const _TIMEOUT = 5000; /* ms */
+
 const NotificationManager = new Lang.Class({
     Name: 'NotificationManager',
 
     _init: function(overlay) {
         this._overlay = overlay;
-        this._cache = {};
     },
 
-    showMessage: function (msg) {
-        let notification = new Notification.Plain(msg);
-        notification.connect('dismissed',
-                             notification.destroy.bind(notification));
-        this._overlay.add_overlay(notification);
-        notification.reveal();
-    },
-
-    showNotification: function(notification) {
-        if(notification.get_parent() !== this._overlay) {
-            this._overlay.add_overlay(notification);
-
+    _add: function(notification) {
+        this._current = notification;
+        if (!(notification instanceof Notification.Plain)) {
             let dismissId = notification.connect('dismissed', (function() {
                 this._overlay.remove(notification);
                 notification.disconnect(dismissId);
+                this._current = null;
             }).bind(this));
         }
+        this._overlay.add_overlay(notification);
+        Mainloop.timeout_add(_TIMEOUT, notification.dismiss.bind(notification));
         notification.reveal();
     },
+
+    showMessage: function (msg) {
+        let notification = new Notification.Plain(msg);
+        notification.connect('dismissed', (function() {
+            this._current = null;
+            notification.destroy();
+        }).bind(this));
+        this.showNotification(notification);
+    },
+
+    showNotification: function(notification) {
+        if(notification.get_parent() === this._overlay)
+            return;
+        if (!this._current) {
+            this._add(notification);
+        } else {
+            this._current.dismiss();
+            Mainloop.timeout_add(this._current.transition_duration,
+                                 this._add.bind(this, notification));
+        }
+    }
 });


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