[gnome-shell] messageTray: Dispose Notification on destroy



commit ed97f61750c808f25c835ac38a4969ff721191e7
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Tue May 14 03:58:58 2019 +0200

    messageTray: Dispose Notification on destroy
    
    When the notification is destroyed we should also dispose the underneath GLib
    object, and ensure that we don't dispose this twice.
    
    In order to avoid this, don't destroy transient notifications that have been
    already been removed and only destroy the resident notifications on activation
    if they have not been destroyed earlier.
    Thus connect after to the 'activated' signal and once the default handler has
    been called destroy the notification if not requested earlier.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559

 js/ui/messageTray.js | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 7ee9ff8867..fda7f5bec6 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -370,7 +370,6 @@ var Notification = GObject.registerClass({
         this.source = source;
         this.title = title;
         this.urgency = Urgency.NORMAL;
-        this.resident = false;
         // 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
         this.isTransient = false;
         this.privacyScope = PrivacyScope.USER;
@@ -382,6 +381,7 @@ var Notification = GObject.registerClass({
         this._soundFile = null;
         this._soundPlayed = false;
         this.actions = [];
+        this.setResident(false);
 
         // If called with only one argument we assume the caller
         // will call .update() later on. This is the case of
@@ -460,6 +460,15 @@ var Notification = GObject.registerClass({
 
     setResident(resident) {
         this.resident = resident;
+
+        if (this.resident) {
+            if (this._activatedId) {
+                this.disconnect(this._activatedId);
+                this._activatedId = 0;
+            }
+        } else if (!this._activatedId) {
+            this._activatedId = this.connect_after('activated', () => this.destroy());
+        }
     }
 
     setTransient(isTransient) {
@@ -501,12 +510,16 @@ var Notification = GObject.registerClass({
 
     activate() {
         this.emit('activated');
-        if (!this.resident)
-            this.destroy();
     }
 
     destroy(reason = NotificationDestroyedReason.DISMISSED) {
+        if (this._activatedId) {
+            this.disconnect(this._activatedId);
+            delete this._activatedId;
+        }
+
         this.emit('destroy', reason);
+        this.run_dispose();
     }
 });
 
@@ -1494,7 +1507,7 @@ var MessageTray = class MessageTray {
     _hideNotificationCompleted() {
         let notification = this._notification;
         this._notification = null;
-        if (notification.isTransient)
+        if (!this._notificationRemoved && notification.isTransient)
             notification.destroy(NotificationDestroyedReason.EXPIRED);
 
         this._pointerInNotification = false;


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