From 3ee8aef154c0bd712c5892491938d1202e97e49e Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Fri, 17 Sep 2021 05:00:48 -0700 Subject: [PATCH] Fix bug in iOSDevice detection if both physical and emulator are active Summary: When connecting both to an iOS emulator and physical device, the emulator devices would continuesly be replaced, and Flipper would print the warning `Tried to replace still connected device XXX with a new instance` Fixed the logical mistake that causes it. Not sure if this caused any actual bugs, but at least it was incorrect. Reviewed By: lblasa Differential Revision: D31015451 fbshipit-source-id: 32dd29043e9dc48357fdbf68cde930d3be11419a --- .../app/src/server/devices/ios/iOSDeviceManager.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/desktop/app/src/server/devices/ios/iOSDeviceManager.tsx b/desktop/app/src/server/devices/ios/iOSDeviceManager.tsx index 3b9916a19..4b8f8d513 100644 --- a/desktop/app/src/server/devices/ios/iOSDeviceManager.tsx +++ b/desktop/app/src/server/devices/ios/iOSDeviceManager.tsx @@ -143,7 +143,7 @@ export class IOSDeviceManager { private processDevices( activeDevices: IOSDeviceParams[], - type: 'physical' | 'emulator', + targetType: 'physical' | 'emulator', ) { if (!this.iosBridge) { throw new Error('iOS bridge not yet initialized'); @@ -152,10 +152,7 @@ export class IOSDeviceManager { this.flipperServer .getDevices() .filter( - (device) => - device instanceof IOSDevice && - device.deviceType === type && - device.connected.get(), + (device) => device.os === 'iOS' && device.deviceType === targetType, ) .map((device) => device.serial), ); @@ -163,13 +160,17 @@ export class IOSDeviceManager { for (const {udid, type, name} of activeDevices) { if (currentDeviceIDs.has(udid)) { currentDeviceIDs.delete(udid); - } else { + } else if (targetType === type) { + console.log(`[conn] detected new iOS device ${targetType} ${udid}`); const iOSDevice = new IOSDevice(this.iosBridge, udid, type, name); this.flipperServer.registerDevice(iOSDevice); } } currentDeviceIDs.forEach((id) => { + console.log( + `[conn] Could no longer find ${targetType} ${id}, removing...`, + ); this.flipperServer.unregisterDevice(id); }); }