Skip to content

Commit 68fe898

Browse files
committed
fix(simulator): Boot orphan simulator
Fixes NativeScript/nativescript-cli#3324
1 parent 5153663 commit 68fe898

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface IDevice {
2828

2929
interface ISimctl {
3030
launch(deviceId: string, applicationIdentifier: string): string;
31+
boot(deviceId: string): void;
3132
terminate(deviceId: string, appIdentifier: string): string;
3233
install(deviceId: string, applicationPath: string): void;
3334
uninstall(deviceId: string, applicationIdentifier: string, opts?: any): void;

lib/iphone-simulator-xcode-simctl.ts

+15
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
230230
this.killSimulator();
231231
}
232232

233+
// In case user closes simulator window but simulator app is still alive
234+
if (!bootedDevice && this.isSimulatorAppRunning()) {
235+
const defaultDevice = _.find(this.simctl.getDevices(), device => device.name === this.defaultDeviceIdentifier);
236+
this.simctl.boot(defaultDevice.id);
237+
}
238+
233239
common.startSimulator(device.id);
234240
// startSimulaltor doesn't always finish immediately, and the subsequent
235241
// install fails since the simulator is not running.
@@ -238,6 +244,15 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
238244
}
239245
}
240246

247+
private isSimulatorAppRunning() {
248+
try {
249+
const output = childProcess.execSync("ps cax | grep -w Simulator");
250+
return output.indexOf('Simulator') !== -1;
251+
} catch (e) {
252+
return false;
253+
}
254+
}
255+
241256
private verifyDevice(device: IDevice): void {
242257
const availableDevices = this.getDevices();
243258
if (!_.find(availableDevices, { id: device.id })) {

lib/simctl.ts

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class Simctl implements ISimctl {
2828
return result;
2929
}
3030

31+
public boot(deviceId: string) {
32+
return this.simctlExec("boot", [deviceId]);
33+
}
34+
3135
public terminate(deviceId: string, appIdentifier: string): string {
3236
return this.simctlExec("terminate", [deviceId, appIdentifier]);
3337
}

0 commit comments

Comments
 (0)