Summary: Removing PortForwarderMacApp as it is not used anymore. Before it was used to allow us to debug physical iOS device. However, the support for physical iOS device was removed a while ago for security reasons. The PortForwarder was not in use anymore so it is safe to remove it. Reviewed By: passy Differential Revision: D10337888 fbshipit-source-id: 93f508ec524a0fc055141176c06d7e7169d83f16
87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
import type {Store} from '../reducers/index.js';
|
|
import type Logger from '../fb-stubs/Logger.js';
|
|
|
|
import {promisify} from 'util';
|
|
import child_process from 'child_process';
|
|
const execFile = promisify(child_process.execFile);
|
|
import IOSDevice from '../devices/IOSDevice';
|
|
|
|
type iOSSimulatorDevice = {|
|
|
state: 'Booted' | 'Shutdown' | 'Shutting Down',
|
|
availability: string,
|
|
name: string,
|
|
udid: string,
|
|
|};
|
|
|
|
type IOSDeviceMap = {[id: string]: Array<iOSSimulatorDevice>};
|
|
|
|
function querySimulatorDevices(store: Store): Promise<IOSDeviceMap> {
|
|
const {connections} = store.getState();
|
|
|
|
return execFile('xcrun', ['simctl', 'list', 'devices', '--json'], {
|
|
encoding: 'utf8',
|
|
})
|
|
.then(({stdout}) => JSON.parse(stdout).devices)
|
|
.then((simulatorDevices: IOSDeviceMap) => {
|
|
const simulators: Array<iOSSimulatorDevice> = Object.values(
|
|
simulatorDevices,
|
|
// $FlowFixMe
|
|
).reduce((acc, cv) => acc.concat(cv), []);
|
|
|
|
const currentDeviceIDs: Set<string> = new Set(
|
|
connections.devices
|
|
.filter(device => device instanceof IOSDevice)
|
|
.map(device => device.serial),
|
|
);
|
|
|
|
const deviceIDsToRemove = new Set();
|
|
simulators.forEach((simulator: iOSSimulatorDevice) => {
|
|
const isRunning =
|
|
simulator.state === 'Booted' &&
|
|
simulator.availability === '(available)';
|
|
|
|
if (isRunning && !currentDeviceIDs.has(simulator.udid)) {
|
|
// create device
|
|
store.dispatch({
|
|
type: 'REGISTER_DEVICE',
|
|
payload: new IOSDevice(simulator.udid, 'emulator', simulator.name),
|
|
});
|
|
} else if (!isRunning && currentDeviceIDs.has(simulator.udid)) {
|
|
deviceIDsToRemove.add(simulator.udid);
|
|
// delete device
|
|
}
|
|
});
|
|
|
|
if (deviceIDsToRemove.size > 0) {
|
|
store.dispatch({
|
|
type: 'UNREGISTER_DEVICES',
|
|
payload: deviceIDsToRemove,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
export default (store: Store, logger: Logger) => {
|
|
// monitoring iOS devices only available on MacOS.
|
|
if (process.platform !== 'darwin') {
|
|
return;
|
|
}
|
|
querySimulatorDevices(store)
|
|
.then(() => {
|
|
const simulatorUpdateInterval = setInterval(() => {
|
|
querySimulatorDevices(store).catch(err => {
|
|
console.error(err);
|
|
clearInterval(simulatorUpdateInterval);
|
|
});
|
|
}, 3000);
|
|
})
|
|
.catch(console.error);
|
|
};
|