diff --git a/src/dispatcher/androidDevice.js b/src/dispatcher/androidDevice.js index 64b3c65d2..45abbbf86 100644 --- a/src/dispatcher/androidDevice.js +++ b/src/dispatcher/androidDevice.js @@ -10,6 +10,7 @@ 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'; @@ -160,7 +161,7 @@ export default (store: Store, logger: Logger) => { }); // remove offline devices with same serial as the connected. - const reconnectedDevices = store + const reconnectedDevices: Array = store .getState() .connections.devices.filter( (device: BaseDevice) => @@ -168,10 +169,32 @@ export default (store: Store, logger: Logger) => { ) .map(device => device.serial); - store.dispatch({ - type: 'UNREGISTER_DEVICES', - payload: new Set(reconnectedDevices), - }); + 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: 'REGISTER_DEVICE', diff --git a/src/reducers/connections.js b/src/reducers/connections.js index fba9ca801..cec7a8bb5 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -237,7 +237,9 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => { return { ...state, - clients: state.clients.concat(payload), + clients: state.clients + .filter((client: Client) => client.id !== payload.id) + .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 c08ca0cfd..567cfdb5a 100644 --- a/src/reducers/pluginStates.js +++ b/src/reducers/pluginStates.js @@ -24,6 +24,10 @@ export type Action = | { type: 'CLEAR_PLUGIN_STATE', payload: {id: string, devicePlugins: Set}, + } + | { + type: 'CLEAR_CLIENT_PLUGINS', + payload: string, }; const INITIAL_STATE: State = {}; @@ -55,6 +59,14 @@ 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; }