mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
5855dfc2e0
* refactor: route shutdown through device runtime * fix: cover shutdown cutover review gaps * fix: propagate shutdown cancellation * fix: move shutdown mechanics to platform owners * fix: pass device to shutdown fact fixture * test: cover shutdown facts in session state fixtures * test: simplify Android shutdown assertions * fix: preserve Apple shutdown cancellation
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import type { DeviceInfo } from '@agent-device/kernel/device';
|
|
import type { AppleToolHost } from '@agent-device/contracts/platform';
|
|
|
|
export async function getSimulatorState(
|
|
appleTools: AppleToolHost,
|
|
device: DeviceInfo,
|
|
signal: AbortSignal,
|
|
timeoutMs: number,
|
|
): Promise<string | null> {
|
|
const result = await appleTools.run(
|
|
{
|
|
tool: 'simctl',
|
|
args: simctlArgs(device, ['list', 'devices', '-j']),
|
|
allowFailure: true,
|
|
timeoutMs,
|
|
},
|
|
signal,
|
|
);
|
|
if (result.exitCode !== 0) return null;
|
|
try {
|
|
const payload = JSON.parse(result.stdout) as {
|
|
devices?: Record<string, Array<{ udid: string; state: string }>>;
|
|
};
|
|
return (
|
|
Object.values(payload.devices ?? {})
|
|
.flat()
|
|
.find(({ udid }) => udid === device.id)?.state ?? null
|
|
);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function simctlArgs(device: DeviceInfo, args: readonly string[]): string[] {
|
|
return device.simulatorSetPath ? ['--set', device.simulatorSetPath, ...args] : [...args];
|
|
}
|