(deviceOrUdid: DeviceInfo | string)
| 246 | } |
| 247 | |
| 248 | export async function getSimulatorState(deviceOrUdid: DeviceInfo | string): Promise<string | null> { |
| 249 | const udid = typeof deviceOrUdid === 'string' ? deviceOrUdid : deviceOrUdid.id; |
| 250 | const simctlArgs = |
| 251 | typeof deviceOrUdid === 'string' |
| 252 | ? buildSimctlArgs(['list', 'devices', '-j']) |
| 253 | : buildSimctlArgsForDevice(deviceOrUdid, ['list', 'devices', '-j']); |
| 254 | const result = await runXcrun(simctlArgs, { |
| 255 | allowFailure: true, |
| 256 | timeoutMs: IOS_SIMCTL_LIST_TIMEOUT_MS, |
| 257 | }); |
| 258 | if (result.exitCode !== 0) return null; |
| 259 | |
| 260 | try { |
| 261 | const payload = JSON.parse(String(result.stdout ?? '')) as { |
| 262 | devices: Record<string, { udid: string; state: string }[]>; |
| 263 | }; |
| 264 | |
| 265 | for (const runtime of Object.values(payload.devices ?? {})) { |
| 266 | const match = runtime.find((entry) => entry.udid === udid); |
| 267 | if (match) return match.state; |
| 268 | } |
| 269 | return null; |
| 270 | } catch { |
| 271 | return null; |
| 272 | } |
| 273 | } |
no test coverage detected