From 7040d487d8057bd2aabba72f27ed5f2498caa7e8 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 6 Nov 2019 06:16:08 -0800 Subject: [PATCH] don't keep querying iOS simulators if XCode was not installed properly Summary: Currently the app keeps to find iOS devices if when the tooling isn't properly set up, causing an error to appear every three secs. This change makes sure that happens only once. It also takes care of some run-away promises Reviewed By: jknoxville Differential Revision: D18346619 fbshipit-source-id: 12b581bee0d522b37b9e0c5d5b8dad0e4d2058d9 --- src/dispatcher/iOSDevice.tsx | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/dispatcher/iOSDevice.tsx b/src/dispatcher/iOSDevice.tsx index 57a3f2750..e36a073c6 100644 --- a/src/dispatcher/iOSDevice.tsx +++ b/src/dispatcher/iOSDevice.tsx @@ -66,8 +66,11 @@ if (typeof window !== 'undefined') { }); } -function queryDevices(store: Store, logger: Logger): Promise { - checkXcodeVersionMismatch(); +async function queryDevices(store: Store, logger: Logger): Promise { + if (!(await checkIfDevicesCanBeQueryied(store))) { + return; + } + await checkXcodeVersionMismatch(); const {connections} = store.getState(); const currentDeviceIDs: Set = new Set( connections.devices @@ -192,6 +195,32 @@ async function checkXcodeVersionMismatch() { } } +let canQueryDevices: boolean | undefined = undefined; + +async function checkIfDevicesCanBeQueryied(store: Store): Promise { + if (canQueryDevices !== undefined) { + return canQueryDevices; + } + try { + const exec = promisify(child_process.exec); + // make sure we can use instruments (it will throw otherwise) + await exec('instruments -s devices'); + return (canQueryDevices = true); + } catch (e) { + store.dispatch({ + type: 'SERVER_ERROR', + payload: { + message: + 'It looks like XCode was not installed properly. Further actions are required if you want to use an iOS emulator.', + details: + "You might want to run 'sudo xcode-select -s /Applications/Xcode.app/Contents/Developer'", + error: e, + }, + }); + return (canQueryDevices = false); + } +} + async function isXcodeDetected(): Promise { return promisify(child_process.exec)('xcode-select -p') .then(_ => true)