2
2
"use strict" ;
3
3
4
4
import * as iOSDevice from "../common/mobile/ios/device/ios-device" ;
5
-
6
5
import * as net from "net" ;
7
6
import * as path from "path" ;
8
7
import * as semver from "semver" ;
9
8
import byline = require( "byline" ) ;
10
9
11
- let InspectorBackendPort = 18181 ;
10
+ const inspectorBackendPort = 18181 ;
11
+ const inspectorAppName = "NativeScript Inspector.app" ;
12
+ const inspectorZipName = "NativeScript Inspector.zip" ;
13
+ const inspectorNpmPackageName = "tns-ios-inspector" ;
14
+ const inspectorUiDir = "WebInspectorUI/" ;
15
+ const TIMEOUT_SECONDS = 90 ;
12
16
13
17
class IOSDebugService implements IDebugService {
14
- private static TIMEOUT_SECONDS = 90 ;
15
-
16
18
constructor (
17
19
private $platformService : IPlatformService ,
18
20
private $iOSEmulatorServices : Mobile . IEmulatorPlatformServices ,
@@ -91,13 +93,13 @@ class IOSDebugService implements IDebugService {
91
93
}
92
94
} ) ;
93
95
94
- this . wireDebuggerClient ( ( ) => net . connect ( InspectorBackendPort ) ) . wait ( ) ;
96
+ this . wireDebuggerClient ( ( ) => net . connect ( inspectorBackendPort ) ) . wait ( ) ;
95
97
} ) . future < void > ( ) ( ) ;
96
98
}
97
99
98
100
private emulatorStart ( ) : IFuture < void > {
99
101
return ( ( ) => {
100
- this . wireDebuggerClient ( ( ) => net . connect ( InspectorBackendPort ) ) . wait ( ) ;
102
+ this . wireDebuggerClient ( ( ) => net . connect ( inspectorBackendPort ) ) . wait ( ) ;
101
103
102
104
let attachRequestMessage = this . $iOSNotification . attachRequest ;
103
105
@@ -120,11 +122,11 @@ class IOSDebugService implements IDebugService {
120
122
121
123
private debugBrkCore ( device : Mobile . IiOSDevice ) : IFuture < void > {
122
124
return ( ( ) => {
123
- let timeout = this . $utils . getMilliSecondsTimeout ( IOSDebugService . TIMEOUT_SECONDS ) ;
125
+ let timeout = this . $utils . getMilliSecondsTimeout ( TIMEOUT_SECONDS ) ;
124
126
let readyForAttachTimeout = this . getReadyForAttachTimeout ( timeout ) ;
125
127
126
128
this . $iOSSocketRequestExecutor . executeLaunchRequest ( device , timeout , readyForAttachTimeout ) . wait ( ) ;
127
- this . wireDebuggerClient ( ( ) => device . connectToPort ( InspectorBackendPort ) ) . wait ( ) ;
129
+ this . wireDebuggerClient ( ( ) => device . connectToPort ( inspectorBackendPort ) ) . wait ( ) ;
128
130
} ) . future < void > ( ) ( ) ;
129
131
}
130
132
@@ -139,7 +141,7 @@ class IOSDebugService implements IDebugService {
139
141
return ( ( ) => {
140
142
let timeout = this . getReadyForAttachTimeout ( ) ;
141
143
this . $iOSSocketRequestExecutor . executeAttachRequest ( device , timeout ) . wait ( ) ;
142
- this . wireDebuggerClient ( ( ) => device . connectToPort ( InspectorBackendPort ) ) . wait ( ) ;
144
+ this . wireDebuggerClient ( ( ) => device . connectToPort ( inspectorBackendPort ) ) . wait ( ) ;
143
145
} ) . future < void > ( ) ( ) ;
144
146
}
145
147
@@ -164,15 +166,24 @@ class IOSDebugService implements IDebugService {
164
166
return ( ( ) => {
165
167
let frameworkVersion = this . getProjectFrameworkVersion ( ) . wait ( ) ;
166
168
let inspectorPath = this . getInspectorPath ( frameworkVersion ) . wait ( ) ;
167
- let inspectorSourceLocation = path . join ( inspectorPath , "Safari/Main.html" ) ;
169
+ let inspectorSourceLocation : string ;
168
170
let cmd : string = null ;
169
171
170
- if ( semver . lt ( frameworkVersion , "1.2.0" ) ) {
172
+ if ( semver . lt ( frameworkVersion , "1.2.0" ) ) {
171
173
cmd = `open -a Safari "${ inspectorSourceLocation } "` ;
172
174
} else {
173
- let inspectorApplicationPath = path . join ( inspectorPath , "NativeScript Inspector.app" ) ;
175
+ let inspectorApplicationDir : string ;
176
+ if ( semver . lt ( frameworkVersion , "1.6.0" ) ) {
177
+ inspectorApplicationDir = inspectorPath ;
178
+ inspectorSourceLocation = path . join ( inspectorPath , "Safari/Main.html" ) ;
179
+ } else {
180
+ inspectorApplicationDir = path . join ( inspectorPath , ".." ) ;
181
+ inspectorSourceLocation = path . join ( inspectorPath , "Main.html" ) ;
182
+ }
183
+
184
+ let inspectorApplicationPath = path . join ( inspectorApplicationDir , inspectorAppName ) ;
174
185
if ( ! this . $fs . exists ( inspectorApplicationPath ) . wait ( ) ) {
175
- this . $fs . unzip ( path . join ( inspectorPath , "NativeScript Inspector.zip" ) , inspectorPath ) . wait ( ) ;
186
+ this . $fs . unzip ( path . join ( inspectorApplicationDir , inspectorZipName ) , inspectorApplicationDir ) . wait ( ) ;
176
187
}
177
188
cmd = `open -a '${ inspectorApplicationPath } ' --args '${ inspectorSourceLocation } ' '${ this . $projectData . projectName } ' '${ fileDescriptor } '` ;
178
189
}
@@ -190,6 +201,24 @@ class IOSDebugService implements IDebugService {
190
201
}
191
202
192
203
private getInspectorPath ( frameworkVersion : string ) : IFuture < string > {
204
+ return ( ( ) => {
205
+ if ( semver . lt ( frameworkVersion , "1.6.0" ) ) {
206
+ return this . getInspectorPathFromDebuggerPackage ( frameworkVersion ) . wait ( ) ;
207
+ } else {
208
+ return this . getInspectorPathFromTnsIosPackage ( frameworkVersion ) . wait ( ) ;
209
+ }
210
+ } ) . future < string > ( ) ( ) ;
211
+ }
212
+
213
+ private getInspectorPathFromDebuggerPackage ( frameworkVersion : string ) : IFuture < string > {
214
+ return ( ( ) => {
215
+ let inspectorPackage = this . $npmInstallationManager . install ( inspectorNpmPackageName ) . wait ( ) ;
216
+ let inspectorPath = path . join ( inspectorPackage , inspectorUiDir ) ;
217
+ return inspectorPath ;
218
+ } ) . future < string > ( ) ( ) ;
219
+ }
220
+
221
+ private getInspectorPathFromTnsIosPackage ( frameworkVersion : string ) : IFuture < string > {
193
222
return ( ( ) => {
194
223
let tnsIosPackage = "" ;
195
224
if ( this . $options . frameworkPath ) {
@@ -201,13 +230,13 @@ class IOSDebugService implements IDebugService {
201
230
let platformData = this . $platformsData . getPlatformData ( this . platform ) ;
202
231
tnsIosPackage = this . $npmInstallationManager . install ( platformData . frameworkPackageName , { version : frameworkVersion } ) . wait ( ) ;
203
232
}
204
- let inspectorPath = path . join ( tnsIosPackage , "WebInspectorUI/" ) ;
233
+ let inspectorPath = path . join ( tnsIosPackage , inspectorUiDir ) ;
205
234
return inspectorPath ;
206
235
} ) . future < string > ( ) ( ) ;
207
236
}
208
237
209
238
private getReadyForAttachTimeout ( timeoutInMilliseconds ?: number ) : number {
210
- let timeout = timeoutInMilliseconds || this . $utils . getMilliSecondsTimeout ( IOSDebugService . TIMEOUT_SECONDS ) ;
239
+ let timeout = timeoutInMilliseconds || this . $utils . getMilliSecondsTimeout ( TIMEOUT_SECONDS ) ;
211
240
let readyForAttachTimeout = timeout / 10 ;
212
241
let defaultReadyForAttachTimeout = 5000 ;
213
242
return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout ;
0 commit comments