faster iOS device connection
Summary: First connection attempt to iOS device was only made after 3000ms. This caused all iOS devices only show up after this delay. Now, the devices are queried immediately. Reviewed By: passy Differential Revision: D9613057 fbshipit-source-id: a14e3f02576ec5e159f4002bf68efe53236dcc50
This commit is contained in:
committed by
Facebook Github Bot
parent
ace800ad55
commit
a30e0b53e9
@@ -9,7 +9,10 @@ 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 {promisify} from 'util';
|
||||||
import child_process from 'child_process';
|
import child_process from 'child_process';
|
||||||
|
const exec = promisify(child_process.exec);
|
||||||
|
const execFile = promisify(child_process.execFile);
|
||||||
import IOSDevice from '../devices/IOSDevice';
|
import IOSDevice from '../devices/IOSDevice';
|
||||||
|
|
||||||
type iOSSimulatorDevice = {|
|
type iOSSimulatorDevice = {|
|
||||||
@@ -22,43 +25,20 @@ type iOSSimulatorDevice = {|
|
|||||||
type IOSDeviceMap = {[id: string]: Array<iOSSimulatorDevice>};
|
type IOSDeviceMap = {[id: string]: Array<iOSSimulatorDevice>};
|
||||||
|
|
||||||
// start port forwarding server for real device connections
|
// start port forwarding server for real device connections
|
||||||
const portForwarder: ChildProcess = child_process.exec(
|
const portForwarder: ChildProcess = exec(
|
||||||
'PortForwardingMacApp.app/Contents/MacOS/PortForwardingMacApp -portForward=8088 -multiplexChannelPort=8078',
|
'PortForwardingMacApp.app/Contents/MacOS/PortForwardingMacApp -portForward=8088 -multiplexChannelPort=8078',
|
||||||
);
|
);
|
||||||
window.addEventListener('beforeunload', () => {
|
window.addEventListener('beforeunload', () => {
|
||||||
portForwarder.kill();
|
portForwarder.kill();
|
||||||
});
|
});
|
||||||
|
|
||||||
function querySimulatorDevices(): Promise<IOSDeviceMap> {
|
function querySimulatorDevices(store: Store): Promise<IOSDeviceMap> {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
child_process.execFile(
|
|
||||||
'xcrun',
|
|
||||||
['simctl', 'list', 'devices', '--json'],
|
|
||||||
{encoding: 'utf8'},
|
|
||||||
(err, stdout) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const {devices} = JSON.parse(stdout.toString());
|
|
||||||
resolve(devices);
|
|
||||||
} catch (err) {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default (store: Store, logger: Logger) => {
|
|
||||||
// monitoring iOS devices only available on MacOS.
|
|
||||||
if (process.platform !== 'darwin') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const simulatorUpdateInterval = setInterval(() => {
|
|
||||||
const {connections} = store.getState();
|
const {connections} = store.getState();
|
||||||
querySimulatorDevices()
|
|
||||||
|
return execFile('xcrun', ['simctl', 'list', 'devices', '--json'], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
})
|
||||||
|
.then(({stdout}) => JSON.parse(stdout).devices)
|
||||||
.then((simulatorDevices: IOSDeviceMap) => {
|
.then((simulatorDevices: IOSDeviceMap) => {
|
||||||
const simulators: Array<iOSSimulatorDevice> = Object.values(
|
const simulators: Array<iOSSimulatorDevice> = Object.values(
|
||||||
simulatorDevices,
|
simulatorDevices,
|
||||||
@@ -81,11 +61,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
// create device
|
// create device
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'REGISTER_DEVICE',
|
type: 'REGISTER_DEVICE',
|
||||||
payload: new IOSDevice(
|
payload: new IOSDevice(simulator.udid, 'emulator', simulator.name),
|
||||||
simulator.udid,
|
|
||||||
'emulator',
|
|
||||||
simulator.name,
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
} else if (!isRunning && currentDeviceIDs.has(simulator.udid)) {
|
} else if (!isRunning && currentDeviceIDs.has(simulator.udid)) {
|
||||||
deviceIDsToRemove.add(simulator.udid);
|
deviceIDsToRemove.add(simulator.udid);
|
||||||
@@ -99,10 +75,22 @@ export default (store: Store, logger: Logger) => {
|
|||||||
payload: deviceIDsToRemove,
|
payload: deviceIDsToRemove,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.catch(err => {
|
}
|
||||||
|
|
||||||
|
export default (store: Store, logger: Logger) => {
|
||||||
|
// monitoring iOS devices only available on MacOS.
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
querySimulatorDevices(store)
|
||||||
|
.then(() => {
|
||||||
|
const simulatorUpdateInterval = setInterval(() => {
|
||||||
|
querySimulatorDevices(store).catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
clearInterval(simulatorUpdateInterval);
|
clearInterval(simulatorUpdateInterval);
|
||||||
});
|
});
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user