Skip to content

Commit

Permalink
Ensure that agents are loaded before attempting to load the main live…
Browse files Browse the repository at this point in the history
… development URL. This accomplished by always loading the interstitial page first and then polling to find out whether the interstitial page has finished loading. The agents are loaded next; and then, finally, once agent loading is complete, the main URL is loaded. Should fix adobe#2858.
  • Loading branch information
Ian Wehrman committed Mar 14, 2013
1 parent 8379fa2 commit 5b2dc4e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 37 deletions.
97 changes: 73 additions & 24 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,6 @@ define(function LiveDevelopment(require, exports, module) {
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
}

/** Triggered by Inspector.connect */
function _onConnect(event) {
$(Inspector.Inspector).on("detached", _onDetached);

// Load agents
_setStatus(STATUS_LOADING_AGENTS);
var promises = loadAgents();
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);

// Load the right document (some agents are waiting for the page's load event)
var doc = _getCurrentDocument();
if (doc) {
Inspector.Page.navigate(doc.root.url);
} else {
Inspector.Page.reload();
}
}

/** Triggered by Inspector.disconnect */
function _onDisconnect(event) {
$(Inspector.Inspector).off("detached", _onDetached);
Expand Down Expand Up @@ -532,10 +514,11 @@ define(function LiveDevelopment(require, exports, module) {
// helper function that actually does the launch once we are sure we have
// a doc and the server for that doc is up and running.
function doLaunchAfterServerReady() {
var url = doc.root.url;
var targetUrl = doc.root.url;
var interstitialUrl = launcherUrl + "?" + encodeURIComponent(targetUrl);

_setStatus(STATUS_CONNECTING);
Inspector.connectToURL(url).done(result.resolve).fail(function onConnectFail(err) {
Inspector.connectToURL(interstitialUrl).done(result.resolve).fail(function onConnectFail(err) {
if (err === "CANCEL") {
result.reject(err);
return;
Expand Down Expand Up @@ -572,10 +555,8 @@ define(function LiveDevelopment(require, exports, module) {
retryCount++;

if (!browserStarted && exports.status !== STATUS_ERROR) {
url = launcherUrl + "?" + encodeURIComponent(url);

NativeApp.openLiveBrowser(
url,
interstitialUrl,
true // enable remote debugging
)
.done(function () {
Expand Down Expand Up @@ -608,7 +589,7 @@ define(function LiveDevelopment(require, exports, module) {

if (exports.status !== STATUS_ERROR) {
window.setTimeout(function retryConnect() {
Inspector.connectToURL(url).done(result.resolve).fail(onConnectFail);
Inspector.connectToURL(interstitialUrl).done(result.resolve).fail(onConnectFail);
}, 500);
}
});
Expand Down Expand Up @@ -675,6 +656,74 @@ define(function LiveDevelopment(require, exports, module) {
agents.highlight.redraw();
}
}

/** Triggered by Inspector.connect */
function _onConnect(event) {

/*
* Create a promise that resolves when the interstitial page has
* finished loading.
*
* @return {jQuery.Promise}
*/
function waitForInterstitialPageLoad() {
var deferred = $.Deferred(),
keepPolling = true,
timer = window.setTimeout(function () {
keepPolling = false;
deferred.reject();
}, 10000); // 10 seconds

/*
* Asynchronously check to see if the interstitial page has
* finished loading; if not, check again until timing out.
*/
function pollInterstitialPage() {
if (keepPolling && Inspector.connected()) {
Inspector.Runtime.evaluate("window.isBracketsLiveDevelopmentInterstitialPageLoaded", function (response) {
var result = response.result;

if (result.type === "boolean" && result.value) {
window.clearTimeout(timer);
deferred.resolve();
} else {
pollInterstitialPage();
}
});
} else {
deferred.reject();
}
}

pollInterstitialPage();
return deferred.promise();
}

/*
* Load agents and navigate to the target document once the
* interstitial page has finished loading.
*/
function onInterstitialPageLoad() {
// Load agents
_setStatus(STATUS_LOADING_AGENTS);
var promises = loadAgents();
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);

// Load the right document (some agents are waiting for the page's load event)
var doc = _getCurrentDocument();
if (doc) {
Inspector.Page.navigate(doc.root.url);
} else {
close();
}
}

$(Inspector.Inspector).on("detached", _onDetached);

var interstitialPageLoad = waitForInterstitialPageLoad();
interstitialPageLoad.fail(close);
interstitialPageLoad.done(onInterstitialPageLoad);
}

/** Triggered by a document change from the DocumentManager */
function _onDocumentChange() {
Expand Down
18 changes: 5 additions & 13 deletions src/LiveDevelopment/launch.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@
<script type="application/javascript">
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global window: true */

(function () {
"use strict";

if (!window.location.search) {
return;
}
var url = decodeURIComponent(window.location.search.slice(1));
window.setTimeout(function () {
window.location.href = url;
}, 2500);
}());

function handleLoad () {
window.isBracketsLiveDevelopmentInterstitialPageLoaded = true;
}
</script>
<style type="text/css">
html, body {
Expand Down Expand Up @@ -78,7 +70,7 @@
}
</style>
</head>
<body>
<body onload="handleLoad()">
<div id="loading-image">
<div id="spinner"></div>
</div>
Expand Down

0 comments on commit 5b2dc4e

Please sign in to comment.