@@ -454,24 +454,6 @@ define(function LiveDevelopment(require, exports, module) {
454
454
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
455
455
}
456
456
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
-
475
457
/** Triggered by Inspector.disconnect */
476
458
function _onDisconnect ( event ) {
477
459
$ ( Inspector . Inspector ) . off ( "detached" , _onDetached ) ;
@@ -532,10 +514,11 @@ define(function LiveDevelopment(require, exports, module) {
532
514
// helper function that actually does the launch once we are sure we have
533
515
// a doc and the server for that doc is up and running.
534
516
function doLaunchAfterServerReady ( ) {
535
- var url = doc . root . url ;
517
+ var targetUrl = doc . root . url ;
518
+ var interstitialUrl = launcherUrl + "?" + encodeURIComponent ( targetUrl ) ;
536
519
537
520
_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 ) {
539
522
if ( err === "CANCEL" ) {
540
523
result . reject ( err ) ;
541
524
return ;
@@ -572,10 +555,8 @@ define(function LiveDevelopment(require, exports, module) {
572
555
retryCount ++ ;
573
556
574
557
if ( ! browserStarted && exports . status !== STATUS_ERROR ) {
575
- url = launcherUrl + "?" + encodeURIComponent ( url ) ;
576
-
577
558
NativeApp . openLiveBrowser (
578
- url ,
559
+ interstitialUrl ,
579
560
true // enable remote debugging
580
561
)
581
562
. done ( function ( ) {
@@ -608,7 +589,7 @@ define(function LiveDevelopment(require, exports, module) {
608
589
609
590
if ( exports . status !== STATUS_ERROR ) {
610
591
window . setTimeout ( function retryConnect ( ) {
611
- Inspector . connectToURL ( url ) . done ( result . resolve ) . fail ( onConnectFail ) ;
592
+ Inspector . connectToURL ( interstitialUrl ) . done ( result . resolve ) . fail ( onConnectFail ) ;
612
593
} , 500 ) ;
613
594
}
614
595
} ) ;
@@ -675,6 +656,74 @@ define(function LiveDevelopment(require, exports, module) {
675
656
agents . highlight . redraw ( ) ;
676
657
}
677
658
}
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
+ }
678
727
679
728
/** Triggered by a document change from the DocumentManager */
680
729
function _onDocumentChange ( ) {
0 commit comments