Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/utils/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ export interface Device {
}

export async function getAvailableDevices(): Promise<Device[]> {
const devices: Device[] = [];

try {
const { stdout: adbOutput } = await execAsync('adb devices');
const androidDevices = parseAdbDevicesOutput(adbOutput);
devices.push(...androidDevices);
} catch (error) {
console.error('Error getting Android devices:', error);
}

try {
const { stdout: xcrunOutput } = await execAsync('xcrun xctrace list devices');
const iosDevices = parseXcrunDevicesOutput(xcrunOutput);

return [...androidDevices, ...iosDevices];
devices.push(...iosDevices);
} catch (error) {
console.error('Error getting devices:', error);
return [];
console.error('Error getting iOS devices:', error);
}

return devices;
}

export async function getDefaultDevice(): Promise<string | undefined> {
Expand All @@ -33,7 +40,7 @@ export async function getDefaultDevice(): Promise<string | undefined> {
function parseAdbDevicesOutput(output: string): Device[] {
const lines = output.split('\n');
const devices: Device[] = [];

for (let i = 1; i < lines.length; i++) {
const line = lines[i].trim();
if (line && !line.includes('---')) {
Expand All @@ -47,18 +54,18 @@ function parseAdbDevicesOutput(output: string): Device[] {
}
}
}

return devices;
}

function parseXcrunDevicesOutput(output: string): Device[] {
const lines = output.split('\n');
const devices: Device[] = [];
let currentSection = '';

for (const line of lines) {
const trimmedLine = line.trim();

if (!trimmedLine || trimmedLine.startsWith('==')) {
if (trimmedLine.startsWith('== Devices ==')) {
currentSection = 'device';
Expand All @@ -76,12 +83,12 @@ function parseXcrunDevicesOutput(output: string): Device[] {
devices.push({
id,
name: version ? `${name} (${version})` : name,
type: currentSection === 'simulator' ? 'iOS Simulator' :
currentSection === 'offline' ? 'iOS Device (Offline)' : 'iOS Device'
type: currentSection === 'simulator' ? 'iOS Simulator' :
currentSection === 'offline' ? 'iOS Device (Offline)' : 'iOS Device'
});
}
}

return devices;
}

Expand Down
Loading