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
This commit is contained in:
committed by
Facebook Github Bot
parent
2446e82dc6
commit
7040d487d8
@@ -66,8 +66,11 @@ if (typeof window !== 'undefined') {
|
||||
});
|
||||
}
|
||||
|
||||
function queryDevices(store: Store, logger: Logger): Promise<void> {
|
||||
checkXcodeVersionMismatch();
|
||||
async function queryDevices(store: Store, logger: Logger): Promise<void> {
|
||||
if (!(await checkIfDevicesCanBeQueryied(store))) {
|
||||
return;
|
||||
}
|
||||
await checkXcodeVersionMismatch();
|
||||
const {connections} = store.getState();
|
||||
const currentDeviceIDs: Set<string> = new Set(
|
||||
connections.devices
|
||||
@@ -192,6 +195,32 @@ async function checkXcodeVersionMismatch() {
|
||||
}
|
||||
}
|
||||
|
||||
let canQueryDevices: boolean | undefined = undefined;
|
||||
|
||||
async function checkIfDevicesCanBeQueryied(store: Store): Promise<boolean> {
|
||||
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<boolean> {
|
||||
return promisify(child_process.exec)('xcode-select -p')
|
||||
.then(_ => true)
|
||||
|
||||
Reference in New Issue
Block a user