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)