Show iOS version in launcher

Summary:
A little hacky because we currently have too many implementations for getting devices but lblasa is working on cleaning this up. Once that's done, we should add some tests for this.

Changelog: Show the iOS version of simulators in the launcher window

Reviewed By: lblasa

Differential Revision: D48777923

fbshipit-source-id: 18846520feba8eb10b6417f87bd802ffaabb1dff
This commit is contained in:
Pascal Hartig
2023-08-29 04:55:46 -07:00
committed by Facebook GitHub Bot
parent 7ce86869e4
commit d4d8c965eb
5 changed files with 33 additions and 15 deletions

View File

@@ -176,6 +176,7 @@ export type IOSDeviceParams = {
udid: string;
type: DeviceType;
name: string;
osVersion?: string;
deviceTypeIdentifier?: string;
state?: string;
};

View File

@@ -42,6 +42,16 @@ interface IOSInstalledAppDescriptor {
debuggableStatus: boolean;
}
function getOSVersionFromXCRunOutput(s: string): string | undefined {
// E.g. 'com.apple.CoreSimulator.SimRuntime.iOS-16-1'
const match = s.match(
/com\.apple\.CoreSimulator\.SimRuntime\.iOS-(\d+)-(\d+)/,
);
if (match) {
return `${match[1]}.${match[2]}`;
}
}
export interface IOSBridge {
startLogListener: (
udid: string,
@@ -284,21 +294,23 @@ export class SimctlBridge implements IOSBridge {
'--json',
])
.then(({stdout}) => JSON.parse(stdout!.toString()).devices)
.then((simulatorDevices: Array<iOSSimulatorDevice>) => {
const simulators = Object.values(simulatorDevices).flat();
return simulators
.then((simulatorDevices: {[key: string]: Array<iOSSimulatorDevice>}) =>
Object.keys(simulatorDevices).flatMap((key: string) =>
simulatorDevices[key]
.filter(
(simulator) =>
(simulator: iOSSimulatorDevice) =>
(!bootedOnly || simulator.state === 'Booted') &&
isSimulatorAvailable(simulator),
)
.map((simulator) => {
.map((simulator: iOSSimulatorDevice) => {
return {
...simulator,
type: 'emulator',
osVersion: getOSVersionFromXCRunOutput(key),
} as IOSDeviceParams;
});
});
}),
),
);
}
async launchSimulator(udid: string): Promise<any> {

View File

@@ -24,11 +24,13 @@ const fakeDevices: IOSDeviceParams[] = [
udid: 'luke',
type: 'emulator',
name: 'Luke',
osVersion: '16.4',
},
{
udid: 'yoda',
type: 'emulator',
name: 'Yoda',
osVersion: '16.4',
},
];
const fakeExistingDevices = [

View File

@@ -48,6 +48,7 @@ export type DeviceTarget = {
udid: string;
type: DeviceType;
name: string;
osVersion?: string;
};
let idbDeviceListing = 0;
@@ -253,6 +254,7 @@ function parseIdbTarget(line: string): DeviceTarget | undefined {
? 'emulator'
: ('physical' as DeviceType),
name: parsed.name,
osVersion: parsed.os_version,
};
}

View File

@@ -229,6 +229,7 @@ export const LaunchEmulatorDialog = withTrackingScope(
.then(onClose)
}>
{device.name}
{device.osVersion ? ` (${device.osVersion})` : ''}
</Button>
</VirtualDeviceRow>
))