Skip to content

Commit 0d596f6

Browse files
author
Yosif Yosifov
committed
Modify startSimulator to kill the booted one if it's not with the same device id
1 parent 05ea7bf commit 0d596f6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/iphone-simulator-xcode-simctl.ts

100644100755
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
4040
});
4141
}
4242

43-
public run(applicationPath: string, applicationIdentifier: string): void {
43+
public async run(applicationPath: string, applicationIdentifier: string): void {
4444
let device = this.getDeviceToRun();
4545
let currentBootedDevice = _.find(this.getDevices(), device => this.isDeviceBooted(device));
4646
if (currentBootedDevice && (currentBootedDevice.name.toLowerCase() !== device.name.toLowerCase() || currentBootedDevice.runtimeVersion !== device.runtimeVersion)) {
47-
this.killSimulator();
47+
await this.killSimulator();
4848
}
4949

5050
this.startSimulator(device);
@@ -145,9 +145,14 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
145145
return _.find(devices, device => this.isDeviceBooted(device));
146146
}
147147

148-
public startSimulator(device?: IDevice): void {
148+
public async startSimulator(device?: IDevice): void {
149149
device = device || this.getDeviceToRun();
150150
if (!this.isDeviceBooted(device)) {
151+
let bootedDevice = this.getBootedDevice();
152+
if(bootedDevice && bootedDevice.id !== device.id) {
153+
await this.killSimulator();
154+
}
155+
151156
common.startSimulator(device.id);
152157
// startSimulaltor doesn't always finish immediately, and the subsequent
153158
// install fails since the simulator is not running.
@@ -156,7 +161,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
156161
}
157162
}
158163

159-
private killSimulator(): Promise<any> {
164+
private async killSimulator(): Promise<any> {
160165
return childProcess.spawn("pkill", ["-9", "-f", "Simulator"]);
161166
}
162-
}
167+
}

0 commit comments

Comments
 (0)