From 9cbdc3038fb6a7b0ed43316c2c64990e08c2511f Mon Sep 17 00:00:00 2001 From: Lawrence Lomax Date: Tue, 1 Feb 2022 00:43:24 -0800 Subject: [PATCH] Remove mising iOS Bridge invariant in iOSDeviceManager Summary: There's no need for us to have a property that can be undefined, since we can use the magic of *passing arguments* to achieve the same end result. The unit test a bit more precarious, but it's left here for posterity or until we decide to kill it otherwise. Reviewed By: passy Differential Revision: D33892407 fbshipit-source-id: 3b499511189862e2265d8d6d29f849a7b813050e --- .../devices/ios/__tests__/iOSDevice.node.tsx | 2 -- .../src/devices/ios/iOSDeviceManager.tsx | 18 +++++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx b/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx index eb372e8e2..eda1cfd18 100644 --- a/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx +++ b/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx @@ -72,7 +72,6 @@ test('test queryDevices when simctl used', () => { ); (flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings; flipperServer.ios.simctlBridge = fakeSimctlBridge; - flipperServer.ios.iosBridge = fakeSimctlBridge; flipperServer.ios.queryDevices(fakeSimctlBridge); expect(hasCalledSimctlActiveDevices).toEqual(true); expect(hasCalledIDBActiveDevices).toEqual(false); @@ -85,7 +84,6 @@ test('test queryDevices when idb used', () => { ); (flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings; flipperServer.ios.simctlBridge = fakeSimctlBridge; - flipperServer.ios.iosBridge = fakeIDBBridge; flipperServer.ios.queryDevices(fakeIDBBridge); expect(hasCalledSimctlActiveDevices).toEqual(false); expect(hasCalledIDBActiveDevices).toEqual(true); diff --git a/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx b/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx index 47c24c0ed..7c48782b8 100644 --- a/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx +++ b/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx @@ -35,7 +35,6 @@ export class IOSDeviceManager { 'MacOS', 'PortForwardingMacApp', ); - iosBridge: IOSBridge | undefined; simctlBridge: SimctlBridge = new SimctlBridge(); public xcodeCommandLineToolsDetected = false; @@ -89,14 +88,11 @@ export class IOSDeviceManager { queryDevices(bridge: IOSBridge): Promise { return bridge .getActiveDevices(true) - .then((devices) => this.processDevices(devices)); + .then((devices) => this.processDevices(bridge, devices)); } - private processDevices(activeDevices: IOSDeviceParams[]) { + private processDevices(bridge: IOSBridge, activeDevices: IOSDeviceParams[]) { console.debug('[conn] processDevices', activeDevices); - if (!this.iosBridge) { - throw new Error('iOS bridge not yet initialized'); - } const currentDeviceIDs = new Set( this.flipperServer .getDevices() @@ -116,7 +112,7 @@ export class IOSDeviceManager { console.info(`[conn] detected new iOS device ${udid}`, activeDevice); const iOSDevice = new IOSDevice( this.flipperServer, - this.iosBridge, + bridge, udid, type, name, @@ -141,15 +137,15 @@ export class IOSDeviceManager { this.startDevicePortForwarders(); } try { + // Check for version mismatch now for immediate error handling. + await this.checkXcodeVersionMismatch(); // Awaiting the promise here to trigger immediate error handling. - this.iosBridge = await makeIOSBridge( + const bridge = await makeIOSBridge( settings.idbPath, isDetected, settings.enablePhysicalIOS, ); - // Check for version mismatch now for immediate error handling. - await this.checkXcodeVersionMismatch(); - this.queryDevicesForever(this.iosBridge); + this.queryDevicesForever(bridge); } catch (err) { // This case is expected if both Xcode and idb are missing. if (err.message === ERR_NO_IDB_OR_XCODE_AVAILABLE) {