@@ -8,9 +8,14 @@ const inspectorBackendPort = 18181;
88const inspectorAppName = "NativeScript Inspector.app" ;
99const inspectorNpmPackageName = "tns-ios-inspector" ;
1010const inspectorUiDir = "WebInspectorUI/" ;
11- const TIMEOUT_SECONDS = 90 ;
11+ const TIMEOUT_SECONDS = 9 ;
1212
1313class IOSDebugService implements IDebugService {
14+ private _lldbProcess : ChildProcess ;
15+ private _sockets : net . Socket [ ] = [ ] ;
16+ private _childProcess : ChildProcess ;
17+ private _socketProxy : net . Server ;
18+
1419 constructor (
1520 private $config : IConfiguration ,
1621 private $platformService : IPlatformService ,
@@ -35,10 +40,6 @@ class IOSDebugService implements IDebugService {
3540 this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
3641 }
3742
38- private _lldbProcess : ChildProcess ;
39- private _sockets : net . Socket [ ] = [ ] ;
40- private _childProcess : ChildProcess ;
41-
4243 public get platform ( ) : string {
4344 return "ios" ;
4445 }
@@ -80,16 +81,20 @@ class IOSDebugService implements IDebugService {
8081
8182 public debugStop ( ) : IFuture < void > {
8283 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 ;
8687 }
88+
89+ _ . forEach ( this . _sockets , socket => socket . destroy ( ) ) ;
8790 this . _sockets = [ ] ;
91+
8892 if ( this . _lldbProcess ) {
8993 this . _lldbProcess . stdin . write ( "process detach\n" ) ;
9094 this . _lldbProcess . kill ( ) ;
9195 this . _lldbProcess = undefined ;
9296 }
97+
9398 if ( this . _childProcess ) {
9499 this . _childProcess . kill ( ) ;
95100 this . _childProcess = undefined ;
@@ -163,9 +168,7 @@ class IOSDebugService implements IDebugService {
163168 private debugBrkCore ( device : Mobile . IiOSDevice , shouldBreak ?: boolean ) : IFuture < void > {
164169 return ( ( ) => {
165170 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 ( ) ;
169172 this . wireDebuggerClient ( device ) . wait ( ) ;
170173 } ) . future < void > ( ) ( ) ;
171174 }
@@ -179,56 +182,46 @@ class IOSDebugService implements IDebugService {
179182
180183 private deviceStartCore ( device : Mobile . IiOSDevice ) : IFuture < void > {
181184 return ( ( ) => {
182- let timeout = this . getReadyForAttachTimeout ( ) ;
185+ let timeout = this . $utils . getMilliSecondsTimeout ( TIMEOUT_SECONDS ) ;
183186 this . $iOSSocketRequestExecutor . executeAttachRequest ( device , timeout ) . wait ( ) ;
184187 this . wireDebuggerClient ( device ) . wait ( ) ;
185188 } ) . future < void > ( ) ( ) ;
186189 }
187190
188191 private wireDebuggerClient ( device ?: Mobile . IiOSDevice ) : IFuture < void > {
189192 return ( ( ) => {
190- let socketProxy = this . $socketProxyFactory . createSocketProxy ( ( ) => {
193+ this . _socketProxy = this . $socketProxyFactory . createSocketProxy ( ( ) => {
191194 let socket = device ? device . connectToPort ( inspectorBackendPort ) : net . connect ( inspectorBackendPort ) ;
192195 this . _sockets . push ( socket ) ;
193196 return socket ;
194197 } ) . wait ( ) ;
195- this . executeOpenDebuggerClient ( socketProxy ) . wait ( ) ;
198+
199+ this . openDebuggerClient ( < any > this . _socketProxy . address ( ) ) . wait ( ) ;
196200 } ) . future < void > ( ) ( ) ;
197201 }
198202
199- public executeOpenDebuggerClient ( fileDescriptor : string ) : IFuture < void > {
203+ private openDebuggerClient ( fileDescriptor : string ) : IFuture < void > {
200204 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 > ( ) ( ) ;
202220 } else {
203221 return ( ( ) => {
204222 this . $logger . info ( "Suppressing debugging client." ) ;
205223 } ) . future < void > ( ) ( ) ;
206224 }
207225 }
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- }
233226}
234227$injector . register ( "iOSDebugService" , IOSDebugService ) ;
0 commit comments