Save logs that are shown in logs plugin if persisted logging is enabled

Summary:
This is the second part of the feature which enables data/log persistence by adding a global setting which controls whether the data is wiped when the same device is disconnected and reconnected.

Building on the previous diff, this diff uses the setting from the Redux Store to determine whether to "wipe" the data or not.

Changelog: Added option in Flipper settings to persist device data upon reconnection instead of wiping everything.

Reviewed By: mweststrate

Differential Revision: D38076567

fbshipit-source-id: 83658ac09bc88921a56517e1a1f624d4a4bbc2c5
This commit is contained in:
Feiyu Wong
2022-07-28 13:56:34 -07:00
committed by Facebook GitHub Bot
parent 3ffb25e672
commit ab49b17c7b
2 changed files with 191 additions and 9 deletions

View File

@@ -72,12 +72,9 @@ export function connectFlipperServerToStore(
handleDeviceConnected(server, store, logger, deviceInfo);
});
server.on('device-disconnected', (device) => {
logger.track('usage', 'unregister-device', {
os: device.os,
serial: device.serial,
});
server.on('device-disconnected', (deviceInfo) => {
// N.B.: note that we don't remove the device, we keep it in offline
handleDeviceDisconnected(store, logger, deviceInfo);
});
server.on('client-setup', (client) => {
@@ -202,7 +199,7 @@ function handleServerStateChange({
}
}
function handleDeviceConnected(
export function handleDeviceConnected(
server: FlipperServer,
store: Store,
logger: Logger,
@@ -224,6 +221,15 @@ function handleDeviceConnected(
`Tried to replace still connected device '${existing.serial}' with a new instance.`,
);
}
if (store.getState().settingsState.persistDeviceData) {
//Recycle device
existing?.connected.set(true);
store.dispatch({
type: 'SELECT_DEVICE',
payload: existing,
});
return;
}
existing.destroy();
}
@@ -232,13 +238,27 @@ function handleDeviceConnected(
store.getState().plugins.devicePlugins,
store.getState().connections.enabledDevicePlugins,
);
store.dispatch({
type: 'REGISTER_DEVICE',
payload: device,
});
}
export function handleDeviceDisconnected(
store: Store,
logger: Logger,
deviceInfo: DeviceDescription,
) {
logger.track('usage', 'unregister-device', {
os: deviceInfo.os,
serial: deviceInfo.serial,
});
const existing = store
.getState()
.connections.devices.find((device) => device.serial === deviceInfo.serial);
existing?.connected.set(false);
}
export async function handleClientConnected(
server: FlipperServer,
store: Store,
@@ -247,7 +267,6 @@ export async function handleClientConnected(
) {
const {connections} = store.getState();
const existingClient = connections.clients.get(id);
if (existingClient) {
existingClient.destroy();
store.dispatch({