Skip to content

Commit

Permalink
[cli] Update listDevices order to show physical devices first (#197)
Browse files Browse the repository at this point in the history
* [cli] Update listDevices order to show physical devices first

* Add changelog entry
  • Loading branch information
gabrieldonadel committed Apr 29, 2024
1 parent 6167900 commit 7187925
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### 💡 Others

- Update devices order to show physical devices first. ([#197](https://github.com/expo/orbit/pull/197) by [@gabrieldonadel](https://github.com/gabrieldonadel))

## 1.1.1 — 2024-03-15

### 🐛 Bug fixes
Expand Down
25 changes: 14 additions & 11 deletions apps/cli/src/commands/ListDevices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppleDevice, Emulator, Simulator } from 'eas-shared';
import { DevicesPerPlatform } from 'common-types/build/cli-commands/listDevices';
import { InternalError, Platform } from 'common-types';
import { InternalError, Platform, Devices } from 'common-types';

export async function listDevicesAsync<P extends Platform>({
platform,
Expand All @@ -14,16 +14,16 @@ export async function listDevicesAsync<P extends Platform>({

if (platform === Platform.Ios || platform === Platform.All) {
try {
result.ios.devices = result.ios.devices.concat(
await Simulator.getAvailableIosSimulatorsListAsync()
);

const connectedDevices = await AppleDevice.getConnectedDevicesAsync();
for (let connectedDevice of connectedDevices) {
for (const connectedDevice of connectedDevices) {
if (!result.ios.devices.some(({ udid }) => udid === connectedDevice.udid)) {
result.ios.devices.push(connectedDevice);
}
}

result.ios.devices = result.ios.devices.concat(
await Simulator.getAvailableIosSimulatorsListAsync()
);
} catch (error) {
console.warn('Unable to get iOS devices', error);
if (error instanceof Error) {
Expand All @@ -39,7 +39,11 @@ export async function listDevicesAsync<P extends Platform>({
try {
const runningDevices = await Emulator.getRunningDevicesAsync();

result.android.devices = (await Emulator.getAvailableAndroidEmulatorsAsync())?.map(
result.android.devices = result.android.devices.concat(
runningDevices.filter((r) => r.deviceType === 'device')
);

const androidEmulators = ((await Emulator.getAvailableAndroidEmulatorsAsync()) || [])?.map(
(emulator) => {
const runningEmulator = runningDevices.find(
(r) => r.deviceType === 'emulator' && r.name === emulator.name
Expand All @@ -48,12 +52,11 @@ export async function listDevicesAsync<P extends Platform>({
...emulator,
state: runningEmulator ? 'Booted' : 'Shutdown',
pid: runningEmulator?.pid,
};
} as Devices.AndroidEmulator;
}
);
result.android.devices = result.android.devices.concat(
runningDevices.filter((r) => r.deviceType === 'device')
);

result.android.devices = result.android.devices.concat(androidEmulators);
} catch (error) {
console.warn('Unable to get Android devices', error);
if (error instanceof Error) {
Expand Down

0 comments on commit 7187925

Please sign in to comment.