@@ -11,6 +11,7 @@ const inspectorUiDir = "WebInspectorUI/";
11
11
12
12
export class IOSDebugService extends DebugServiceBase implements IPlatformDebugService {
13
13
private _lldbProcess : ChildProcess ;
14
+ private deviceIdentifier : string ;
14
15
15
16
constructor ( protected device : Mobile . IiOSDevice ,
16
17
protected $devicesService : Mobile . IDevicesService ,
@@ -26,25 +27,24 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
26
27
private $socketProxyFactory : ISocketProxyFactory ,
27
28
private $projectDataService : IProjectDataService ,
28
29
private $deviceLogProvider : Mobile . IDeviceLogProvider ) {
30
+
29
31
super ( device , $devicesService ) ;
30
32
this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
31
33
this . $socketProxyFactory . on ( CONNECTION_ERROR_EVENT_NAME , ( e : Error ) => this . emit ( CONNECTION_ERROR_EVENT_NAME , e ) ) ;
34
+ this . deviceIdentifier = this . device . deviceInfo . identifier ;
32
35
}
33
36
34
37
public get platform ( ) : string {
35
38
return "ios" ;
36
39
}
37
40
38
41
public async debug ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
39
-
40
- if ( debugOptions . debugBrk && debugOptions . start ) {
41
- this . $errors . failWithoutHelp ( "Expected exactly one of the --debug-brk or --start options." ) ;
42
- }
42
+ this . validateOptions ( debugOptions ) ;
43
43
44
44
await this . startDeviceLogProcess ( debugData , debugOptions ) ;
45
45
await this . $iOSDebuggerPortService . attachToDebuggerPortFoundEvent ( this . device , debugData , debugOptions ) ;
46
46
47
- if ( ! debugOptions . start ) { // not attach
47
+ if ( ! debugOptions . start ) {
48
48
if ( this . device . isEmulator ) {
49
49
await this . startAppOnSimulator ( debugData , debugOptions ) ;
50
50
} else {
@@ -67,12 +67,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
67
67
68
68
public async debugStop ( ) : Promise < void > {
69
69
this . $socketProxyFactory . removeAllProxies ( ) ;
70
-
71
- if ( this . _lldbProcess ) {
72
- this . _lldbProcess . stdin . write ( "process detach\n" ) ;
73
- await this . killProcess ( this . _lldbProcess ) ;
74
- this . _lldbProcess = undefined ;
75
- }
70
+ await this . stopAppDebuggerOnSimulator ( ) ;
76
71
}
77
72
78
73
protected getChromeDebugUrl ( debugOptions : IDebugOptions , port : number ) : string {
@@ -83,11 +78,17 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
83
78
return chromeDebugUrl ;
84
79
}
85
80
81
+ private validateOptions ( debugOptions : IDebugOptions ) {
82
+ if ( debugOptions . debugBrk && debugOptions . start ) {
83
+ this . $errors . failWithoutHelp ( "Expected exactly one of the --debug-brk or --start options." ) ;
84
+ }
85
+ }
86
+
86
87
private async startDeviceLogProcess ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < void > {
87
88
if ( debugOptions . justlaunch ) {
88
89
// No logs should be printed on console when `--justlaunch` option is passed.
89
90
// On the other side we need to start log process in order to get debugger port from logs.
90
- this . $deviceLogProvider . muteLogsForDevice ( debugData . deviceIdentifier ) ;
91
+ this . $deviceLogProvider . muteLogsForDevice ( this . deviceIdentifier ) ;
91
92
}
92
93
93
94
let projectName = debugData . projectName ;
@@ -97,21 +98,12 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
97
98
}
98
99
99
100
if ( projectName ) {
100
- this . $deviceLogProvider . setProjectNameForDevice ( debugData . deviceIdentifier , projectName ) ;
101
+ this . $deviceLogProvider . setProjectNameForDevice ( this . deviceIdentifier , projectName ) ;
101
102
}
102
103
103
104
await this . device . openDeviceLogStream ( { predicate : IOS_LOG_PREDICATE } ) ;
104
105
}
105
106
106
- private async killProcess ( childProcess : ChildProcess ) : Promise < void > {
107
- if ( childProcess ) {
108
- return new Promise < void > ( ( resolve , reject ) => {
109
- childProcess . on ( "close" , resolve ) ;
110
- childProcess . kill ( ) ;
111
- } ) ;
112
- }
113
- }
114
-
115
107
private async startAppOnSimulator ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < void > {
116
108
const args = debugOptions . debugBrk ? "--nativescript-debug-brk" : "--nativescript-debug-start" ;
117
109
const launchResult = await this . $iOSEmulatorServices . runApplicationOnEmulator ( debugData . pathToAppPackage , {
@@ -120,38 +112,56 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
120
112
args : args ,
121
113
appId : debugData . applicationIdentifier ,
122
114
skipInstall : true ,
123
- device : debugData . deviceIdentifier ,
115
+ device : this . deviceIdentifier ,
124
116
justlaunch : debugOptions . justlaunch ,
125
117
timeout : debugOptions . timeout ,
126
118
sdk : debugOptions . sdk
127
119
} ) ;
128
120
const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , launchResult ) ;
129
- this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
130
- if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
131
- this . _lldbProcess . stdout . pipe ( process . stdout ) ;
132
- }
133
- this . _lldbProcess . stderr . pipe ( process . stderr ) ;
134
- this . _lldbProcess . stdin . write ( "process continue\n" ) ;
121
+ this . startAppDebuggerOnSimulator ( pid ) ;
135
122
}
136
123
137
124
private async startAppOnDevice ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < void > {
138
125
const runOptions : IRunPlatformOptions = {
139
- device : debugData . deviceIdentifier ,
126
+ device : this . deviceIdentifier ,
140
127
emulator : this . device . isEmulator ,
141
128
justlaunch : debugOptions . justlaunch
142
129
} ;
143
130
const projectData = this . $projectDataService . getProjectData ( debugData . projectDir ) ;
144
131
await this . $platformService . startApplication ( this . platform , runOptions , { appId : debugData . applicationIdentifier , projectName : projectData . projectName } ) ;
145
132
}
146
133
134
+ private startAppDebuggerOnSimulator ( pid : string ) {
135
+ this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
136
+ if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
137
+ this . _lldbProcess . stdout . pipe ( process . stdout ) ;
138
+ }
139
+ this . _lldbProcess . stderr . pipe ( process . stderr ) ;
140
+ this . _lldbProcess . stdin . write ( "process continue\n" ) ;
141
+ }
142
+
143
+ private async stopAppDebuggerOnSimulator ( ) {
144
+ if ( this . _lldbProcess ) {
145
+ this . _lldbProcess . stdin . write ( "process detach\n" ) ;
146
+ await this . killProcess ( this . _lldbProcess ) ;
147
+ this . _lldbProcess = undefined ;
148
+ }
149
+ }
150
+
151
+ private async killProcess ( childProcess : ChildProcess ) : Promise < void > {
152
+ if ( childProcess ) {
153
+ return new Promise < void > ( ( resolve , reject ) => {
154
+ childProcess . on ( "close" , resolve ) ;
155
+ childProcess . kill ( ) ;
156
+ } ) ;
157
+ }
158
+ }
159
+
147
160
private async wireDebuggerClient ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
148
- // the VSCode Ext starts `tns debug ios --no-client` to start/attach to debug sessions
149
- // check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
150
- const deviceIdentifier = this . device ? this . device . deviceInfo . identifier : debugData . deviceIdentifier ;
151
161
if ( ( debugOptions . inspector || ! debugOptions . client ) && this . $hostInfo . isDarwin ) {
152
- const existingTcpProxy = this . $socketProxyFactory . getTCPSocketProxy ( deviceIdentifier ) ;
162
+ const existingTcpProxy = this . $socketProxyFactory . getTCPSocketProxy ( this . deviceIdentifier ) ;
153
163
const getDeviceSocket = async ( ) => await this . device . getDebugSocket ( debugData . applicationIdentifier , debugData . projectDir ) ;
154
- const tcpSocketProxy = existingTcpProxy || await this . $socketProxyFactory . addTCPSocketProxy ( getDeviceSocket , deviceIdentifier ) ;
164
+ const tcpSocketProxy = existingTcpProxy || await this . $socketProxyFactory . addTCPSocketProxy ( getDeviceSocket , this . deviceIdentifier ) ;
155
165
if ( ! existingTcpProxy ) {
156
166
await this . openAppInspector ( tcpSocketProxy . address ( ) , debugData , debugOptions ) ;
157
167
}
@@ -162,9 +172,9 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
162
172
this . $logger . info ( "'--chrome' is the default behavior. Use --inspector to debug iOS applications using the Safari Web Inspector." ) ;
163
173
}
164
174
165
- const existingWebProxy = this . $socketProxyFactory . getWebSocketProxy ( deviceIdentifier ) ;
175
+ const existingWebProxy = this . $socketProxyFactory . getWebSocketProxy ( this . deviceIdentifier ) ;
166
176
const getDeviceSocket = async ( ) => await this . device . getDebugSocket ( debugData . applicationIdentifier , debugData . projectDir ) ;
167
- const webSocketProxy = existingWebProxy || await this . $socketProxyFactory . addWebSocketProxy ( getDeviceSocket , deviceIdentifier ) ;
177
+ const webSocketProxy = existingWebProxy || await this . $socketProxyFactory . addWebSocketProxy ( getDeviceSocket , this . deviceIdentifier ) ;
168
178
169
179
return this . getChromeDebugUrl ( debugOptions , webSocketProxy . options . port ) ;
170
180
}
0 commit comments