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
This commit is contained in:
John Knox
2018-12-04 07:08:05 -08:00
committed by Facebook Github Bot
parent 3057c0a6e7
commit 606d689cae
3 changed files with 35 additions and 12 deletions

View File

@@ -9,8 +9,8 @@ import type {ChildProcess} from 'child_process';
import type {Store} from '../reducers/index.js'; import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js'; import type Logger from '../fb-stubs/Logger.js';
import type {DeviceType} from '../devices/BaseDevice'; import type {DeviceType} from '../devices/BaseDevice';
import {RecurringError} from '../utils/errors';
import {RecurringError} from '../utils/errors';
import {promisify} from 'util'; import {promisify} from 'util';
import path from 'path'; import path from 'path';
import child_process from 'child_process'; import child_process from 'child_process';
@@ -18,6 +18,7 @@ const execFile = child_process.execFile;
import IOSDevice from '../devices/IOSDevice'; import IOSDevice from '../devices/IOSDevice';
import iosUtil from '../fb-stubs/iOSContainerUtility'; import iosUtil from '../fb-stubs/iOSContainerUtility';
import isProduction from '../utils/isProduction.js'; import isProduction from '../utils/isProduction.js';
import GK from '../fb-stubs/GK';
type iOSSimulatorDevice = {| type iOSSimulatorDevice = {|
state: 'Booted' | 'Shutdown' | 'Shutting Down', state: 'Booted' | 'Shutdown' | 'Shutting Down',
@@ -43,10 +44,9 @@ function forwardPort(port: number, multiplexChannelPort: number) {
]); ]);
} }
// start port forwarding server for real device connections // start port forwarding server for real device connections
const portForwarders: Array<ChildProcess> = [ const portForwarders: Array<ChildProcess> = GK.get('flipper_ios_device_support')
forwardPort(8089, 8079), ? [forwardPort(8089, 8079), forwardPort(8088, 8078)]
forwardPort(8088, 8078), : [];
];
window.addEventListener('beforeunload', () => { window.addEventListener('beforeunload', () => {
portForwarders.forEach(process => process.kill()); portForwarders.forEach(process => process.kill());
}); });
@@ -112,12 +112,10 @@ function getActiveSimulators(): Promise<Array<IOSDeviceParams>> {
} }
function getActiveDevices(): Promise<Array<IOSDeviceParams>> { function getActiveDevices(): Promise<Array<IOSDeviceParams>> {
return iosUtil.isAvailable() return iosUtil.targets().catch(e => {
? iosUtil.targets().catch(e => { console.error(new RecurringError(e.message));
console.error(new RecurringError(e.message)); return [];
return []; });
})
: Promise.resolve([]);
} }
export default (store: Store, logger: Logger) => { export default (store: Store, logger: Logger) => {

View File

@@ -4,6 +4,8 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* @format * @format
*/ */
import {promisify} from 'util';
const exec = promisify(require('child_process').exec);
const errorMessage = 'Physical iOS devices not yet supported'; const errorMessage = 'Physical iOS devices not yet supported';
@@ -18,7 +20,21 @@ function isAvailable(): boolean {
} }
function targets(): Promise<Array<DeviceTarget>> { function targets(): Promise<Array<DeviceTarget>> {
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( function push(

View File

@@ -10,6 +10,7 @@ import type Client from '../Client';
import type {UninitializedClient} from '../UninitializedClient'; import type {UninitializedClient} from '../UninitializedClient';
import {isEqual} from 'lodash'; import {isEqual} from 'lodash';
import {RecurringError} from '../utils/errors'; import {RecurringError} from '../utils/errors';
import iosUtil from '../fb-stubs/iOSContainerUtility';
export type State = {| export type State = {|
devices: Array<BaseDevice>, devices: Array<BaseDevice>,
@@ -153,12 +154,20 @@ export default function reducer(
selection = {}; selection = {};
} }
const error =
payload.os === 'iOS' &&
payload.deviceType === 'physical' &&
!iosUtil.isAvailable()
? 'iOS Devices are not yet supported'
: null;
return { return {
...state, ...state,
devices, devices,
// select device if none was selected before // select device if none was selected before
selectedDevice, selectedDevice,
...selection, ...selection,
error,
}; };
} }
case 'UNREGISTER_DEVICES': { case 'UNREGISTER_DEVICES': {