( fileSystem: FileSystemExecutor, executor: CommandExecutor, )
| 738 | } |
| 739 | |
| 740 | async function listAvailableDevices( |
| 741 | fileSystem: FileSystemExecutor, |
| 742 | executor: CommandExecutor, |
| 743 | ): Promise<SetupDevice[]> { |
| 744 | let jsonPath: string | undefined; |
| 745 | |
| 746 | try { |
| 747 | jsonPath = path.join(fileSystem.tmpdir(), `xcodebuildmcp-setup-devices-${Date.now()}.json`); |
| 748 | |
| 749 | const result = await executor( |
| 750 | ['xcrun', 'devicectl', 'list', 'devices', '--json-output', jsonPath], |
| 751 | 'List Devices (setup)', |
| 752 | false, |
| 753 | undefined, |
| 754 | ); |
| 755 | |
| 756 | if (result.success) { |
| 757 | const jsonContent = await fileSystem.readFile(jsonPath, 'utf8'); |
| 758 | const devices = parseDeviceListResponse(JSON.parse(jsonContent)); |
| 759 | if (devices.length > 0) { |
| 760 | return devices; |
| 761 | } |
| 762 | } |
| 763 | } catch { |
| 764 | // Fall back to xctrace below. |
| 765 | } finally { |
| 766 | if (jsonPath != null) { |
| 767 | await fileSystem.rm(jsonPath, { force: true }).catch(() => {}); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | try { |
| 772 | const fallbackResult = await executor( |
| 773 | ['xcrun', 'xctrace', 'list', 'devices'], |
| 774 | 'List Devices (setup fallback)', |
| 775 | false, |
| 776 | undefined, |
| 777 | ); |
| 778 | |
| 779 | if (!fallbackResult.success) { |
| 780 | return []; |
| 781 | } |
| 782 | |
| 783 | return parseXctraceDevices(fallbackResult.output); |
| 784 | } catch { |
| 785 | return []; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | function getDefaultDeviceIndex(devices: SetupDevice[], existingDeviceId?: string): number { |
| 790 | if (existingDeviceId != null) { |
no test coverage detected