Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Unregister device
Browse files Browse the repository at this point in the history
Summary:
Add a new reducer to allow device unregistration. It works as follow:

If the device is disconnected, it will remove the device from the devices list.

If there are more devices, the first device will become selected. If there are running apps, the first app will be selected.

Reviewed By: antonk52

Differential Revision: D55795279

fbshipit-source-id: de90cddf386a9ad3fe0c955b3696c91036decc79
  • Loading branch information
lblasa authored and facebook-github-bot committed Apr 22, 2024
1 parent 14b6931 commit b5f41df
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions desktop/flipper-ui/src/reducers/connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export type Action =
type: 'REGISTER_DEVICE';
payload: BaseDevice;
}
| {
type: 'UNREGISTER_DEVICE';
payload: BaseDevice;
}
| {
type: 'SELECT_DEVICE';
payload: BaseDevice;
Expand Down Expand Up @@ -259,6 +263,40 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
};
}

case 'UNREGISTER_DEVICE': {
const {payload} = action;

const newDevices = state.devices.slice();
const existing = state.devices.findIndex(
(device) => device.serial === payload.serial,
);
if (existing !== -1) {
const d = newDevices[existing];
if (d.connected.get()) {
throw new Error(
`Cannot unregister, '${d.serial}' as is still connected`,
);
}
newDevices.splice(existing, 1);
}

let selectedNewDevice: BaseDevice | null = null;
let selectedNewAppId: null | string = null;
if (newDevices.length > 0) {
selectedNewDevice = newDevices[0];
selectedNewAppId =
getAllClients(state).find((c) => c.device === selectedNewDevice)
?.id ?? null;
}

return {
...state,
devices: newDevices,
selectedDevice: selectedNewDevice,
selectedAppId: selectedNewAppId,
};
}

case 'SELECT_PLUGIN': {
const {selectedPlugin, selectedAppId, deepLinkPayload} = action.payload;

Expand Down

0 comments on commit b5f41df

Please sign in to comment.