Use polymorphic IOSBridge to perform iOS target listing

Summary:
Bulding on the work from prior diffs we can use the created bridge directly. No need to have if statements calling out to sub-functions, just use the base type itself which will use the appropriate implementation.

There's no behavioural change here. Either idb was queried for sims/devices or simctl was queried for just sims, they were always mutually exclusive.

Reviewed By: passy

Differential Revision: D33842604

fbshipit-source-id: 0bf63ffc34368c70df31c105ea0ba5df941e72cc
This commit is contained in:
Lawrence Lomax
2022-02-01 00:43:24 -08:00
committed by Facebook GitHub Bot
parent b0046c8ddb
commit 757b82757e
2 changed files with 24 additions and 39 deletions

View File

@@ -17,14 +17,12 @@ import IOSDevice from './IOSDevice';
import {
ERR_NO_IDB_OR_XCODE_AVAILABLE,
IOSBridge,
IDBBridge,
makeIOSBridge,
SimctlBridge,
} from './IOSBridge';
import {FlipperServerImpl} from '../../FlipperServerImpl';
import {getFlipperServerConfig} from '../../FlipperServerConfig';
import {IdbConfig, setIdbConfig} from './idbConfig';
import {assertNotNull} from 'flipper-server-core/src/comms/Utilities';
export class IOSDeviceManager {
private portForwarders: Array<ChildProcess> = [];
@@ -88,25 +86,10 @@ export class IOSDeviceManager {
];
}
getPromiseForQueryingDevices(isIdbAvailable: boolean): Promise<any> {
assertNotNull(this.idbConfig);
return isIdbAvailable
? getActiveDevices(
this.idbConfig.idbPath,
this.idbConfig.enablePhysicalIOS,
).then((devices: IOSDeviceParams[]) => {
this.processDevices(devices);
})
: this.getSimulators(true).then((devices) =>
this.processDevices(devices),
);
}
private async queryDevices(): Promise<any> {
assertNotNull(this.idbConfig);
const isIdbAvailable = await iosUtil.isAvailable(this.idbConfig.idbPath);
console.debug(`[conn] queryDevices. isIdbAvailable ${isIdbAvailable}`);
return this.getPromiseForQueryingDevices(isIdbAvailable);
queryDevices(bridge: IOSBridge): Promise<any> {
return bridge
.getActiveDevices(true)
.then((devices) => this.processDevices(devices));
}
private processDevices(activeDevices: IOSDeviceParams[]) {
@@ -166,7 +149,7 @@ export class IOSDeviceManager {
);
// Check for version mismatch now for immediate error handling.
await this.checkXcodeVersionMismatch();
this.queryDevicesForever();
this.queryDevicesForever(this.iosBridge);
} catch (err) {
// This case is expected if both Xcode and idb are missing.
if (err.message === ERR_NO_IDB_OR_XCODE_AVAILABLE) {
@@ -198,12 +181,12 @@ export class IOSDeviceManager {
});
}
private queryDevicesForever() {
return this.queryDevices()
private queryDevicesForever(bridge: IOSBridge) {
return this.queryDevices(bridge)
.then(() => {
// It's important to schedule the next check AFTER the current one has completed
// to avoid simultaneous queries which can cause multiple user input prompts.
setTimeout(() => this.queryDevicesForever(), 3000);
setTimeout(() => this.queryDevicesForever(bridge), 3000);
})
.catch((err) => {
console.warn('Failed to continuously query devices:', err);
@@ -259,10 +242,3 @@ export function checkXcodeVersionMismatch(
}
return undefined;
}
function getActiveDevices(
idbPath: string,
isPhysicalDeviceEnabled: boolean,
): Promise<Array<IOSDeviceParams>> {
return new IDBBridge(idbPath, isPhysicalDeviceEnabled).getActiveDevices(true);
}