archive disconnected Android devices

Summary:
Adding a `archive` method to Android devices, that returns a new ArchivedDevice with the same properties as the Android device. This method is called when an android device disconnects and the new ArchivedDevice is added to the devices list. When the device reconnects again, the archived device is removed.

Currently only logs are persisted. In following diffs we can:
- add support for iOS
- move the persisted pluginStates to the archived device as well

Reviewed By: passy

Differential Revision: D15942904

fbshipit-source-id: 07c5415994594abd630d0c4b458b76d1aac6ef02
This commit is contained in:
Daniel Büchele
2019-06-24 03:32:17 -07:00
committed by Facebook Github Bot
parent fdd75a123f
commit 74d7359cbe
5 changed files with 60 additions and 6 deletions

View File

@@ -158,6 +158,21 @@ export default (store: Store, logger: Logger) => {
name: androidDevice.title,
serial: androidDevice.serial,
});
// remove offline devices with same serial as the connected.
const reconnectedDevices = store
.getState()
.connections.devices.filter(
(device: BaseDevice) =>
device.serial === androidDevice.serial && device.isArchived,
)
.map(device => device.serial);
store.dispatch({
type: 'UNREGISTER_DEVICES',
payload: new Set(reconnectedDevices),
});
store.dispatch({
type: 'REGISTER_DEVICE',
payload: androidDevice,
@@ -178,10 +193,29 @@ export default (store: Store, logger: Logger) => {
serial: id,
}),
);
const archivedDevices = deviceIds
.map(id => {
const device = store
.getState()
.connections.devices.find(device => device.serial === id);
if (device && !device.isArchived) {
return device.archive();
}
})
.filter(Boolean);
store.dispatch({
type: 'UNREGISTER_DEVICES',
payload: new Set(deviceIds),
});
archivedDevices.forEach((payload: BaseDevice) =>
store.dispatch({
type: 'REGISTER_DEVICE',
payload,
}),
);
}
watchAndroidDevices();