Skip to content

Commit 5b2dc4e

Browse files
author
Ian Wehrman
committed
Ensure that agents are loaded before attempting to load the main live 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.
1 parent 8379fa2 commit 5b2dc4e

File tree

2 files changed

+78
-37
lines changed

2 files changed

+78
-37
lines changed

src/LiveDevelopment/LiveDevelopment.js

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -454,24 +454,6 @@ define(function LiveDevelopment(require, exports, module) {
454454
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
455455
}
456456

457-
/** Triggered by Inspector.connect */
458-
function _onConnect(event) {
459-
$(Inspector.Inspector).on("detached", _onDetached);
460-
461-
// Load agents
462-
_setStatus(STATUS_LOADING_AGENTS);
463-
var promises = loadAgents();
464-
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
465-
466-
// Load the right document (some agents are waiting for the page's load event)
467-
var doc = _getCurrentDocument();
468-
if (doc) {
469-
Inspector.Page.navigate(doc.root.url);
470-
} else {
471-
Inspector.Page.reload();
472-
}
473-
}
474-
475457
/** Triggered by Inspector.disconnect */
476458
function _onDisconnect(event) {
477459
$(Inspector.Inspector).off("detached", _onDetached);
@@ -532,10 +514,11 @@ define(function LiveDevelopment(require, exports, module) {
532514
// helper function that actually does the launch once we are sure we have
533515
// a doc and the server for that doc is up and running.
534516
function doLaunchAfterServerReady() {
535-
var url = doc.root.url;
517+
var targetUrl = doc.root.url;
518+
var interstitialUrl = launcherUrl + "?" + encodeURIComponent(targetUrl);
536519

537520
_setStatus(STATUS_CONNECTING);
538-
Inspector.connectToURL(url).done(result.resolve).fail(function onConnectFail(err) {
521+
Inspector.connectToURL(interstitialUrl).done(result.resolve).fail(function onConnectFail(err) {
539522
if (err === "CANCEL") {
540523
result.reject(err);
541524
return;
@@ -572,10 +555,8 @@ define(function LiveDevelopment(require, exports, module) {
572555
retryCount++;
573556

574557
if (!browserStarted && exports.status !== STATUS_ERROR) {
575-
url = launcherUrl + "?" + encodeURIComponent(url);
576-
577558
NativeApp.openLiveBrowser(
578-
url,
559+
interstitialUrl,
579560
true // enable remote debugging
580561
)
581562
.done(function () {
@@ -608,7 +589,7 @@ define(function LiveDevelopment(require, exports, module) {
608589

609590
if (exports.status !== STATUS_ERROR) {
610591
window.setTimeout(function retryConnect() {
611-
Inspector.connectToURL(url).done(result.resolve).fail(onConnectFail);
592+
Inspector.connectToURL(interstitialUrl).done(result.resolve).fail(onConnectFail);
612593
}, 500);
613594
}
614595
});
@@ -675,6 +656,74 @@ define(function LiveDevelopment(require, exports, module) {
675656
agents.highlight.redraw();
676657
}
677658
}
659+
660+
/** Triggered by Inspector.connect */
661+
function _onConnect(event) {
662+
663+
/*
664+
* Create a promise that resolves when the interstitial page has
665+
* finished loading.
666+
*
667+
* @return {jQuery.Promise}
668+
*/
669+
function waitForInterstitialPageLoad() {
670+
var deferred = $.Deferred(),
671+
keepPolling = true,
672+
timer = window.setTimeout(function () {
673+
keepPolling = false;
674+
deferred.reject();
675+
}, 10000); // 10 seconds
676+
677+
/*
678+
* Asynchronously check to see if the interstitial page has
679+
* finished loading; if not, check again until timing out.
680+
*/
681+
function pollInterstitialPage() {
682+
if (keepPolling && Inspector.connected()) {
683+
Inspector.Runtime.evaluate("window.isBracketsLiveDevelopmentInterstitialPageLoaded", function (response) {
684+
var result = response.result;
685+
686+
if (result.type === "boolean" && result.value) {
687+
window.clearTimeout(timer);
688+
deferred.resolve();
689+
} else {
690+
pollInterstitialPage();
691+
}
692+
});
693+
} else {
694+
deferred.reject();
695+
}
696+
}
697+
698+
pollInterstitialPage();
699+
return deferred.promise();
700+
}
701+
702+
/*
703+
* Load agents and navigate to the target document once the
704+
* interstitial page has finished loading.
705+
*/
706+
function onInterstitialPageLoad() {
707+
// Load agents
708+
_setStatus(STATUS_LOADING_AGENTS);
709+
var promises = loadAgents();
710+
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
711+
712+
// Load the right document (some agents are waiting for the page's load event)
713+
var doc = _getCurrentDocument();
714+
if (doc) {
715+
Inspector.Page.navigate(doc.root.url);
716+
} else {
717+
close();
718+
}
719+
}
720+
721+
$(Inspector.Inspector).on("detached", _onDetached);
722+
723+
var interstitialPageLoad = waitForInterstitialPageLoad();
724+
interstitialPageLoad.fail(close);
725+
interstitialPageLoad.done(onInterstitialPageLoad);
726+
}
678727

679728
/** Triggered by a document change from the DocumentManager */
680729
function _onDocumentChange() {

src/LiveDevelopment/launch.html

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,10 @@
2929
<script type="application/javascript">
3030
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
3131
/*global window: true */
32-
33-
(function () {
34-
"use strict";
35-
36-
if (!window.location.search) {
37-
return;
38-
}
39-
var url = decodeURIComponent(window.location.search.slice(1));
40-
window.setTimeout(function () {
41-
window.location.href = url;
42-
}, 2500);
43-
}());
32+
33+
function handleLoad () {
34+
window.isBracketsLiveDevelopmentInterstitialPageLoaded = true;
35+
}
4436
</script>
4537
<style type="text/css">
4638
html, body {
@@ -78,7 +70,7 @@
7870
}
7971
</style>
8072
</head>
81-
<body>
73+
<body onload="handleLoad()">
8274
<div id="loading-image">
8375
<div id="spinner"></div>
8476
</div>

0 commit comments

Comments
 (0)