mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-28 11:28:38 +00:00
Bug 918383 - Fix app debugging when connecting to a simulator app that isn't installed yet. r=paul
This commit is contained in:
parent
d984c2e9c2
commit
f6e9c67447
@ -259,23 +259,63 @@ let UI = {
|
||||
debug: function(button, location) {
|
||||
button.disabled = true;
|
||||
let project = AppProjects.get(location);
|
||||
|
||||
let onFailedToStart = (error) => {
|
||||
// If not installed, install and open it
|
||||
if (error == "NO_SUCH_APP") {
|
||||
return this.install(project);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
let onStarted = () => {
|
||||
// Once we asked the app to launch, the app isn't necessary completely loaded.
|
||||
// launch request only ask the app to launch and immediatly returns.
|
||||
// We have to keep trying to get app tab actors required to create its target.
|
||||
let deferred = promise.defer();
|
||||
let loop = (count) => {
|
||||
// Ensure not looping for ever
|
||||
if (count >= 100) {
|
||||
deferred.reject("Unable to connect to the app");
|
||||
return;
|
||||
}
|
||||
// Also, in case the app wasn't installed yet, we also have to keep asking the
|
||||
// app to launch, as launch request made right after install may race.
|
||||
this.start(project);
|
||||
getTargetForApp(
|
||||
this.connection.client,
|
||||
this.listTabsResponse.webappsActor,
|
||||
this._getProjectManifestURL(project)).
|
||||
then(deferred.resolve,
|
||||
(err) => {
|
||||
if (err == "appNotFound")
|
||||
setTimeout(loop, 500, count + 1);
|
||||
else
|
||||
deferred.reject(err);
|
||||
});
|
||||
};
|
||||
loop(0);
|
||||
return deferred.promise;
|
||||
};
|
||||
let onTargetReady = (target) => {
|
||||
// Finally, when it's finally opened, display the toolbox
|
||||
let deferred = promise.defer();
|
||||
gDevTools.showToolbox(target,
|
||||
null,
|
||||
devtools.Toolbox.HostType.WINDOW).then(toolbox => {
|
||||
this.connection.once(Connection.Events.DISCONNECTED, () => {
|
||||
toolbox.destroy();
|
||||
});
|
||||
deferred.resolve(toolbox);
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
// First try to open the app
|
||||
this.start(project)
|
||||
.then(
|
||||
null,
|
||||
(error) => {
|
||||
// If not installed, install and open it
|
||||
if (error == "NO_SUCH_APP") {
|
||||
return this.install(project)
|
||||
.then(() => this.start(project));
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
// Finally, when it's finally opened, display the toolbox
|
||||
return this.openToolbox(project)
|
||||
})
|
||||
.then(null, onFailedToStart)
|
||||
.then(onStarted)
|
||||
.then(onTargetReady)
|
||||
.then(() => {
|
||||
// And only when the toolbox is opened, release the button
|
||||
button.disabled = false;
|
||||
@ -287,24 +327,6 @@ let UI = {
|
||||
});
|
||||
},
|
||||
|
||||
openToolbox: function(project) {
|
||||
let deferred = promise.defer();
|
||||
let manifest = this._getProjectManifestURL(project);
|
||||
getTargetForApp(this.connection.client,
|
||||
this.listTabsResponse.webappsActor,
|
||||
manifest).then((target) => {
|
||||
gDevTools.showToolbox(target,
|
||||
null,
|
||||
devtools.Toolbox.HostType.WINDOW).then(toolbox => {
|
||||
this.connection.once(Connection.Events.DISCONNECTED, () => {
|
||||
toolbox.destroy();
|
||||
});
|
||||
deferred.resolve();
|
||||
});
|
||||
}, deferred.reject);
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
reveal: function(location) {
|
||||
let project = AppProjects.get(location);
|
||||
if (project.type == "packaged") {
|
||||
|
Loading…
Reference in New Issue
Block a user