1
- import * as iOSDevice from "../common/mobile/ios/device/ios-device" ;
2
1
import * as path from "path" ;
3
2
import * as log4js from "log4js" ;
4
3
import { ChildProcess } from "child_process" ;
5
4
import { DebugServiceBase } from "./debug-service-base" ;
6
5
import { IOS_LOG_PREDICATE } from "../common/constants" ;
7
- import { CONNECTION_ERROR_EVENT_NAME , AWAIT_NOTIFICATION_TIMEOUT_SECONDS } from "../constants" ;
6
+ import { CONNECTION_ERROR_EVENT_NAME } from "../constants" ;
8
7
import { getPidFromiOSSimulatorLogs } from "../common/helpers" ;
9
8
const inspectorAppName = "NativeScript Inspector.app" ;
10
9
const inspectorNpmPackageName = "tns-ios-inspector" ;
@@ -22,7 +21,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
22
21
private $logger : ILogger ,
23
22
private $errors : IErrors ,
24
23
private $packageInstallationManager : IPackageInstallationManager ,
25
- private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
24
+ private $iOSDebuggerPortService : IIOSDebuggerPortService ,
26
25
private $processService : IProcessService ,
27
26
private $socketProxyFactory : ISocketProxyFactory ,
28
27
private $projectDataService : IProjectDataService ,
@@ -42,32 +41,28 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
42
41
this . $errors . failWithoutHelp ( "Expected exactly one of the --debug-brk or --start options." ) ;
43
42
}
44
43
45
- if ( this . $devicesService . isOnlyiOSSimultorRunning ( ) || this . $devicesService . deviceCount === 0 ) {
46
- debugOptions . emulator = true ;
47
- }
48
-
49
44
await this . startDeviceLogProcess ( debugData , debugOptions ) ;
45
+ await this . $iOSDebuggerPortService . attachToDebuggerPortFoundEvent ( this . device , debugData , debugOptions ) ;
50
46
51
- if ( debugOptions . emulator ) {
52
- if ( debugOptions . start ) {
53
- return this . emulatorStart ( debugData , debugOptions ) ;
47
+ if ( ! debugOptions . start ) { // not attach
48
+ if ( this . device . isEmulator ) {
49
+ await this . startAppOnSimulator ( debugData , debugOptions ) ;
54
50
} else {
55
- return this . emulatorDebugBrk ( debugData , debugOptions ) ;
56
- }
57
- } else {
58
- if ( debugOptions . start ) {
59
- return this . deviceStart ( debugData , debugOptions ) ;
60
- } else {
61
- return this . deviceDebugBrk ( debugData , debugOptions ) ;
51
+ await this . startAppOnDevice ( debugData , debugOptions ) ;
62
52
}
63
53
}
54
+
55
+ return this . wireDebuggerClient ( debugData , debugOptions ) ;
64
56
}
65
57
66
58
public async debugStart ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < void > {
67
- await this . $devicesService . initialize ( { platform : this . platform , deviceId : debugData . deviceIdentifier } ) ;
68
- // TODO: this.device
69
- const action = async ( device : Mobile . IiOSDevice ) => device . isEmulator ? await this . emulatorDebugBrk ( debugData , debugOptions ) : await this . debugBrkCore ( debugData , debugOptions ) ;
70
- await this . $devicesService . execute ( action , this . getCanExecuteAction ( debugData . deviceIdentifier ) ) ;
59
+ if ( this . device . isEmulator ) {
60
+ await this . startAppOnSimulator ( debugData , debugOptions ) ;
61
+ } else {
62
+ await this . startAppOnDevice ( debugData , debugOptions ) ;
63
+ }
64
+
65
+ await this . wireDebuggerClient ( debugData , debugOptions ) ;
71
66
}
72
67
73
68
public async debugStop ( ) : Promise < void > {
@@ -117,7 +112,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
117
112
}
118
113
}
119
114
120
- private async emulatorDebugBrk ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
115
+ private async startAppOnSimulator ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < void > {
121
116
const args = debugOptions . debugBrk ? "--nativescript-debug-brk" : "--nativescript-debug-start" ;
122
117
const launchResult = await this . $iOSEmulatorServices . runApplicationOnEmulator ( debugData . pathToAppPackage , {
123
118
waitForDebugger : true ,
@@ -130,67 +125,23 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
130
125
timeout : debugOptions . timeout ,
131
126
sdk : debugOptions . sdk
132
127
} ) ;
133
-
134
128
const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , launchResult ) ;
135
129
this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
136
130
if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
137
131
this . _lldbProcess . stdout . pipe ( process . stdout ) ;
138
132
}
139
133
this . _lldbProcess . stderr . pipe ( process . stderr ) ;
140
134
this . _lldbProcess . stdin . write ( "process continue\n" ) ;
141
-
142
- const debugUrl = await this . wireDebuggerClient ( debugData , debugOptions ) ;
143
- return debugUrl ;
144
135
}
145
136
146
- private async emulatorStart ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
147
- const debugUrl = await this . wireDebuggerClient ( debugData , debugOptions ) ;
148
- return debugUrl ;
149
- }
150
-
151
- private async deviceDebugBrk ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
152
- await this . $devicesService . initialize ( { platform : this . platform , deviceId : debugData . deviceIdentifier } ) ;
153
- const projectData = this . $projectDataService . getProjectData ( debugData . projectDir ) ;
154
- const action = async ( device : iOSDevice . IOSDevice ) : Promise < string > => {
155
- if ( device . isEmulator ) {
156
- return await this . emulatorDebugBrk ( debugData , debugOptions ) ;
157
- }
158
-
159
- const runOptions : IRunPlatformOptions = {
160
- device : debugData . deviceIdentifier ,
161
- emulator : debugOptions . emulator ,
162
- justlaunch : debugOptions . justlaunch
163
- } ;
164
-
165
- const promisesResults = await Promise . all < any > ( [
166
- this . $platformService . startApplication ( this . platform , runOptions , { appId : debugData . applicationIdentifier , projectName : projectData . projectName } ) ,
167
- this . debugBrkCore ( debugData , debugOptions )
168
- ] ) ;
169
-
170
- return _ . last ( promisesResults ) ;
137
+ private async startAppOnDevice ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < void > {
138
+ const runOptions : IRunPlatformOptions = {
139
+ device : debugData . deviceIdentifier ,
140
+ emulator : this . device . isEmulator ,
141
+ justlaunch : debugOptions . justlaunch
171
142
} ;
172
-
173
- // TODO: this.device
174
- const deviceActionResult = await this . $devicesService . execute ( action , this . getCanExecuteAction ( debugData . deviceIdentifier ) ) ;
175
- return deviceActionResult [ 0 ] . result ;
176
- }
177
-
178
- private async debugBrkCore ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
179
- await this . $iOSSocketRequestExecutor . executeLaunchRequest ( this . device . deviceInfo . identifier , AWAIT_NOTIFICATION_TIMEOUT_SECONDS , AWAIT_NOTIFICATION_TIMEOUT_SECONDS , debugData . applicationIdentifier , debugOptions ) ;
180
- const debugUrl = await this . wireDebuggerClient ( debugData , debugOptions ) ;
181
- return debugUrl ;
182
- }
183
-
184
- private async deviceStart ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
185
- await this . $devicesService . initialize ( { platform : this . platform , deviceId : debugData . deviceIdentifier } ) ;
186
- const action = async ( device : Mobile . IiOSDevice ) => device . isEmulator ? await this . emulatorStart ( debugData , debugOptions ) : await this . deviceStartCore ( debugData , debugOptions ) ;
187
- const deviceActionResult = await this . $devicesService . execute ( action , this . getCanExecuteAction ( debugData . deviceIdentifier ) ) ;
188
- return deviceActionResult [ 0 ] . result ;
189
- }
190
-
191
- private async deviceStartCore ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
192
- const debugUrl = await this . wireDebuggerClient ( debugData , debugOptions ) ;
193
- return debugUrl ;
143
+ const projectData = this . $projectDataService . getProjectData ( debugData . projectDir ) ;
144
+ await this . $platformService . startApplication ( this . platform , runOptions , { appId : debugData . applicationIdentifier , projectName : projectData . projectName } ) ;
194
145
}
195
146
196
147
private async wireDebuggerClient ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
0 commit comments