From a097e673d815d6a5ffb0a5bdcaee160f15f4e608 Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 16 Jul 2019 08:30:43 -0700 Subject: [PATCH] Back out "[flipper] fix reconnecting clients" Summary: Original commit changeset: 1d0e6ce17c89 Backing this out until we can come up with a better way to do it. The change was introduced so that when a device disconnects / crashes, we don't lose all plugin state, and you can still see what was on screen before the crash.. However, there are some problems with this solution, which get quite complicated. Putting them here for future reference: * Closing an app results in the plugins staying there, and there's no way to tell it's not actually connected. * If the app reconnects, the JS plugin doesn't get re-initialized. Even though the client plugin has been. Reviewed By: bnelo12 Differential Revision: D16280932 fbshipit-source-id: 92585cdd0dace2012924df4106327a1e21ab9f9b --- src/dispatcher/androidDevice.js | 33 +++++---------------------------- src/reducers/connections.js | 4 +--- src/reducers/pluginStates.js | 12 ------------ 3 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/dispatcher/androidDevice.js b/src/dispatcher/androidDevice.js index 45abbbf86..64b3c65d2 100644 --- a/src/dispatcher/androidDevice.js +++ b/src/dispatcher/androidDevice.js @@ -10,7 +10,6 @@ import child_process from 'child_process'; import type {Store} from '../reducers/index.js'; import type BaseDevice from '../devices/BaseDevice'; import type {Logger} from '../fb-interfaces/Logger.js'; -import type Client from '../Client.js'; import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js'; import {getAdbClient} from '../utils/adbClient'; import {default as which} from 'which'; @@ -161,7 +160,7 @@ export default (store: Store, logger: Logger) => { }); // remove offline devices with same serial as the connected. - const reconnectedDevices: Array = store + const reconnectedDevices = store .getState() .connections.devices.filter( (device: BaseDevice) => @@ -169,32 +168,10 @@ export default (store: Store, logger: Logger) => { ) .map(device => device.serial); - if (reconnectedDevices.length > 0) { - reconnectedDevices.forEach((device: string) => { - // remove all disconnected clients for the reconnected device - store - .getState() - .connections.clients.filter( - (client: Client) => client.query.device_id === device, - ) - .forEach((client: Client) => { - store.dispatch({ - type: 'CLIENT_REMOVED', - payload: client.id, - }); - store.dispatch({ - type: 'CLEAR_CLIENT_PLUGINS', - payload: client.id, - }); - }); - }); - - // remove archived devices of previously connected devices - store.dispatch({ - type: 'UNREGISTER_DEVICES', - payload: new Set(reconnectedDevices), - }); - } + store.dispatch({ + type: 'UNREGISTER_DEVICES', + payload: new Set(reconnectedDevices), + }); store.dispatch({ type: 'REGISTER_DEVICE', diff --git a/src/reducers/connections.js b/src/reducers/connections.js index cb084a46a..66fd8b9a0 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -237,9 +237,7 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { return { ...state, - clients: state.clients - .filter((client: Client) => client.id !== payload.id) - .concat(payload), + clients: state.clients.concat(payload), uninitializedClients: state.uninitializedClients.filter(c => { return ( c.deviceId !== payload.query.device_id || diff --git a/src/reducers/pluginStates.js b/src/reducers/pluginStates.js index 567cfdb5a..c08ca0cfd 100644 --- a/src/reducers/pluginStates.js +++ b/src/reducers/pluginStates.js @@ -24,10 +24,6 @@ export type Action = | { type: 'CLEAR_PLUGIN_STATE', payload: {id: string, devicePlugins: Set}, - } - | { - type: 'CLEAR_CLIENT_PLUGINS', - payload: string, }; const INITIAL_STATE: State = {}; @@ -59,14 +55,6 @@ export default function reducer( } return newState; }, {}); - } else if (action.type === 'CLEAR_CLIENT_PLUGINS') { - const {payload} = action; - return Object.keys(state).reduce((newState, pluginKey) => { - if (!pluginKey.startsWith(payload)) { - newState[pluginKey] = state[pluginKey]; - } - return newState; - }, {}); } else { return state; }