From ab84bd563a39208a5f26ca7558221228507dc432 Mon Sep 17 00:00:00 2001 From: John Knox Date: Thu, 4 Jun 2020 08:13:21 -0700 Subject: [PATCH] Enable physical iOS devices in open source Summary: The last piece of the puzzle to get this working. Now if a user has iOS development enabled in Flipper settings, and has XCode installed, we'll run the PortForwardingMacApp processes required to interact with iOS devices. It's not great the way it starts the processes without any error checking, but since that's the way it currently works, I'm leaving it as it is for now. Reviewed By: mweststrate Differential Revision: D21881041 fbshipit-source-id: 1d1fdb7e0621cff88408bb707d768bb5c6bea0cc --- desktop/app/src/dispatcher/iOSDevice.tsx | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/desktop/app/src/dispatcher/iOSDevice.tsx b/desktop/app/src/dispatcher/iOSDevice.tsx index 1222b0690..79fc1fbf9 100644 --- a/desktop/app/src/dispatcher/iOSDevice.tsx +++ b/desktop/app/src/dispatcher/iOSDevice.tsx @@ -31,6 +31,8 @@ type iOSSimulatorDevice = { type IOSDeviceParams = {udid: string; type: DeviceType; name: string}; +let portForwarders: Array = []; + function isAvailable(simulator: iOSSimulatorDevice): boolean { // For some users "availability" is set, for others it's "isAvailable" // It's not clear which key is set, so we are checking both. @@ -55,10 +57,15 @@ function forwardPort(port: number, multiplexChannelPort: number) { `-multiplexChannelPort=${multiplexChannelPort}`, ]); } -// start port forwarding server for real device connections -const portForwarders: Array = GK.get('flipper_ios_device_support') - ? [forwardPort(8089, 8079), forwardPort(8088, 8078)] - : []; + +function startDevicePortForwarders(): void { + if (portForwarders.length > 0) { + // Only ever start them once. + return; + } + // start port forwarding server for real device connections + portForwarders = [forwardPort(8089, 8079), forwardPort(8088, 8078)]; +} if (typeof window !== 'undefined') { window.addEventListener('beforeunload', () => { @@ -264,7 +271,11 @@ export default (store: Store, logger: Logger) => { store.dispatch(setXcodeDetected(isDetected)); return isDetected; }) - .then((isDetected) => - isDetected ? queryDevicesForever(store, logger) : Promise.resolve(), - ); + .then((isDetected) => { + if (isDetected) { + startDevicePortForwarders(); + return queryDevicesForever(store, logger); + } + return Promise.resolve(); + }); };