| 534 | } |
| 535 | |
| 536 | function getDefaultSimulatorIndex( |
| 537 | simulators: ListedSimulator[], |
| 538 | existingSimulatorId?: string, |
| 539 | existingSimulatorName?: string, |
| 540 | ): number { |
| 541 | if (existingSimulatorId != null) { |
| 542 | const byId = simulators.findIndex((simulator) => simulator.udid === existingSimulatorId); |
| 543 | if (byId >= 0) { |
| 544 | return byId; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | if (existingSimulatorName != null) { |
| 549 | const byName = simulators.findIndex((simulator) => simulator.name === existingSimulatorName); |
| 550 | if (byName >= 0) { |
| 551 | return byName; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | const booted = simulators.findIndex((simulator) => simulator.state === 'Booted'); |
| 556 | return booted >= 0 ? booted : 0; |
| 557 | } |
| 558 | |
| 559 | async function selectSimulator(opts: { |
| 560 | existingSimulatorId?: string; |