@@ -30,12 +30,12 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
30
30
this . simctl = new Simctl ( ) ;
31
31
}
32
32
33
- public getDevices ( ) : IDevice [ ] {
33
+ public getDevices ( ) : Promise < IDevice [ ] > {
34
34
return this . simctl . getDevices ( ) ;
35
35
}
36
36
37
- public getSdks ( ) : ISdk [ ] {
38
- let devices = this . simctl . getDevices ( ) ;
37
+ public async getSdks ( ) : Promise < ISdk [ ] > {
38
+ let devices = await this . simctl . getDevices ( ) ;
39
39
return _ . map ( devices , device => {
40
40
return {
41
41
displayName : `iOS ${ device . runtimeVersion } ` ,
@@ -44,8 +44,8 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
44
44
} ) ;
45
45
}
46
46
47
- public run ( applicationPath : string , applicationIdentifier : string , options : IOptions ) : string {
48
- const device = this . getDeviceToRun ( options ) ;
47
+ public async run ( applicationPath : string , applicationIdentifier : string , options : IOptions ) : Promise < string > {
48
+ const device = await this . getDeviceToRun ( options ) ;
49
49
50
50
this . startSimulator ( options , device ) ;
51
51
if ( ! options . skipInstall ) {
@@ -55,40 +55,41 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
55
55
return this . simctl . launch ( device . id , applicationIdentifier , options ) ;
56
56
}
57
57
58
- public sendNotification ( notification : string , deviceId : string ) : void {
58
+ public sendNotification ( notification : string , deviceId : string ) : Promise < void > {
59
59
let device = this . getDeviceFromIdentifier ( deviceId ) ;
60
+
60
61
if ( ! device ) {
61
62
errors . fail ( "Could not find device." ) ;
62
63
}
63
64
64
- this . simctl . notifyPost ( deviceId , notification ) ;
65
+ return this . simctl . notifyPost ( deviceId , notification ) ;
65
66
}
66
67
67
- public getApplicationPath ( deviceId : string , applicationIdentifier : string ) : string {
68
+ public getApplicationPath ( deviceId : string , applicationIdentifier : string ) : Promise < string > {
68
69
return this . simctl . getAppContainer ( deviceId , applicationIdentifier ) ;
69
70
}
70
71
71
72
public getInstalledApplications ( deviceId : string ) : IApplication [ ] {
72
73
return common . getInstalledApplications ( deviceId ) ;
73
74
}
74
75
75
- public installApplication ( deviceId : string , applicationPath : string ) : void {
76
+ public installApplication ( deviceId : string , applicationPath : string ) : Promise < void > {
76
77
return this . simctl . install ( deviceId , applicationPath ) ;
77
78
}
78
79
79
- public uninstallApplication ( deviceId : string , appIdentifier : string ) : void {
80
+ public uninstallApplication ( deviceId : string , appIdentifier : string ) : Promise < void > {
80
81
return this . simctl . uninstall ( deviceId , appIdentifier , { skipError : true } ) ;
81
82
}
82
83
83
- public startApplication ( deviceId : string , appIdentifier : string , options : IOptions ) : string {
84
+ public async startApplication ( deviceId : string , appIdentifier : string , options : IOptions ) : Promise < string > {
84
85
// simctl launch command does not launch the process immediately and we have to wait a little bit,
85
86
// just to ensure all related processes and services are alive.
86
- const launchResult = this . simctl . launch ( deviceId , appIdentifier , options ) ;
87
+ const launchResult = await this . simctl . launch ( deviceId , appIdentifier , options ) ;
87
88
utils . sleep ( 0.5 ) ;
88
89
return launchResult ;
89
90
}
90
91
91
- public stopApplication ( deviceId : string , appIdentifier : string , bundleExecutable : string ) : string {
92
+ public async stopApplication ( deviceId : string , appIdentifier : string , bundleExecutable : string ) : Promise < string > {
92
93
try {
93
94
let xcodeMajorVersion : number = null ;
94
95
try {
@@ -103,7 +104,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
103
104
// Xcode 7.x does not have support for `xcrun simctl terminate` command
104
105
resultOfTermination = childProcess . execSync ( `killall ${ bundleExecutable } ` , { skipError : true } ) ;
105
106
} else {
106
- resultOfTermination = this . simctl . terminate ( deviceId , appIdentifier ) ;
107
+ resultOfTermination = await this . simctl . terminate ( deviceId , appIdentifier ) ;
107
108
}
108
109
109
110
// killall command does not terminate the processes immediately and we have to wait a little bit,
@@ -116,9 +117,9 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
116
117
}
117
118
}
118
119
119
- public getDeviceLogProcess ( deviceId : string , predicate ?: string ) : child_process . ChildProcess {
120
+ public async getDeviceLogProcess ( deviceId : string , predicate ?: string ) : Promise < child_process . ChildProcess > {
120
121
if ( ! this . isDeviceLogOperationStarted ) {
121
- const device = this . getDeviceFromIdentifier ( deviceId ) ;
122
+ const device = await this . getDeviceFromIdentifier ( deviceId ) ;
122
123
const deviceVersion = device ? device . runtimeVersion : "" ;
123
124
const majorVersion = deviceVersion . split ( "." ) [ 0 ] ;
124
125
@@ -135,8 +136,8 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
135
136
return this . deviceLogChildProcess ;
136
137
}
137
138
138
- private getDeviceToRun ( options : IOptions , device ?: any ) : IDevice {
139
- let devices = _ . sortBy ( this . simctl . getDevices ( ) , ( device ) => device . runtimeVersion ) ,
139
+ private async getDeviceToRun ( options : IOptions , device ?: any ) : Promise < IDevice > {
140
+ let devices = _ . sortBy ( await this . simctl . getDevices ( ) , ( device ) => device . runtimeVersion ) ,
140
141
sdkVersion = options . sdkVersion || options . sdk ,
141
142
deviceIdOrName = options . device ;
142
143
@@ -181,30 +182,30 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
181
182
return device . state === 'Booted' ;
182
183
}
183
184
184
- private getBootedDevice ( ) : IDevice {
185
- let devices = this . simctl . getDevices ( ) ;
185
+ private async getBootedDevice ( ) : Promise < IDevice > {
186
+ let devices = await this . simctl . getDevices ( ) ;
186
187
return _ . find ( devices , device => this . isDeviceBooted ( device ) ) ;
187
188
}
188
189
189
- private getBootedDevices ( ) : IDevice [ ] {
190
- const devices = this . simctl . getDevices ( ) ;
190
+ private async getBootedDevices ( ) : Promise < IDevice [ ] > {
191
+ const devices = await this . simctl . getDevices ( ) ;
191
192
return _ . filter ( devices , device => this . isDeviceBooted ( device ) ) ;
192
193
}
193
194
194
- public startSimulator ( options : IOptions , device ?: IDevice ) : void {
195
+ public async startSimulator ( options : IOptions , device ?: IDevice ) : Promise < void > {
195
196
if ( ! device && options . device ) {
196
197
this . verifyDevice ( options . device ) ;
197
198
}
198
199
199
- device = device || this . getDeviceToRun ( options ) ;
200
+ device = device || await this . getDeviceToRun ( options ) ;
200
201
201
202
// In case the id is undefined, skip verification - we'll start default simulator.
202
203
if ( device && device . id ) {
203
204
this . verifyDevice ( device ) ;
204
205
}
205
206
206
207
if ( ! device || ! device . runtimeVersion || ! device . fullId ) {
207
- device = this . getDeviceToRun ( options , device ) ;
208
+ device = await this . getDeviceToRun ( options , device ) ;
208
209
}
209
210
210
211
if ( ! this . isDeviceBooted ( device ) ) {
@@ -214,7 +215,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
214
215
if ( isSimulatorAppRunning ) {
215
216
// In case user closes simulator window but simulator app is still alive
216
217
if ( ! haveBootedDevices ) {
217
- device = this . getDeviceToRun ( options ) ;
218
+ device = await this . getDeviceToRun ( options ) ;
218
219
}
219
220
this . simctl . boot ( device . id ) ;
220
221
} else {
@@ -229,8 +230,8 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
229
230
}
230
231
}
231
232
232
- private haveBootedDevices ( ) : boolean {
233
- const bootedDevices = this . getBootedDevices ( ) ;
233
+ private async haveBootedDevices ( ) : Promise < boolean > {
234
+ const bootedDevices = await this . getBootedDevices ( ) ;
234
235
return bootedDevices && bootedDevices . length > 0 ;
235
236
}
236
237
@@ -245,16 +246,16 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
245
246
}
246
247
}
247
248
248
- private verifyDevice ( device : IDevice | string ) : void {
249
- const availableDevices = this . getDevices ( ) ;
249
+ private async verifyDevice ( device : IDevice | string ) : Promise < void > {
250
+ const availableDevices = await this . getDevices ( ) ;
250
251
const deviceId = ( < IDevice > device ) . id || device ;
251
252
if ( ! _ . find ( availableDevices , { id : deviceId } ) && ! _ . find ( availableDevices , { name : deviceId } ) ) {
252
253
errors . fail ( `No simulator image available for device identifier '${ deviceId } '.` ) ;
253
254
}
254
255
}
255
256
256
- private getDeviceFromIdentifier ( deviceId : string ) {
257
- const availableDevices = this . getDevices ( ) ;
257
+ private async getDeviceFromIdentifier ( deviceId : string ) {
258
+ const availableDevices = await this . getDevices ( ) ;
258
259
259
260
return _ . find ( availableDevices , { id : deviceId } ) ;
260
261
}
0 commit comments