@@ -8,9 +8,14 @@ const inspectorBackendPort = 18181;
8
8
const inspectorAppName = "NativeScript Inspector.app" ;
9
9
const inspectorNpmPackageName = "tns-ios-inspector" ;
10
10
const inspectorUiDir = "WebInspectorUI/" ;
11
- const TIMEOUT_SECONDS = 90 ;
11
+ const TIMEOUT_SECONDS = 9 ;
12
12
13
13
class IOSDebugService implements IDebugService {
14
+ private _lldbProcess : ChildProcess ;
15
+ private _sockets : net . Socket [ ] = [ ] ;
16
+ private _childProcess : ChildProcess ;
17
+ private _socketProxy : net . Server ;
18
+
14
19
constructor (
15
20
private $config : IConfiguration ,
16
21
private $platformService : IPlatformService ,
@@ -35,10 +40,6 @@ class IOSDebugService implements IDebugService {
35
40
this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
36
41
}
37
42
38
- private _lldbProcess : ChildProcess ;
39
- private _sockets : net . Socket [ ] = [ ] ;
40
- private _childProcess : ChildProcess ;
41
-
42
43
public get platform ( ) : string {
43
44
return "ios" ;
44
45
}
@@ -80,16 +81,20 @@ class IOSDebugService implements IDebugService {
80
81
81
82
public debugStop ( ) : IFuture < void > {
82
83
return ( ( ) => {
83
- this . $socketProxyFactory . stopServer ( ) ;
84
- for ( let socket of this . _sockets ) {
85
- socket . destroy ( ) ;
84
+ if ( this . _socketProxy ) {
85
+ this . _socketProxy . close ( ) ;
86
+ this . _socketProxy = null ;
86
87
}
88
+
89
+ _ . forEach ( this . _sockets , socket => socket . destroy ( ) ) ;
87
90
this . _sockets = [ ] ;
91
+
88
92
if ( this . _lldbProcess ) {
89
93
this . _lldbProcess . stdin . write ( "process detach\n" ) ;
90
94
this . _lldbProcess . kill ( ) ;
91
95
this . _lldbProcess = undefined ;
92
96
}
97
+
93
98
if ( this . _childProcess ) {
94
99
this . _childProcess . kill ( ) ;
95
100
this . _childProcess = undefined ;
@@ -163,9 +168,7 @@ class IOSDebugService implements IDebugService {
163
168
private debugBrkCore ( device : Mobile . IiOSDevice , shouldBreak ?: boolean ) : IFuture < void > {
164
169
return ( ( ) => {
165
170
let timeout = this . $utils . getMilliSecondsTimeout ( TIMEOUT_SECONDS ) ;
166
- let readyForAttachTimeout = this . getReadyForAttachTimeout ( timeout ) ;
167
-
168
- this . $iOSSocketRequestExecutor . executeLaunchRequest ( device , timeout , readyForAttachTimeout , shouldBreak ) . wait ( ) ;
171
+ this . $iOSSocketRequestExecutor . executeLaunchRequest ( device , timeout , timeout , shouldBreak ) . wait ( ) ;
169
172
this . wireDebuggerClient ( device ) . wait ( ) ;
170
173
} ) . future < void > ( ) ( ) ;
171
174
}
@@ -179,56 +182,46 @@ class IOSDebugService implements IDebugService {
179
182
180
183
private deviceStartCore ( device : Mobile . IiOSDevice ) : IFuture < void > {
181
184
return ( ( ) => {
182
- let timeout = this . getReadyForAttachTimeout ( ) ;
185
+ let timeout = this . $utils . getMilliSecondsTimeout ( TIMEOUT_SECONDS ) ;
183
186
this . $iOSSocketRequestExecutor . executeAttachRequest ( device , timeout ) . wait ( ) ;
184
187
this . wireDebuggerClient ( device ) . wait ( ) ;
185
188
} ) . future < void > ( ) ( ) ;
186
189
}
187
190
188
191
private wireDebuggerClient ( device ?: Mobile . IiOSDevice ) : IFuture < void > {
189
192
return ( ( ) => {
190
- let socketProxy = this . $socketProxyFactory . createSocketProxy ( ( ) => {
193
+ this . _socketProxy = this . $socketProxyFactory . createSocketProxy ( ( ) => {
191
194
let socket = device ? device . connectToPort ( inspectorBackendPort ) : net . connect ( inspectorBackendPort ) ;
192
195
this . _sockets . push ( socket ) ;
193
196
return socket ;
194
197
} ) . wait ( ) ;
195
- this . executeOpenDebuggerClient ( socketProxy ) . wait ( ) ;
198
+
199
+ this . openDebuggerClient ( < any > this . _socketProxy . address ( ) ) . wait ( ) ;
196
200
} ) . future < void > ( ) ( ) ;
197
201
}
198
202
199
- public executeOpenDebuggerClient ( fileDescriptor : string ) : IFuture < void > {
203
+ private openDebuggerClient ( fileDescriptor : string ) : IFuture < void > {
200
204
if ( this . $options . client ) {
201
- return this . openDebuggingClient ( fileDescriptor ) ;
205
+ return ( ( ) => {
206
+ let inspectorPath = this . $npmInstallationManager . install ( inspectorNpmPackageName ) . wait ( ) ;
207
+ let inspectorSourceLocation = path . join ( inspectorPath , inspectorUiDir , "Main.html" ) ;
208
+ let inspectorApplicationPath = path . join ( inspectorPath , inspectorAppName ) ;
209
+
210
+ // TODO : Sadly $npmInstallationManager.install does not install the package, it only inserts it in the cache through the npm cache add command
211
+ // Since npm cache add command does not execute scripts our posinstall script that extract the Inspector Application does not execute as well
212
+ // So until this behavior is changed this ugly workaround should not be deleted
213
+ if ( ! this . $fs . exists ( inspectorApplicationPath ) . wait ( ) ) {
214
+ this . $npm . executeNpmCommand ( "npm run-script postinstall" , inspectorPath ) . wait ( ) ;
215
+ }
216
+
217
+ let cmd = `open -a '${ inspectorApplicationPath } ' --args '${ inspectorSourceLocation } ' '${ this . $projectData . projectName } ' '${ fileDescriptor } '` ;
218
+ this . $childProcess . exec ( cmd ) . wait ( ) ;
219
+ } ) . future < void > ( ) ( ) ;
202
220
} else {
203
221
return ( ( ) => {
204
222
this . $logger . info ( "Suppressing debugging client." ) ;
205
223
} ) . future < void > ( ) ( ) ;
206
224
}
207
225
}
208
-
209
- private openDebuggingClient ( fileDescriptor : string ) : IFuture < void > {
210
- return ( ( ) => {
211
- let inspectorPath = this . $npmInstallationManager . install ( inspectorNpmPackageName ) . wait ( ) ;
212
- let inspectorSourceLocation = path . join ( inspectorPath , inspectorUiDir , "Main.html" ) ;
213
- let inspectorApplicationPath = path . join ( inspectorPath , inspectorAppName ) ;
214
-
215
- // TODO : Sadly $npmInstallationManager.install does not install the package, it only inserts it in the cache through the npm cache add command
216
- // Since npm cache add command does not execute scripts our posinstall script that extract the Inspector Application does not execute as well
217
- // So until this behavior is changed this ugly workaround should not be deleted
218
- if ( ! this . $fs . exists ( inspectorApplicationPath ) . wait ( ) ) {
219
- this . $npm . executeNpmCommand ( "npm run-script postinstall" , inspectorPath ) . wait ( ) ;
220
- }
221
-
222
- let cmd = `open -a '${ inspectorApplicationPath } ' --args '${ inspectorSourceLocation } ' '${ this . $projectData . projectName } ' '${ fileDescriptor } '` ;
223
- this . $childProcess . exec ( cmd ) . wait ( ) ;
224
- } ) . future < void > ( ) ( ) ;
225
- }
226
-
227
- private getReadyForAttachTimeout ( timeoutInMilliseconds ?: number ) : number {
228
- let timeout = timeoutInMilliseconds || this . $utils . getMilliSecondsTimeout ( TIMEOUT_SECONDS ) ;
229
- let readyForAttachTimeout = timeout / 10 ;
230
- let defaultReadyForAttachTimeout = 5000 ;
231
- return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout ;
232
- }
233
226
}
234
227
$injector . register ( "iOSDebugService" , IOSDebugService ) ;
0 commit comments