From 6ce93428a1e403282e1744d9600d7b19af7af7d5 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Tue, 20 Nov 2018 15:25:19 +0000 Subject: [PATCH 1/2] extension: Ensure signal disconnection Make sure we disconnect from the 'extension-state-changed' signal in the disable function even if dockManager failed to destroy properly. If we fail to disconnect from that signal, conditionallyenabledock will be called when the next extension is disabled, and ubuntu-dock will re-enable itself. --- extension.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/extension.js b/extension.js index 55e580f81..a342038c6 100644 --- a/extension.js +++ b/extension.js @@ -21,20 +21,24 @@ function enable() { * Listen to enabled extension, if Dash to Dock is on the list or become active, * we disable this dock. */ - dockManager=null; // even if declared, we need to initialize it to not trigger a referenceError. _extensionlistenerId = ExtensionSystem.connect('extension-state-changed', conditionallyenabledock); conditionallyenabledock(); } function disable() { - dockManager.destroy(); - - dockManager=null; - - if (_extensionlistenerId) { - ExtensionSystem.disconnect(_extensionlistenerId); - _extensionlistenerId = 0; + try { + if (dockManager != null) { + dockManager.destroy(); + dockManager = null; + } + } catch(e) { + log('Failed to destroy dockManager: %s'.format(e.message)); + } finally { + if (_extensionlistenerId) { + ExtensionSystem.disconnect(_extensionlistenerId); + _extensionlistenerId = 0; + } } } From c7085f72d1feaef638e6dcc22201df036578c14c Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Tue, 20 Nov 2018 15:26:29 +0000 Subject: [PATCH 2/2] extension: Use Array.prototype.every() --- extension.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/extension.js b/extension.js index a342038c6..203bfaae1 100644 --- a/extension.js +++ b/extension.js @@ -43,13 +43,9 @@ function disable() { } function conditionallyenabledock() { - let to_enable = true; - let runningExtensions = ExtensionSystem.extensionOrder; - for (let i = 0; i < runningExtensions.length; i++) { - if (runningExtensions[i] === "dash-to-dock@micxgx.gmail.com") { - to_enable = false; - } - } + let to_enable = ExtensionSystem.extensionOrder.every((e) => { + return e != 'dash-to-dock@micxgx.gmail.com'; + }); // enable or disable dock depending on dock status and to_enable state if (to_enable && !dockManager) {