MCPcopy
hub / github.com/garrytan/gstack / listDevices

Function listDevices

ios-qa/daemon/src/devicectl.ts:69–95  ·  view source on GitHub ↗
(spawn: SpawnImpl = defaultSpawn)

Source from the content-addressed store, hash-verified

67 * and pairing-in-progress devices.
68 */
69export function listDevices(spawn: SpawnImpl = defaultSpawn): DeviceEntry[] {
70 const tmp = join(tmpdir(), `devicectl-list-${process.pid}-${Date.now()}.json`);
71 try {
72 const r = spawn('xcrun', ['devicectl', 'list', 'devices', '--json-output', tmp]);
73 if (r.status !== 0) return [];
74 const raw = readFileSync(tmp, 'utf-8');
75 const obj = JSON.parse(raw);
76 const list = (obj.result?.devices ?? []) as Array<Record<string, unknown>>;
77 return list.map((d) => {
78 const conn = d.connectionProperties as Record<string, unknown> | undefined;
79 const props = d.deviceProperties as Record<string, unknown> | undefined;
80 const hw = d.hardwareProperties as Record<string, unknown> | undefined;
81 const pairingState = String(conn?.pairingState ?? '');
82 return {
83 identifier: String(d.identifier ?? ''),
84 name: String(props?.name ?? 'unknown'),
85 model: String(hw?.productType ?? 'unknown'),
86 state: String(conn?.tunnelState ?? 'unknown'),
87 paired: pairingState === 'paired',
88 };
89 });
90 } catch {
91 return [];
92 } finally {
93 try { rmSync(tmp, { force: true }); } catch { /* ignore */ }
94 }
95}
96
97/**
98 * Resolve the CoreDevice tunnel's IPv6 address from `devicectl device info

Callers 1

bootstrapTunnelFunction · 0.90

Calls 1

spawnFunction · 0.85

Tested by

no test coverage detected