From aa8196aae8a1a5779a27706a9c1e398adf2ed0b0 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 4 Oct 2018 16:09:44 +0000 Subject: [PATCH] Bug 1494615 - Remove concept of availableAddons in WebIDE;r=ladybenko There is only one addon to manage in WebIDe, removing the concept of available addons will make it easier to move the ADBAddon module to a shared folder. Differential Revision: https://phabricator.services.mozilla.com/D7402 --HG-- extra : moz-landing-system : lando --- .../src/modules/usb-runtimes.js | 6 ++-- devtools/client/webide/content/addons.js | 30 +++++++------------ devtools/client/webide/content/webide.js | 6 ++-- devtools/client/webide/modules/addons.js | 19 +++++------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js b/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js index 8893510b9b11..29cf65389ecc 100644 --- a/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js +++ b/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js @@ -5,7 +5,7 @@ "use strict"; const { ADBScanner } = require("devtools/shared/adb/adb-scanner"); -const { GetAvailableAddons } = require("devtools/client/webide/modules/addons"); +const { getADBAddon } = require("devtools/client/webide/modules/addons"); /** * This module provides a collection of helper methods to detect USB runtimes whom Firefox @@ -22,8 +22,8 @@ function disableUSBRuntimes() { exports.disableUSBRuntimes = disableUSBRuntimes; async function enableUSBRuntimes() { - const { adb } = GetAvailableAddons(); - if (adb.status !== "installed") { + const adbAddon = getADBAddon(); + if (adbAddon.status !== "installed") { console.error("ADB extension is not installed"); return; } diff --git a/devtools/client/webide/content/addons.js b/devtools/client/webide/content/addons.js index 9d86f9f0ca35..4efaa047ce1a 100644 --- a/devtools/client/webide/content/addons.js +++ b/devtools/client/webide/content/addons.js @@ -5,7 +5,7 @@ const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {}); const Services = require("Services"); const {gDevTools} = require("devtools/client/framework/devtools"); -const {GetAvailableAddons, ForgetAddonsList} = require("devtools/client/webide/modules/addons"); +const {getADBAddon, forgetADBAddon} = require("devtools/client/webide/modules/addons"); const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties"); const {ADBScanner} = require("devtools/shared/adb/adb-scanner"); const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes"); @@ -18,22 +18,20 @@ window.addEventListener("load", function() { } }; document.querySelector("#close").onclick = CloseUI; - BuildUI(GetAvailableAddons()); + BuildUI(); }, {capture: true, once: true}); window.addEventListener("unload", function() { - ForgetAddonsList(); + forgetADBAddon(); }, {capture: true, once: true}); function CloseUI() { window.parent.UI.openProject(); } -function BuildUI(addons) { - BuildItem(addons.adb, "adb"); -} +function BuildUI() { + const addon = getADBAddon(); -function BuildItem(addon, type) { function onAddonUpdate(arg) { progress.removeAttribute("value"); li.setAttribute("status", addon.status); @@ -73,12 +71,8 @@ function BuildItem(addon, type) { const name = document.createElement("span"); name.className = "name"; - switch (type) { - case "adb": - li.setAttribute("addon", type); - name.textContent = "ADB Extension"; - break; - } + li.setAttribute("addon", "adb"); + name.textContent = "ADB Extension"; li.appendChild(name); @@ -102,12 +96,10 @@ function BuildItem(addon, type) { const progress = document.createElement("progress"); li.appendChild(progress); - if (type == "adb") { - const warning = document.createElement("p"); - warning.textContent = Strings.GetStringFromName("addons_adb_warning"); - warning.className = "warning"; - li.appendChild(warning); - } + const warning = document.createElement("p"); + warning.textContent = Strings.GetStringFromName("addons_adb_warning"); + warning.className = "warning"; + li.appendChild(warning); document.querySelector("ul").appendChild(li); } diff --git a/devtools/client/webide/content/webide.js b/devtools/client/webide/content/webide.js index 9018b86e0ad5..53c439c85d03 100644 --- a/devtools/client/webide/content/webide.js +++ b/devtools/client/webide/content/webide.js @@ -16,7 +16,7 @@ const {Connection} = require("devtools/shared/client/connection-manager"); const {AppManager} = require("devtools/client/webide/modules/app-manager"); const EventEmitter = require("devtools/shared/event-emitter"); const promise = require("promise"); -const {GetAvailableAddons} = require("devtools/client/webide/modules/addons"); +const {getADBAddon} = require("devtools/client/webide/modules/addons"); const {getJSON} = require("devtools/client/shared/getjson"); const Telemetry = require("devtools/client/shared/telemetry"); const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes"); @@ -86,8 +86,8 @@ var UI = { // If the user decides to uninstall any of this addon, we won't install it again. const autoinstallADBExtension = Services.prefs.getBoolPref("devtools.webide.autoinstallADBExtension"); if (autoinstallADBExtension) { - const addons = GetAvailableAddons(); - addons.adb.install(); + const adbAddon = getADBAddon(); + adbAddon.install(); } Services.prefs.setBoolPref("devtools.webide.autoinstallADBExtension", false); diff --git a/devtools/client/webide/modules/addons.js b/devtools/client/webide/modules/addons.js index b910a5482537..7379a79e7f29 100644 --- a/devtools/client/webide/modules/addons.js +++ b/devtools/client/webide/modules/addons.js @@ -34,23 +34,20 @@ addonsListener.onEnabled = addonsListener.onDisabled = addonsListener.onInstalled = addonsListener.onUninstalled = (updatedAddon) => { - const addons = GetAvailableAddons(); - addons.adb.updateInstallStatus(); + getADBAddon().updateInstallStatus(); }; AddonManager.addAddonListener(addonsListener); -var AvailableAddons = null; -var GetAvailableAddons = exports.GetAvailableAddons = function() { - if (!AvailableAddons) { - AvailableAddons = { - adb: new ADBAddon() - }; +var adbAddon = null; +var getADBAddon = exports.getADBAddon = function() { + if (!adbAddon) { + adbAddon = new ADBAddon(); } - return AvailableAddons; + return adbAddon; }; -exports.ForgetAddonsList = function() { - AvailableAddons = null; +exports.forgetADBAddon = function() { + adbAddon = null; }; function ADBAddon() {