зеркало из 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";
|
"use strict";
|
||||||
|
|
||||||
const { ADBScanner } = require("devtools/shared/adb/adb-scanner");
|
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
|
* This module provides a collection of helper methods to detect USB runtimes whom Firefox
|
||||||
|
@ -22,7 +22,6 @@ function disableUSBRuntimes() {
|
||||||
exports.disableUSBRuntimes = disableUSBRuntimes;
|
exports.disableUSBRuntimes = disableUSBRuntimes;
|
||||||
|
|
||||||
async function enableUSBRuntimes() {
|
async function enableUSBRuntimes() {
|
||||||
const adbAddon = getADBAddon();
|
|
||||||
if (adbAddon.status !== "installed") {
|
if (adbAddon.status !== "installed") {
|
||||||
console.error("ADB extension is not installed");
|
console.error("ADB extension is not installed");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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 Services = require("Services");
|
||||||
const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties");
|
const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties");
|
||||||
|
|
||||||
const {gDevTools} = require("devtools/client/framework/devtools");
|
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 {ADBScanner} = require("devtools/shared/adb/adb-scanner");
|
||||||
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
|
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
|
||||||
|
|
||||||
|
loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
|
||||||
|
|
||||||
window.addEventListener("load", function() {
|
window.addEventListener("load", function() {
|
||||||
document.querySelector("#aboutaddons").onclick = function() {
|
document.querySelector("#aboutaddons").onclick = function() {
|
||||||
const browserWin = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
const browserWin = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
||||||
|
@ -23,24 +24,18 @@ window.addEventListener("load", function() {
|
||||||
BuildUI();
|
BuildUI();
|
||||||
}, {capture: true, once: true});
|
}, {capture: true, once: true});
|
||||||
|
|
||||||
window.addEventListener("unload", function() {
|
|
||||||
forgetADBAddon();
|
|
||||||
}, {capture: true, once: true});
|
|
||||||
|
|
||||||
function CloseUI() {
|
function CloseUI() {
|
||||||
window.parent.UI.openProject();
|
window.parent.UI.openProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
function BuildUI() {
|
function BuildUI() {
|
||||||
const addon = getADBAddon();
|
|
||||||
|
|
||||||
function onAddonUpdate(arg) {
|
function onAddonUpdate(arg) {
|
||||||
progress.removeAttribute("value");
|
progress.removeAttribute("value");
|
||||||
li.setAttribute("status", addon.status);
|
li.setAttribute("status", adbAddon.status);
|
||||||
status.textContent = Strings.GetStringFromName("addons_status_" + addon.status);
|
status.textContent = Strings.GetStringFromName("addons_status_" + adbAddon.status);
|
||||||
if (addon.status == "installed") {
|
if (adbAddon.status == "installed") {
|
||||||
RuntimeScanners.add(ADBScanner);
|
RuntimeScanners.add(ADBScanner);
|
||||||
} else if (addon.status == "uninstalled") {
|
} else if (adbAddon.status == "uninstalled") {
|
||||||
RuntimeScanners.remove(ADBScanner);
|
RuntimeScanners.remove(ADBScanner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,18 +52,18 @@ function BuildUI() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addon.on("update", onAddonUpdate);
|
adbAddon.on("update", onAddonUpdate);
|
||||||
addon.on("failure", onAddonFailure);
|
adbAddon.on("failure", onAddonFailure);
|
||||||
addon.on("progress", onAddonProgress);
|
adbAddon.on("progress", onAddonProgress);
|
||||||
|
|
||||||
window.addEventListener("unload", function() {
|
window.addEventListener("unload", function() {
|
||||||
addon.off("update", onAddonUpdate);
|
adbAddon.off("update", onAddonUpdate);
|
||||||
addon.off("failure", onAddonFailure);
|
adbAddon.off("failure", onAddonFailure);
|
||||||
addon.off("progress", onAddonProgress);
|
adbAddon.off("progress", onAddonProgress);
|
||||||
}, {once: true});
|
}, {once: true});
|
||||||
|
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
li.setAttribute("status", addon.status);
|
li.setAttribute("status", adbAddon.status);
|
||||||
|
|
||||||
const name = document.createElement("span");
|
const name = document.createElement("span");
|
||||||
name.className = "name";
|
name.className = "name";
|
||||||
|
@ -80,18 +75,18 @@ function BuildUI() {
|
||||||
|
|
||||||
const status = document.createElement("span");
|
const status = document.createElement("span");
|
||||||
status.className = "status";
|
status.className = "status";
|
||||||
status.textContent = Strings.GetStringFromName("addons_status_" + addon.status);
|
status.textContent = Strings.GetStringFromName("addons_status_" + adbAddon.status);
|
||||||
li.appendChild(status);
|
li.appendChild(status);
|
||||||
|
|
||||||
const installButton = document.createElement("button");
|
const installButton = document.createElement("button");
|
||||||
installButton.className = "install-button";
|
installButton.className = "install-button";
|
||||||
installButton.onclick = () => addon.install();
|
installButton.onclick = () => adbAddon.install();
|
||||||
installButton.textContent = Strings.GetStringFromName("addons_install_button");
|
installButton.textContent = Strings.GetStringFromName("addons_install_button");
|
||||||
li.appendChild(installButton);
|
li.appendChild(installButton);
|
||||||
|
|
||||||
const uninstallButton = document.createElement("button");
|
const uninstallButton = document.createElement("button");
|
||||||
uninstallButton.className = "uninstall-button";
|
uninstallButton.className = "uninstall-button";
|
||||||
uninstallButton.onclick = () => addon.uninstall();
|
uninstallButton.onclick = () => adbAddon.uninstall();
|
||||||
uninstallButton.textContent = Strings.GetStringFromName("addons_uninstall_button");
|
uninstallButton.textContent = Strings.GetStringFromName("addons_uninstall_button");
|
||||||
li.appendChild(uninstallButton);
|
li.appendChild(uninstallButton);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* import-globals-from project-panel.js */
|
/* import-globals-from project-panel.js */
|
||||||
/* import-globals-from runtime-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 {gDevTools} = require("devtools/client/framework/devtools");
|
||||||
const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
|
const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
|
||||||
const {Toolbox} = require("devtools/client/framework/toolbox");
|
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 {AppManager} = require("devtools/client/webide/modules/app-manager");
|
||||||
const EventEmitter = require("devtools/shared/event-emitter");
|
const EventEmitter = require("devtools/shared/event-emitter");
|
||||||
const promise = require("promise");
|
const promise = require("promise");
|
||||||
const {getADBAddon} = require("devtools/shared/adb/adb-addon");
|
|
||||||
const {getJSON} = require("devtools/client/shared/getjson");
|
const {getJSON} = require("devtools/client/shared/getjson");
|
||||||
const Telemetry = require("devtools/client/shared/telemetry");
|
const Telemetry = require("devtools/client/shared/telemetry");
|
||||||
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
|
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
|
||||||
const {openContentLink} = require("devtools/client/shared/link");
|
const {openContentLink} = require("devtools/client/shared/link");
|
||||||
|
|
||||||
|
loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
|
||||||
|
|
||||||
const Strings =
|
const Strings =
|
||||||
Services.strings.createBundle("chrome://devtools/locale/webide.properties");
|
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.
|
// If the user decides to uninstall any of this addon, we won't install it again.
|
||||||
const autoinstallADBExtension = Services.prefs.getBoolPref("devtools.webide.autoinstallADBExtension");
|
const autoinstallADBExtension = Services.prefs.getBoolPref("devtools.webide.autoinstallADBExtension");
|
||||||
if (autoinstallADBExtension) {
|
if (autoinstallADBExtension) {
|
||||||
const adbAddon = getADBAddon();
|
|
||||||
adbAddon.install();
|
adbAddon.install();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
|
const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
|
||||||
const {Devices} = require("resource://devtools/shared/apps/Devices.jsm");
|
|
||||||
const Services = require("Services");
|
const Services = require("Services");
|
||||||
const EventEmitter = require("devtools/shared/event-emitter");
|
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() {
|
function ADBAddon() {
|
||||||
EventEmitter.decorate(this);
|
EventEmitter.decorate(this);
|
||||||
|
|
||||||
|
this._status = "unknown";
|
||||||
|
|
||||||
// This addon uses the string "linux" for "linux32"
|
// This addon uses the string "linux" for "linux32"
|
||||||
const fixedOS = OS == "linux32" ? "linux" : OS;
|
const fixedOS = OS == "linux32" ? "linux" : OS;
|
||||||
this.xpiLink = ADB_LINK.replace(/#OS#/g, fixedOS);
|
this.xpiLink = ADB_LINK.replace(/#OS#/g, fixedOS);
|
||||||
|
@ -63,10 +41,16 @@ function ADBAddon() {
|
||||||
this.uninstallOldExtension();
|
this.uninstallOldExtension();
|
||||||
|
|
||||||
this.updateInstallStatus();
|
this.updateInstallStatus();
|
||||||
|
|
||||||
|
const addonsListener = {};
|
||||||
|
addonsListener.onEnabled =
|
||||||
|
addonsListener.onDisabled =
|
||||||
|
addonsListener.onInstalled =
|
||||||
|
addonsListener.onUninstalled = () => this.updateInstallStatus();
|
||||||
|
AddonManager.addAddonListener(addonsListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADBAddon.prototype = {
|
ADBAddon.prototype = {
|
||||||
_status: "unknown",
|
|
||||||
set status(value) {
|
set status(value) {
|
||||||
Devices.adbExtensionInstalled = (value == "installed");
|
Devices.adbExtensionInstalled = (value == "installed");
|
||||||
if (this._status != value) {
|
if (this._status != value) {
|
||||||
|
@ -74,6 +58,7 @@ ADBAddon.prototype = {
|
||||||
this.emit("update");
|
this.emit("update");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get status() {
|
get status() {
|
||||||
return this._status;
|
return this._status;
|
||||||
},
|
},
|
||||||
|
@ -158,3 +143,5 @@ ADBAddon.prototype = {
|
||||||
this.installFailureHandler(install, "Install failed");
|
this.installFailureHandler(install, "Install failed");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.adbAddon = new ADBAddon();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче