Bug 1124425 - Clean up listTabs promises. r=ochameau

This commit is contained in:
J. Ryan Stinnett 2015-01-21 14:51:00 +01:00
Родитель 5b39b1ea41
Коммит 8b313a4ba1
3 изменённых файлов: 20 добавлений и 17 удалений

Просмотреть файл

@ -677,7 +677,7 @@ let UI = {
}
// Ignore unselection of project on runtime disconnection
if (AppManager.connection.status != Connection.Status.CONNECTED) {
if (!AppManager.connected) {
return;
}
@ -729,7 +729,7 @@ let UI = {
}
// For other project types, we need to be connected to the runtime
if (AppManager.connection.status != Connection.Status.CONNECTED) {
if (!AppManager.connected) {
return;
}
@ -821,7 +821,7 @@ let UI = {
let debugCmd = document.querySelector("#cmd_toggleToolbox");
let playButton = document.querySelector('#action-button-play');
if (!AppManager.selectedProject || AppManager.connection.status != Connection.Status.CONNECTED) {
if (!AppManager.selectedProject || !AppManager.connected) {
playCmd.setAttribute("disabled", "true");
stopCmd.setAttribute("disabled", "true");
debugCmd.setAttribute("disabled", "true");
@ -874,7 +874,7 @@ let UI = {
let box = document.querySelector("#runtime-actions");
let runtimePanelButton = document.querySelector("#runtime-panel-button");
if (AppManager.connection.status == Connection.Status.CONNECTED) {
if (AppManager.connected) {
if (AppManager.deviceFront) {
detailsCmd.removeAttribute("disabled");
permissionsCmd.removeAttribute("disabled");
@ -1103,8 +1103,7 @@ let Cmds = {
return a.manifest.name > b.manifest.name;
});
let mainProcess = AppManager.isMainProcessDebuggable();
if (AppManager.connection.status == Connection.Status.CONNECTED &&
(sortedApps.length > 0 || mainProcess)) {
if (AppManager.connected && (sortedApps.length > 0 || mainProcess)) {
runtimeappsHeaderNode.removeAttribute("hidden");
} else {
runtimeappsHeaderNode.setAttribute("hidden", "true");
@ -1154,9 +1153,11 @@ let Cmds = {
// But re-list them and rebuild, in case any tabs navigated since the last
// time they were listed.
AppManager.listTabs().then(() => {
this._buildProjectPanelTabs();
});
if (AppManager.connected) {
AppManager.listTabs().then(() => {
this._buildProjectPanelTabs();
}).catch(console.error);
}
return deferred.promise;
},
@ -1164,8 +1165,7 @@ let Cmds = {
_buildProjectPanelTabs: function() {
let tabs = AppManager.tabStore.tabs;
let tabsHeaderNode = document.querySelector("#panel-header-tabs");
if (AppManager.connection.status == Connection.Status.CONNECTED &&
tabs.length > 0) {
if (AppManager.connected && tabs.length > 0) {
tabsHeaderNode.removeAttribute("hidden");
} else {
tabsHeaderNode.setAttribute("hidden", "true");

Просмотреть файл

@ -99,7 +99,7 @@ let AppManager = exports.AppManager = {
this.selectedRuntime = null;
}
if (this.connection.status != Connection.Status.CONNECTED) {
if (!this.connected) {
if (this._appsFront) {
this._appsFront.off("install-progress", this.onInstallProgress);
this._appsFront.unwatchApps();
@ -136,6 +136,10 @@ let AppManager = exports.AppManager = {
this.update("connection");
},
get connected() {
return this.connection.status == Connection.Status.CONNECTED;
},
get apps() {
if (this._appsFront) {
return this._appsFront.apps;
@ -336,8 +340,7 @@ let AppManager = exports.AppManager = {
connectToRuntime: function(runtime) {
if (this.connection.status == Connection.Status.CONNECTED &&
this.selectedRuntime === runtime) {
if (this.connected && this.selectedRuntime === runtime) {
// Already connected
return promise.resolve();
}
@ -350,7 +353,7 @@ let AppManager = exports.AppManager = {
let onConnectedOrDisconnected = () => {
this.connection.off(Connection.Events.CONNECTED, onConnectedOrDisconnected);
this.connection.off(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
if (this.connection.status == Connection.Status.CONNECTED) {
if (this.connected) {
deferred.resolve();
} else {
deferred.reject();
@ -413,7 +416,7 @@ let AppManager = exports.AppManager = {
},
disconnectRuntime: function() {
if (this.connection.status != Connection.Status.CONNECTED) {
if (!this.connected) {
return promise.resolve();
}
let deferred = promise.defer();

Просмотреть файл

@ -96,7 +96,7 @@ TabStore.prototype = {
listTabs: function() {
if (!this._connection || !this._connection.client) {
return promise.reject();
return promise.reject(new Error("Can't listTabs, not connected."));
}
let deferred = promise.defer();
this._connection.client.listTabs(response => {