From 17051290a6681ceb7bd379a418279647918ff2ed Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sun, 13 May 2018 17:01:56 -0700 Subject: [PATCH] dash: Only create trash/mount apps if they are turned on Previously, the apps always existed even if the icons were not shown. This meant that the event handling was still being done wastefully. So, let's only create the apps when they are actually needed. --- dash.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/dash.js b/dash.js index e1c67cb122..b98af2ada6 100644 --- a/dash.js +++ b/dash.js @@ -278,12 +278,6 @@ var MyDash = new Lang.Class({ this._appSystem = Shell.AppSystem.get_default(); - // Remove Drive Icons - this._removables = new Locations.Removables(); - - // Trash Icon - this._trash = new Locations.Trash(); - this._signalsHandler.add([ this._appSystem, 'installed-changed', @@ -311,14 +305,6 @@ var MyDash = new Lang.Class({ Main.overview, 'item-drag-cancelled', Lang.bind(this, this._onDragCancelled) - ], [ - this._trash, - 'changed', - Lang.bind(this, this._queueRedisplay) - ], [ - this._removables, - 'changed', - Lang.bind(this, this._queueRedisplay) ]); }, @@ -763,11 +749,31 @@ var MyDash = new Lang.Class({ } if (this._dtdSettings.get_boolean('show-mounts')) { + if (!this._removables) { + this._removables = new Locations.Removables(); + this._signalsHandler.addWithLabel('show-mounts', + [ this._removables, + 'changed', + Lang.bind(this, this._queueRedisplay) ]); + } Array.prototype.push.apply(newApps, this._removables.getApps()); + } else if (this._removables) { + this._signalsHandler.removeWithLabel('show-mounts'); + this._removables = null; } if (this._dtdSettings.get_boolean('show-trash')) { + if (!this._trash) { + this._trash = new Locations.Trash(); + this._signalsHandler.addWithLabel('show-trash', + [ this._trash, + 'changed', + Lang.bind(this, this._queueRedisplay) ]); + } newApps.push(this._trash.getApp()); + } else if (this._trash) { + this._signalsHandler.removeWithLabel('show-trash'); + this._trash = null; } // Figure out the actual changes to the list of items; we iterate