From 606d689caea00aa03f4183889c807274a7061ffd Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 4 Dec 2018 07:08:05 -0800 Subject: [PATCH] Don't do iOS-specific setup when not supported Summary: Now flipper will include iOS devices in the dropdown, but you'll also get a message saying they aren't yet supported. Also doesn't start up the PortForwardingMacApp instances in this case, because it's pointless. Reviewed By: priteshrnandgaonkar Differential Revision: D13319990 fbshipit-source-id: 75d72c6ed2478c7b999c5f43b764f097141b33de --- src/dispatcher/iOSDevice.js | 20 +++++++++----------- src/fb-stubs/iOSContainerUtility.js | 18 +++++++++++++++++- src/reducers/connections.js | 9 +++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/dispatcher/iOSDevice.js b/src/dispatcher/iOSDevice.js index f930c5f43..bd16ef995 100644 --- a/src/dispatcher/iOSDevice.js +++ b/src/dispatcher/iOSDevice.js @@ -9,8 +9,8 @@ import type {ChildProcess} from 'child_process'; import type {Store} from '../reducers/index.js'; import type Logger from '../fb-stubs/Logger.js'; import type {DeviceType} from '../devices/BaseDevice'; -import {RecurringError} from '../utils/errors'; +import {RecurringError} from '../utils/errors'; import {promisify} from 'util'; import path from 'path'; import child_process from 'child_process'; @@ -18,6 +18,7 @@ const execFile = child_process.execFile; import IOSDevice from '../devices/IOSDevice'; import iosUtil from '../fb-stubs/iOSContainerUtility'; import isProduction from '../utils/isProduction.js'; +import GK from '../fb-stubs/GK'; type iOSSimulatorDevice = {| state: 'Booted' | 'Shutdown' | 'Shutting Down', @@ -43,10 +44,9 @@ function forwardPort(port: number, multiplexChannelPort: number) { ]); } // start port forwarding server for real device connections -const portForwarders: Array = [ - forwardPort(8089, 8079), - forwardPort(8088, 8078), -]; +const portForwarders: Array = GK.get('flipper_ios_device_support') + ? [forwardPort(8089, 8079), forwardPort(8088, 8078)] + : []; window.addEventListener('beforeunload', () => { portForwarders.forEach(process => process.kill()); }); @@ -112,12 +112,10 @@ function getActiveSimulators(): Promise> { } function getActiveDevices(): Promise> { - return iosUtil.isAvailable() - ? iosUtil.targets().catch(e => { - console.error(new RecurringError(e.message)); - return []; - }) - : Promise.resolve([]); + return iosUtil.targets().catch(e => { + console.error(new RecurringError(e.message)); + return []; + }); } export default (store: Store, logger: Logger) => { diff --git a/src/fb-stubs/iOSContainerUtility.js b/src/fb-stubs/iOSContainerUtility.js index da78d4ffe..832ff9c7c 100644 --- a/src/fb-stubs/iOSContainerUtility.js +++ b/src/fb-stubs/iOSContainerUtility.js @@ -4,6 +4,8 @@ * LICENSE file in the root directory of this source tree. * @format */ +import {promisify} from 'util'; +const exec = promisify(require('child_process').exec); const errorMessage = 'Physical iOS devices not yet supported'; @@ -18,7 +20,21 @@ function isAvailable(): boolean { } function targets(): Promise> { - return Promise.reject(errorMessage); + return exec('instruments -s devices').then(({stdout}) => + stdout + .toString() + .split('\n') + .map(line => line.trim()) + .map(line => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line)) + .filter(Boolean) + .filter( + ([match, name, udid, isSim]) => + !isSim && (name.includes('iPhone') || name.includes('iPad')), + ) + .map(([match, name, udid]) => { + return {udid: udid, type: 'physical', name: name}; + }), + ); } function push( diff --git a/src/reducers/connections.js b/src/reducers/connections.js index e9132e081..729c6ff46 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -10,6 +10,7 @@ import type Client from '../Client'; import type {UninitializedClient} from '../UninitializedClient'; import {isEqual} from 'lodash'; import {RecurringError} from '../utils/errors'; +import iosUtil from '../fb-stubs/iOSContainerUtility'; export type State = {| devices: Array, @@ -153,12 +154,20 @@ export default function reducer( selection = {}; } + const error = + payload.os === 'iOS' && + payload.deviceType === 'physical' && + !iosUtil.isAvailable() + ? 'iOS Devices are not yet supported' + : null; + return { ...state, devices, // select device if none was selected before selectedDevice, ...selection, + error, }; } case 'UNREGISTER_DEVICES': {