[gnome-shell/wip/rstrode/rhel-7.9: 69/86] appDisplay: Don't leak duplicate items in AppView




commit 06f74e06aec005617e33130d9155d92be46aade9
Author: Ray Strode <rstrode redhat com>
Date:   Mon Jul 15 13:52:58 2019 -0400

    appDisplay: Don't leak duplicate items in AppView
    
    If an icon already exists in an app view with the same id, the
    duplicate is not added on a call to addItem.  Unfortunately,
    since it's not added, the icon actor gets orphaned and leaked.
    
    This commit address the problem by introducing a new hasItem
    method and disallowing callers to call addItem with a duplicate
    in the first place.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/628

 js/ui/appDisplay.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index b5a5d7cb30..7bd2b038f2 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -152,10 +152,14 @@ var BaseAppView = new Lang.Class({
         return this._allItems;
     },
 
+    hasItem(id) {
+        return this._items[id] !== undefined;
+    },
+
     addItem(icon) {
         let id = icon.id;
-        if (this._items[id] !== undefined)
-            return;
+        if (this.hasItem(id))
+            throw new Error(`icon with id ${id} already added to view`)
 
         this._allItems.push(icon);
         this._items[id] = icon;
@@ -512,6 +516,8 @@ var AllView = new Lang.Class({
 
         let folders = this._folderSettings.get_strv('folder-children');
         folders.forEach(id => {
+            if (this.hasItem(id))
+                return;
             let path = this._folderSettings.path + 'folders/' + id + '/';
             let icon = new FolderIcon(id, path, this);
             icon.connect('name-changed', this._itemNameChanged.bind(this));
@@ -1311,6 +1317,9 @@ var FolderIcon = new Lang.Class({
         let excludedApps = this._folder.get_strv('excluded-apps');
         let appSys = Shell.AppSystem.get_default();
         let addAppId = appId => {
+            if (this.view.hasItem(appId))
+                return;
+
             if (excludedApps.indexOf(appId) >= 0)
                 return;
 


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