зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1494615 - Update adb-addon module to expose a singleton;r=ladybenko
Depends on D7403 The getADBAddon/forgetADBAddon is not removing listeners or doing anything useful since the next call to getADBADdon will just recreate an instance of ADBAddon. We can expose a singleton and use lazy requires to achieve the same effect Differential Revision: https://phabricator.services.mozilla.com/D7404 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c1aabb3bca
Коммит
c1b5abb562
|
@ -5,7 +5,7 @@
|
|||
"use strict";
|
||||
|
||||
const { ADBScanner } = require("devtools/shared/adb/adb-scanner");
|
||||
const { getADBAddon } = require("devtools/shared/adb/adb-addon");
|
||||
loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
|
||||
|
||||
/**
|
||||
* This module provides a collection of helper methods to detect USB runtimes whom Firefox
|
||||
|
@ -22,7 +22,6 @@ function disableUSBRuntimes() {
|
|||
exports.disableUSBRuntimes = disableUSBRuntimes;
|
||||
|
||||
async function enableUSBRuntimes() {
|
||||
const adbAddon = getADBAddon();
|
||||
if (adbAddon.status !== "installed") {
|
||||
console.error("ADB extension is not installed");
|
||||
return;
|
||||
|
|
|
@ -2,16 +2,17 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const {loader, require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
|
||||
|
||||
const Services = require("Services");
|
||||
const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties");
|
||||
|
||||
const {gDevTools} = require("devtools/client/framework/devtools");
|
||||
const {getADBAddon, forgetADBAddon} = require("devtools/shared/adb/adb-addon");
|
||||
const {ADBScanner} = require("devtools/shared/adb/adb-scanner");
|
||||
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
|
||||
|
||||
loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
|
||||
|
||||
window.addEventListener("load", function() {
|
||||
document.querySelector("#aboutaddons").onclick = function() {
|
||||
const browserWin = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
||||
|
@ -23,24 +24,18 @@ window.addEventListener("load", function() {
|
|||
BuildUI();
|
||||
}, {capture: true, once: true});
|
||||
|
||||
window.addEventListener("unload", function() {
|
||||
forgetADBAddon();
|
||||
}, {capture: true, once: true});
|
||||
|
||||
function CloseUI() {
|
||||
window.parent.UI.openProject();
|
||||
}
|
||||
|
||||
function BuildUI() {
|
||||
const addon = getADBAddon();
|
||||
|
||||
function onAddonUpdate(arg) {
|
||||
progress.removeAttribute("value");
|
||||
li.setAttribute("status", addon.status);
|
||||
status.textContent = Strings.GetStringFromName("addons_status_" + addon.status);
|
||||
if (addon.status == "installed") {
|
||||
li.setAttribute("status", adbAddon.status);
|
||||
status.textContent = Strings.GetStringFromName("addons_status_" + adbAddon.status);
|
||||
if (adbAddon.status == "installed") {
|
||||
RuntimeScanners.add(ADBScanner);
|
||||
} else if (addon.status == "uninstalled") {
|
||||
} else if (adbAddon.status == "uninstalled") {
|
||||
RuntimeScanners.remove(ADBScanner);
|
||||
}
|
||||
}
|
||||
|
@ -57,18 +52,18 @@ function BuildUI() {
|
|||
}
|
||||
}
|
||||
|
||||
addon.on("update", onAddonUpdate);
|
||||
addon.on("failure", onAddonFailure);
|
||||
addon.on("progress", onAddonProgress);
|
||||
adbAddon.on("update", onAddonUpdate);
|
||||
adbAddon.on("failure", onAddonFailure);
|
||||
adbAddon.on("progress", onAddonProgress);
|
||||
|
||||
window.addEventListener("unload", function() {
|
||||
addon.off("update", onAddonUpdate);
|
||||
addon.off("failure", onAddonFailure);
|
||||
addon.off("progress", onAddonProgress);
|
||||
adbAddon.off("update", onAddonUpdate);
|
||||
adbAddon.off("failure", onAddonFailure);
|
||||
adbAddon.off("progress", onAddonProgress);
|
||||
}, {once: true});
|
||||
|
||||
const li = document.createElement("li");
|
||||
li.setAttribute("status", addon.status);
|
||||
li.setAttribute("status", adbAddon.status);
|
||||
|
||||
const name = document.createElement("span");
|
||||
name.className = "name";
|
||||
|
@ -80,18 +75,18 @@ function BuildUI() {
|
|||
|
||||
const status = document.createElement("span");
|
||||
status.className = "status";
|
||||
status.textContent = Strings.GetStringFromName("addons_status_" + addon.status);
|
||||
status.textContent = Strings.GetStringFromName("addons_status_" + adbAddon.status);
|
||||
li.appendChild(status);
|
||||
|
||||
const installButton = document.createElement("button");
|
||||
installButton.className = "install-button";
|
||||
installButton.onclick = () => addon.install();
|
||||
installButton.onclick = () => adbAddon.install();
|
||||
installButton.textContent = Strings.GetStringFromName("addons_install_button");
|
||||
li.appendChild(installButton);
|
||||
|
||||
const uninstallButton = document.createElement("button");
|
||||
uninstallButton.className = "uninstall-button";
|
||||
uninstallButton.onclick = () => addon.uninstall();
|
||||
uninstallButton.onclick = () => adbAddon.uninstall();
|
||||
uninstallButton.textContent = Strings.GetStringFromName("addons_uninstall_button");
|
||||
li.appendChild(uninstallButton);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* import-globals-from project-panel.js */
|
||||
/* import-globals-from runtime-panel.js */
|
||||
|
||||
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const {loader, require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const {gDevTools} = require("devtools/client/framework/devtools");
|
||||
const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
|
||||
const {Toolbox} = require("devtools/client/framework/toolbox");
|
||||
|
@ -16,12 +16,13 @@ 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 {getADBAddon} = require("devtools/shared/adb/adb-addon");
|
||||
const {getJSON} = require("devtools/client/shared/getjson");
|
||||
const Telemetry = require("devtools/client/shared/telemetry");
|
||||
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
|
||||
const {openContentLink} = require("devtools/client/shared/link");
|
||||
|
||||
loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
|
||||
|
||||
const Strings =
|
||||
Services.strings.createBundle("chrome://devtools/locale/webide.properties");
|
||||
|
||||
|
@ -86,7 +87,6 @@ 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 adbAddon = getADBAddon();
|
||||
adbAddon.install();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"use strict";
|
||||
|
||||
const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
|
||||
const {Devices} = require("resource://devtools/shared/apps/Devices.jsm");
|
||||
const Services = require("Services");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
|
||||
|
@ -29,32 +28,11 @@ if (platform.includes("Win")) {
|
|||
}
|
||||
}
|
||||
|
||||
const addonsListener = {};
|
||||
addonsListener.onEnabled =
|
||||
addonsListener.onDisabled =
|
||||
addonsListener.onInstalled =
|
||||
addonsListener.onUninstalled = (updatedAddon) => {
|
||||
getADBAddon().updateInstallStatus();
|
||||
};
|
||||
AddonManager.addAddonListener(addonsListener);
|
||||
|
||||
// adbAddon is the exposed singleton for ADBAddon.
|
||||
let adbAddon = null;
|
||||
function getADBAddon() {
|
||||
if (!adbAddon) {
|
||||
adbAddon = new ADBAddon();
|
||||
}
|
||||
return adbAddon;
|
||||
}
|
||||
exports.getADBAddon = getADBAddon;
|
||||
|
||||
exports.forgetADBAddon = function() {
|
||||
adbAddon = null;
|
||||
};
|
||||
|
||||
function ADBAddon() {
|
||||
EventEmitter.decorate(this);
|
||||
|
||||
this._status = "unknown";
|
||||
|
||||
// This addon uses the string "linux" for "linux32"
|
||||
const fixedOS = OS == "linux32" ? "linux" : OS;
|
||||
this.xpiLink = ADB_LINK.replace(/#OS#/g, fixedOS);
|
||||
|
@ -63,10 +41,16 @@ function ADBAddon() {
|
|||
this.uninstallOldExtension();
|
||||
|
||||
this.updateInstallStatus();
|
||||
|
||||
const addonsListener = {};
|
||||
addonsListener.onEnabled =
|
||||
addonsListener.onDisabled =
|
||||
addonsListener.onInstalled =
|
||||
addonsListener.onUninstalled = () => this.updateInstallStatus();
|
||||
AddonManager.addAddonListener(addonsListener);
|
||||
}
|
||||
|
||||
ADBAddon.prototype = {
|
||||
_status: "unknown",
|
||||
set status(value) {
|
||||
Devices.adbExtensionInstalled = (value == "installed");
|
||||
if (this._status != value) {
|
||||
|
@ -74,6 +58,7 @@ ADBAddon.prototype = {
|
|||
this.emit("update");
|
||||
}
|
||||
},
|
||||
|
||||
get status() {
|
||||
return this._status;
|
||||
},
|
||||
|
@ -158,3 +143,5 @@ ADBAddon.prototype = {
|
|||
this.installFailureHandler(install, "Install failed");
|
||||
},
|
||||
};
|
||||
|
||||
exports.adbAddon = new ADBAddon();
|
||||
|
|
Загрузка…
Ссылка в новой задаче