Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Added spinner for device searching (#3328)
Browse files Browse the repository at this point in the history
* Added spinner for device loading

* Update resolveDeviceAsync.ts
  • Loading branch information
EvanBacon authored Mar 25, 2021
1 parent 912bce7 commit d8c1d8a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/expo-cli/src/commands/run/ios/resolveDeviceAsync.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import chalk from 'chalk';
import ora from 'ora';
import { SimControl, Simulator } from 'xdl';

import CommandError from '../../../CommandError';
import Log from '../../../log';
import prompt from '../../../prompts';
import { profileMethod } from '../../utils/profileMethod';

async function getSimulatorsAsync(): Promise<SimControl.SimulatorDevice[]> {
const simulatorDeviceInfo = await SimControl.listAsync('devices');
Expand All @@ -13,11 +15,15 @@ async function getSimulatorsAsync(): Promise<SimControl.SimulatorDevice[]> {
}

async function getBuildDestinationsAsync() {
const devices = (await SimControl.listDevicesAsync()).filter(device => {
const devices = (
await profileMethod(SimControl.listDevicesAsync, 'SimControl.listDevicesAsync')()
).filter(device => {
return device.deviceType === 'device';
});

const simulators = await Simulator.sortDefaultDeviceToBeginningAsync(await getSimulatorsAsync());
const simulators = await Simulator.sortDefaultDeviceToBeginningAsync(
await profileMethod(getSimulatorsAsync)()
);

return [...devices, ...simulators];
}
Expand All @@ -26,10 +32,20 @@ export async function resolveDeviceAsync(
device: string | boolean | undefined
): Promise<SimControl.SimulatorDevice | SimControl.XCTraceDevice> {
if (!device) {
return await Simulator.ensureSimulatorOpenAsync();
return await profileMethod(
Simulator.ensureSimulatorOpenAsync,
'Simulator.ensureSimulatorOpenAsync'
)();
}

const devices = await getBuildDestinationsAsync();
const spinner = ora(
`🔍 Finding ${device === true ? 'devices' : `device ${chalk.cyan(device)}`}`
).start();
const devices: (
| SimControl.SimulatorDevice
| SimControl.XCTraceDevice
)[] = await getBuildDestinationsAsync().catch(() => []);
spinner.stop();

if (device === true) {
// --device with no props after
Expand Down

0 comments on commit d8c1d8a

Please sign in to comment.