[gnome-shell] MessageTray: remove source if associated application exits



commit c4dad3d2c12d6a076931467a0c0d9a054678df98
Author: Neha Doijode <ndoijode gmail com>
Date:   Tue Mar 8 04:40:10 2011 +0530

    MessageTray: remove source if associated application exits
    
    We don't want sources that are no longer associated with a running
    application to stick around in the message tray.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642659

 js/ui/notificationDaemon.js |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 7953b85..adfe870 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -435,6 +435,7 @@ Source.prototype = {
         MessageTray.Source.prototype._init.call(this, title);
 
         this._pid = pid;
+        this._appStateChangedId = 0;
         this._setApp();
         if (this.app)
             this.title = this.app.get_name();
@@ -459,6 +460,10 @@ Source.prototype = {
         if (!this.app)
             return;
 
+        // We only update the app if this.app is null, so we can't disconnect the old this._appStateChangedId
+        // even if it were non-zero for some reason.
+        this._appStateChangedId = this.app.connect('notify::state', Lang.bind(this,  this._appStateChanged));
+
         // Only override the icon if we were previously using
         // notification-based icons (ie, not a trayicon) or if it was unset before
         if (!this._isTrayIcon) {
@@ -482,6 +487,16 @@ Source.prototype = {
             this.destroy();
     },
 
+    _appStateChanged: function() {
+        // Destroy notification sources when their apps exit.
+        // The app exiting would normally result in a tray icon being removed,
+        // so it should be ok to destroy the source associated with a tray icon
+        // here too, however we just let that happen through the code path
+        // associated with the tray icon being removed.
+        if (!this._isTrayIcon && this.app.get_state() == Shell.AppState.STOPPED)
+            this.destroy();
+    },
+
     openApp: function() {
         if (this.app == null)
             return;
@@ -491,5 +506,13 @@ Source.prototype = {
             let mostRecentWindow = windows[0];
             Main.activateWindow(mostRecentWindow);
         }
+    },
+
+    destroy: function() {
+        if (this.app && this._appStateChangedId) {
+            this.app.disconnect(this._appStateChangedId);
+            this._appStateChangedId = 0;
+        }
+        MessageTray.Source.prototype.destroy.call(this);
     }
 };



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