зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1081093 - Auto-install Tools Adapter add-on in WebIDE. r=jryans
This commit is contained in:
Родитель
b33d528c76
Коммит
362af65779
|
@ -30,13 +30,14 @@ function CloseUI() {
|
|||
}
|
||||
|
||||
function BuildUI(addons) {
|
||||
BuildItem(addons.adb, true /* is adb */);
|
||||
BuildItem(addons.adb, "adb");
|
||||
BuildItem(addons.adapters, "adapters");
|
||||
for (let addon of addons.simulators) {
|
||||
BuildItem(addon, false /* is adb */);
|
||||
BuildItem(addon, "simulator");
|
||||
}
|
||||
}
|
||||
|
||||
function BuildItem(addon, isADB) {
|
||||
function BuildItem(addon, type) {
|
||||
|
||||
function onAddonUpdate(event, arg) {
|
||||
switch (event) {
|
||||
|
@ -73,20 +74,29 @@ function BuildItem(addon, isADB) {
|
|||
let li = document.createElement("li");
|
||||
li.setAttribute("status", addon.status);
|
||||
|
||||
// Used in tests
|
||||
if (isADB) {
|
||||
li.setAttribute("addon", "adb");
|
||||
} else {
|
||||
li.setAttribute("addon", "simulator-" + addon.version);
|
||||
}
|
||||
|
||||
let name = document.createElement("span");
|
||||
name.className = "name";
|
||||
if (isADB) {
|
||||
name.textContent = Strings.GetStringFromName("addons_adb_label");
|
||||
} else {
|
||||
let stability = Strings.GetStringFromName("addons_" + addon.stability);
|
||||
name.textContent = Strings.formatStringFromName("addons_simulator_label", [addon.version, stability], 2);
|
||||
|
||||
switch (type) {
|
||||
case "adb":
|
||||
li.setAttribute("addon", type);
|
||||
name.textContent = Strings.GetStringFromName("addons_adb_label");
|
||||
break;
|
||||
case "adapters":
|
||||
li.setAttribute("addon", type);
|
||||
try {
|
||||
name.textContent = Strings.GetStringFromName("addons_adapters_label");
|
||||
} catch(e) {
|
||||
// This code (bug 1081093) will be backported to Aurora, which doesn't
|
||||
// contain this string.
|
||||
name.textContent = "Tools Adapters Add-on";
|
||||
}
|
||||
break;
|
||||
case "simulator":
|
||||
li.setAttribute("addon", "simulator-" + addon.version);
|
||||
let stability = Strings.GetStringFromName("addons_" + addon.stability);
|
||||
name.textContent = Strings.formatStringFromName("addons_simulator_label", [addon.version, stability], 2);
|
||||
break;
|
||||
}
|
||||
|
||||
li.appendChild(name);
|
||||
|
@ -111,7 +121,7 @@ function BuildItem(addon, isADB) {
|
|||
let progress = document.createElement("progress");
|
||||
li.appendChild(progress);
|
||||
|
||||
if (isADB) {
|
||||
if (type == "adb") {
|
||||
let warning = document.createElement("p");
|
||||
warning.textContent = Strings.GetStringFromName("addons_adb_warning");
|
||||
warning.className = "warning";
|
||||
|
|
|
@ -69,15 +69,22 @@ let UI = {
|
|||
this.autoSelectProject();
|
||||
});
|
||||
|
||||
// Auto install the ADB Addon Helper. Only once.
|
||||
// If the user decides to uninstall the addon, we won't install it again.
|
||||
let autoInstallADBHelper = Services.prefs.getBoolPref("devtools.webide.autoinstallADBHelper");
|
||||
if (autoInstallADBHelper && !Devices.helperAddonInstalled) {
|
||||
// Auto install the ADB Addon Helper and Tools Adapters. Only once.
|
||||
// If the user decides to uninstall any of this addon, we won't install it again.
|
||||
let autoinstallADBHelper = Services.prefs.getBoolPref("devtools.webide.autoinstallADBHelper");
|
||||
let autoinstallFxdtAdapters = Services.prefs.getBoolPref("devtools.webide.autoinstallFxdtAdapters");
|
||||
if (autoinstallADBHelper) {
|
||||
GetAvailableAddons().then(addons => {
|
||||
addons.adb.install();
|
||||
}, console.error);
|
||||
}
|
||||
if (autoinstallFxdtAdapters) {
|
||||
GetAvailableAddons().then(addons => {
|
||||
addons.adapters.install();
|
||||
}, console.error);
|
||||
}
|
||||
Services.prefs.setBoolPref("devtools.webide.autoinstallADBHelper", false);
|
||||
Services.prefs.setBoolPref("devtools.webide.autoinstallFxdtAdapters", false);
|
||||
|
||||
this.lastConnectedRuntime = Services.prefs.getCharPref("devtools.webide.lastConnectedRuntime");
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@ const {GetAddonsJSON} = require("devtools/webide/remote-resources");
|
|||
|
||||
let SIMULATOR_LINK = Services.prefs.getCharPref("devtools.webide.simulatorAddonsURL");
|
||||
let ADB_LINK = Services.prefs.getCharPref("devtools.webide.adbAddonURL");
|
||||
let ADAPTERS_LINK = Services.prefs.getCharPref("devtools.webide.adaptersAddonURL");
|
||||
let SIMULATOR_ADDON_ID = Services.prefs.getCharPref("devtools.webide.simulatorAddonID");
|
||||
let ADB_ADDON_ID = Services.prefs.getCharPref("devtools.webide.adbAddonID");
|
||||
let ADAPTERS_ADDON_ID = Services.prefs.getCharPref("devtools.webide.adaptersAddonID");
|
||||
|
||||
let platform = Services.appShell.hiddenDOMWindow.navigator.platform;
|
||||
let OS = "";
|
||||
|
@ -26,36 +28,24 @@ if (platform.indexOf("Win") != -1) {
|
|||
if (platform.indexOf("x86_64") != -1) {
|
||||
OS = "linux64";
|
||||
} else {
|
||||
OS = "linux";
|
||||
OS = "linux32";
|
||||
}
|
||||
}
|
||||
|
||||
Simulator.on("unregister", updateSimulatorAddons);
|
||||
Simulator.on("register", updateSimulatorAddons);
|
||||
Devices.on("addon-status-updated", updateAdbAddon);
|
||||
|
||||
function updateSimulatorAddons(event, version) {
|
||||
let addonsListener = {};
|
||||
addonsListener.onEnabled =
|
||||
addonsListener.onDisabled =
|
||||
addonsListener.onInstalled =
|
||||
addonsListener.onUninstalled = (updatedAddon) => {
|
||||
GetAvailableAddons().then(addons => {
|
||||
let foundAddon = null;
|
||||
for (let addon of addons.simulators) {
|
||||
if (addon.version == version) {
|
||||
foundAddon = addon;
|
||||
break;
|
||||
for (let a of [...addons.simulators, addons.adb, addons.adapters]) {
|
||||
if (a.addonID == updatedAddon.id) {
|
||||
a.updateInstallStatus();
|
||||
}
|
||||
}
|
||||
if (!foundAddon) {
|
||||
console.warn("An unknown simulator (un)registered", version);
|
||||
return;
|
||||
}
|
||||
foundAddon.updateInstallStatus();
|
||||
});
|
||||
}
|
||||
|
||||
function updateAdbAddon() {
|
||||
GetAvailableAddons().then(addons => {
|
||||
addons.adb.updateInstallStatus();
|
||||
});
|
||||
}
|
||||
AddonManager.addAddonListener(addonsListener);
|
||||
|
||||
let GetAvailableAddons_promise = null;
|
||||
let GetAvailableAddons = exports.GetAvailableAddons = function() {
|
||||
|
@ -73,6 +63,7 @@ let GetAvailableAddons = exports.GetAvailableAddons = function() {
|
|||
}
|
||||
}
|
||||
addons.adb = new ADBAddon();
|
||||
addons.adapters = new AdaptersAddon();
|
||||
deferred.resolve(addons);
|
||||
}, e => {
|
||||
GetAvailableAddons_promise = null;
|
||||
|
@ -99,13 +90,23 @@ Addon.prototype = {
|
|||
return this._status;
|
||||
},
|
||||
|
||||
install: function() {
|
||||
if (this.status != "uninstalled") {
|
||||
throw new Error("Not uninstalled");
|
||||
}
|
||||
this.status = "preparing";
|
||||
|
||||
updateInstallStatus: function() {
|
||||
AddonManager.getAddonByID(this.addonID, (addon) => {
|
||||
if (addon && !addon.userDisabled) {
|
||||
this.status = "installed";
|
||||
} else {
|
||||
this.status = "uninstalled";
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
install: function() {
|
||||
AddonManager.getAddonByID(this.addonID, (addon) => {
|
||||
if (addon && !addon.userDisabled) {
|
||||
this.status = "installed";
|
||||
return;
|
||||
}
|
||||
this.status = "preparing";
|
||||
if (addon && addon.userDisabled) {
|
||||
addon.userDisabled = false;
|
||||
} else {
|
||||
|
@ -115,7 +116,6 @@ Addon.prototype = {
|
|||
}, "application/x-xpinstall");
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
uninstall: function() {
|
||||
|
@ -167,44 +167,30 @@ function SimulatorAddon(stability, version) {
|
|||
EventEmitter.decorate(this);
|
||||
this.stability = stability;
|
||||
this.version = version;
|
||||
this.xpiLink = SIMULATOR_LINK.replace(/#OS#/g, OS)
|
||||
// This addon uses the string "linux" for "linux32"
|
||||
let fixedOS = OS == "linux32" ? "linux" : OS;
|
||||
this.xpiLink = SIMULATOR_LINK.replace(/#OS#/g, fixedOS)
|
||||
.replace(/#VERSION#/g, version)
|
||||
.replace(/#SLASHED_VERSION#/g, version.replace(/\./g, "_"));
|
||||
this.addonID = SIMULATOR_ADDON_ID.replace(/#SLASHED_VERSION#/g, version.replace(/\./g, "_"));
|
||||
this.updateInstallStatus();
|
||||
}
|
||||
|
||||
SimulatorAddon.prototype = Object.create(Addon.prototype, {
|
||||
updateInstallStatus: {
|
||||
enumerable: true,
|
||||
value: function() {
|
||||
let sim = Simulator.getByVersion(this.version);
|
||||
if (sim) {
|
||||
this.status = "installed";
|
||||
} else {
|
||||
this.status = "uninstalled";
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
SimulatorAddon.prototype = Object.create(Addon.prototype);
|
||||
|
||||
function ADBAddon() {
|
||||
EventEmitter.decorate(this);
|
||||
this.xpiLink = ADB_LINK.replace(/#OS#/g, OS);
|
||||
// This addon uses the string "linux" for "linux32"
|
||||
let fixedOS = OS == "linux32" ? "linux" : OS;
|
||||
this.xpiLink = ADB_LINK.replace(/#OS#/g, fixedOS);
|
||||
this.addonID = ADB_ADDON_ID;
|
||||
this.updateInstallStatus();
|
||||
}
|
||||
ADBAddon.prototype = Object.create(Addon.prototype);
|
||||
|
||||
ADBAddon.prototype = Object.create(Addon.prototype, {
|
||||
updateInstallStatus: {
|
||||
enumerable: true,
|
||||
value: function() {
|
||||
if (Devices.helperAddonInstalled) {
|
||||
this.status = "installed";
|
||||
} else {
|
||||
this.status = "uninstalled";
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function AdaptersAddon() {
|
||||
EventEmitter.decorate(this);
|
||||
this.xpiLink = ADAPTERS_LINK.replace(/#OS#/g, OS);
|
||||
this.addonID = ADAPTERS_ADDON_ID;
|
||||
this.updateInstallStatus();
|
||||
}
|
||||
AdaptersAddon.prototype = Object.create(Addon.prototype);
|
||||
|
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -20,6 +20,10 @@ support-files =
|
|||
addons/adbhelper-linux64.xpi
|
||||
addons/adbhelper-win32.xpi
|
||||
addons/adbhelper-mac64.xpi
|
||||
addons/fxdt-adapters-linux32.xpi
|
||||
addons/fxdt-adapters-linux64.xpi
|
||||
addons/fxdt-adapters-win32.xpi
|
||||
addons/fxdt-adapters-mac64.xpi
|
||||
head.js
|
||||
hosted_app.manifest
|
||||
templates.json
|
||||
|
|
|
@ -27,25 +27,22 @@ Services.prefs.setBoolPref("devtools.webide.enableLocalRuntime", true);
|
|||
Services.prefs.setCharPref("devtools.webide.addonsURL", TEST_BASE + "addons/simulators.json");
|
||||
Services.prefs.setCharPref("devtools.webide.simulatorAddonsURL", TEST_BASE + "addons/fxos_#SLASHED_VERSION#_simulator-#OS#.xpi");
|
||||
Services.prefs.setCharPref("devtools.webide.adbAddonURL", TEST_BASE + "addons/adbhelper-#OS#.xpi");
|
||||
Services.prefs.setCharPref("devtools.webide.adaptersAddonURL", TEST_BASE + "addons/fxdt-adapters-#OS#.xpi");
|
||||
Services.prefs.setCharPref("devtools.webide.templatesURL", TEST_BASE + "templates.json");
|
||||
|
||||
|
||||
SimpleTest.registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("devtools.webide.templatesURL");
|
||||
Services.prefs.clearUserPref("devtools.webide.enabled");
|
||||
Services.prefs.clearUserPref("devtools.webide.enableLocalRuntime");
|
||||
Services.prefs.clearUserPref("devtools.webide.addonsURL");
|
||||
Services.prefs.clearUserPref("devtools.webide.simulatorAddonsURL");
|
||||
Services.prefs.clearUserPref("devtools.webide.adbAddonURL");
|
||||
Services.prefs.clearUserPref("devtools.webide.autoInstallADBHelper", false);
|
||||
Services.prefs.clearUserPref("devtools.webide.autoinstallADBHelper");
|
||||
Services.prefs.clearUserPref("devtools.webide.autoinstallFxdtAdapters");
|
||||
});
|
||||
|
||||
function openWebIDE(autoInstallADBHelper) {
|
||||
function openWebIDE(autoInstallAddons) {
|
||||
info("opening WebIDE");
|
||||
|
||||
if (!autoInstallADBHelper) {
|
||||
Services.prefs.setBoolPref("devtools.webide.autoinstallADBHelper", false);
|
||||
}
|
||||
Services.prefs.setBoolPref("devtools.webide.autoinstallADBHelper", !!autoInstallAddons);
|
||||
Services.prefs.setBoolPref("devtools.webide.autoinstallFxdtAdapters", !!autoInstallAddons);
|
||||
|
||||
let deferred = promise.defer();
|
||||
|
||||
|
|
|
@ -109,10 +109,10 @@
|
|||
let lis;
|
||||
|
||||
lis = addonDoc.querySelectorAll("li");
|
||||
is(lis.length, 4, "4 addons listed");
|
||||
is(lis.length, 5, "5 addons listed");
|
||||
|
||||
lis = addonDoc.querySelectorAll('li[status="installed"]');
|
||||
is(lis.length, 2, "2 addons installed");
|
||||
is(lis.length, 3, "3 addons installed");
|
||||
|
||||
lis = addonDoc.querySelectorAll('li[status="uninstalled"]');
|
||||
is(lis.length, 2, "2 addons uninstalled");
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
pref("devtools.webide.showProjectEditor", true);
|
||||
pref("devtools.webide.templatesURL", "https://code.cdn.mozilla.net/templates/list.json");
|
||||
pref("devtools.webide.autoinstallADBHelper", true);
|
||||
pref("devtools.webide.autoinstallFxdtAdapters", false);
|
||||
pref("devtools.webide.restoreLastProject", true);
|
||||
pref("devtools.webide.enableLocalRuntime", true);
|
||||
pref("devtools.webide.addonsURL", "https://ftp.mozilla.org/pub/mozilla.org/labs/fxos-simulator/index.json");
|
||||
|
@ -13,6 +14,8 @@ pref("devtools.webide.simulatorAddonsURL", "https://ftp.mozilla.org/pub/mozilla.
|
|||
pref("devtools.webide.simulatorAddonID", "fxos_#SLASHED_VERSION#_simulator@mozilla.org");
|
||||
pref("devtools.webide.adbAddonURL", "https://ftp.mozilla.org/pub/mozilla.org/labs/fxos-simulator/adb-helper/#OS#/adbhelper-#OS#-latest.xpi");
|
||||
pref("devtools.webide.adbAddonID", "adbhelper@mozilla.org");
|
||||
pref("devtools.webide.adaptersAddonURL", "https://ftp.mozilla.org/pub/mozilla.org/labs/fxdt-adapters/#OS#/fxdt-adapters-#OS#-latest.xpi");
|
||||
pref("devtools.webide.adaptersAddonID", "fxdevtools-adapters@mozilla.org");
|
||||
pref("devtools.webide.monitorWebSocketURL", "ws://localhost:9000");
|
||||
pref("devtools.webide.lastConnectedRuntime", "");
|
||||
pref("devtools.webide.lastSelectedProject", "");
|
||||
|
|
|
@ -52,6 +52,7 @@ addons_simulator_label=Firefox OS %1$S Simulator (%2$S)
|
|||
addons_install_button=install
|
||||
addons_uninstall_button=uninstall
|
||||
addons_adb_label=ADB Helper Add-on
|
||||
addons_adapters_label=Tools Adapters Add-on
|
||||
addons_adb_warning=USB devices won't be detected without this add-on
|
||||
addons_status_unknown=?
|
||||
addons_status_installed=Installed
|
||||
|
|
Загрузка…
Ссылка в новой задаче