@@ -49,25 +49,37 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}};
4949 window . EmberInspector = Ember . EmberInspectorDebugger = requireModule ( 'ember-debug/main' ) [ 'default' ] ;
5050 Ember . EmberInspectorDebugger . Adapter = requireModule ( 'ember-debug/adapters/' + adapter ) [ 'default' ] ;
5151
52- onApplicationStart ( function appStarted ( app ) {
53- var isFirstBoot = ! ( '__inspector__booted' in app ) ;
54- app . __inspector__booted = true ;
55- Ember . EmberInspectorDebugger . set ( 'application' , app ) ;
56- Ember . EmberInspectorDebugger . start ( true ) ;
57- if ( isFirstBoot ) {
52+ onApplicationStart ( function appStarted ( instance ) {
53+ let app = instance . application ;
54+ if ( ! ( '__inspector__booted' in app ) ) {
55+ app . __inspector__booted = true ;
5856 // Watch for app reset/destroy
5957 app . reopen ( {
6058 reset : function ( ) {
6159 this . __inspector__booted = false ;
6260 this . _super . apply ( this , arguments ) ;
63- } ,
64- willDestroy : function ( ) {
65- Ember . EmberInspectorDebugger . destroyContainer ( ) ;
66- Ember . EmberInspectorDebugger . clear ( ) ;
67- this . _super . apply ( this , arguments ) ;
6861 }
6962 } ) ;
7063 }
64+
65+ if ( instance && ! ( '__inspector__booted' in instance ) ) {
66+ instance . __inspector__booted = true ;
67+
68+ instance . reopen ( {
69+ // Clean up on instance destruction
70+ willDestroy ( ) {
71+ if ( Ember . EmberInspectorDebugger . get ( 'owner' ) === instance ) {
72+ Ember . EmberInspectorDebugger . destroyContainer ( ) ;
73+ Ember . EmberInspectorDebugger . clear ( ) ;
74+ }
75+ return this . _super . apply ( this , arguments ) ;
76+ }
77+ } ) ;
78+ // Boot the inspector (or re-boot if already booted, for example in tests)
79+ Ember . EmberInspectorDebugger . set ( '_application' , app ) ;
80+ Ember . EmberInspectorDebugger . set ( 'owner' , instance ) ;
81+ Ember . EmberInspectorDebugger . start ( true ) ;
82+ }
7183 } ) ;
7284 }
7385 } ) ;
@@ -109,34 +121,42 @@ var EMBER_VERSIONS_SUPPORTED = {{EMBER_VERSIONS_SUPPORTED}};
109121 var app ;
110122 for ( var i = 0 , l = apps . length ; i < l ; i ++ ) {
111123 app = apps [ i ] ;
124+ // We check for the existance of an application instance because
125+ // in Ember > 3 tests don't destroy the app when they're done but the app has no booted instances.
112126 if ( app . _readinessDeferrals === 0 ) {
113- // App started
114- callback ( app ) ;
115- break ;
127+ let instance = app . __deprecatedInstance__ || ( app . _applicationInstances && app . _applicationInstances [ 0 ] ) ;
128+ if ( instance ) {
129+ // App started
130+ setupInstanceInitializer ( app , callback ) ;
131+ callback ( instance ) ;
132+ break ;
133+ }
116134 }
117135 }
118136 Ember . Application . initializer ( {
119137 name : 'ember-inspector-booted' ,
120- initialize : function ( ) {
121- // If 2 arguments are passed, we are on Ember < 2.1 (app is second arg)
122- // If 1 argument is passed, we are on Ember 2.1+ (app is only arg)
123- var app = arguments [ 1 ] || arguments [ 0 ] ;
124- if ( ! app . __inspector__setup ) {
125- app . __inspector__setup = true ;
126- app . reopen ( {
127- didBecomeReady : function ( ) {
128- // _super will get reset when we reopen the app
129- // so we store it in this variable to call it later.
130- var _super = this . _super ;
131- callback ( app ) ;
132- return _super . apply ( this , arguments ) ;
133- }
134- } ) ;
135- }
138+ initialize : function ( app ) {
139+ setupInstanceInitializer ( app , callback ) ;
136140 }
137141 } ) ;
138142 }
139143
144+ function setupInstanceInitializer ( app , callback ) {
145+ if ( ! app . __inspector__setup ) {
146+ app . __inspector__setup = true ;
147+
148+ // We include the app's guid in the initializer name because in Ember versions < 3
149+ // registering an instance initializer with the same name, even if on a different app,
150+ // triggers an error because instance initializers seem to be global instead of per app.
151+ app . instanceInitializer ( {
152+ name : 'ember-inspector-app-instance-booted-' + Ember . guidFor ( app ) ,
153+ initialize : function ( instance ) {
154+ callback ( instance ) ;
155+ }
156+ } ) ;
157+ }
158+ }
159+
140160 function getApplications ( ) {
141161 var namespaces = Ember . A ( Ember . Namespace . NAMESPACES ) ;
142162
0 commit comments