Skip to content

Commit 919e80a

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

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-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

+17
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,17 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
238244
}
239245
}
240246

247+
private isSimulatorAppRunning(): boolean {
248+
const simulatorAppName = "Simulator";
249+
250+
try {
251+
const output = childProcess.execSync(`ps cax | grep -w ${simulatorAppName}`);
252+
return output.indexOf(simulatorAppName) !== -1;
253+
} catch (e) {
254+
return false;
255+
}
256+
}
257+
241258
private verifyDevice(device: IDevice): void {
242259
const availableDevices = this.getDevices();
243260
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)