Fixed issue with reseting logs

Summary:
Noticed that subsequent `adb logcat` invocations are stateful, and we didn't clear it's state when clearing the logs in memory.

This is a bandaid to get back to the previous behavior. I am wondering whether it wouldn't be just much more intuitive to always clear the logs (`adb logcat -c`) before we start the streaming log listener, so that users are never shown old logs from before flipper was connected?

Also fixed a leak in cleaning up the log listeners that was revealed by the possibility to disable the log plugin

Reviewed By: nikoant

Differential Revision: D26450262

fbshipit-source-id: 5b426e2d0e1fafdbc512d48d22b7bd4f30b61309
This commit is contained in:
Michel Weststrate
2021-02-17 08:17:37 -08:00
committed by Facebook GitHub Bot
parent d50c253159
commit d37f1c282a
3 changed files with 12 additions and 4 deletions

View File

@@ -76,7 +76,9 @@ export const LaunchEmulatorDialog = withTrackingScope(
}, [iosEnabled, getSimulators, store]); }, [iosEnabled, getSimulators, store]);
const items = [ const items = [
...(androidEmulators.length > 0 ? [<AndroidOutlined />] : []), ...(androidEmulators.length > 0
? [<AndroidOutlined key="android logo" />]
: []),
...androidEmulators.map((name) => { ...androidEmulators.map((name) => {
const launch = (coldBoot: boolean) => { const launch = (coldBoot: boolean) => {
launchEmulator(name, coldBoot) launchEmulator(name, coldBoot)
@@ -111,7 +113,7 @@ export const LaunchEmulatorDialog = withTrackingScope(
</Dropdown.Button> </Dropdown.Button>
); );
}), }),
...(iosEmulators.length > 0 ? [<AppleOutlined />] : []), ...(iosEmulators.length > 0 ? [<AppleOutlined key="ios logo" />] : []),
...iosEmulators.map((device) => ( ...iosEmulators.map((device) => (
<Button <Button
key={device.udid} key={device.udid}

View File

@@ -115,6 +115,7 @@ export abstract class BasePluginInstance {
importHandler?: StateImportHandler; importHandler?: StateImportHandler;
menuEntries: NormalizedMenuEntry[] = []; menuEntries: NormalizedMenuEntry[] = [];
logListeners: Symbol[] = [];
constructor( constructor(
flipperLib: FlipperLib, flipperLib: FlipperLib,
@@ -139,9 +140,9 @@ export abstract class BasePluginInstance {
return realDevice.connected.get(); return realDevice.connected.get();
}, },
deviceType: realDevice.deviceType, deviceType: realDevice.deviceType,
onLogEntry: (cb) => {
onLogEntry(cb) {
const handle = realDevice.addLogListener(cb); const handle = realDevice.addLogListener(cb);
this.logListeners.push(handle);
return () => { return () => {
realDevice.removeLogListener(handle); realDevice.removeLogListener(handle);
}; };
@@ -265,6 +266,9 @@ export abstract class BasePluginInstance {
destroy() { destroy() {
this.assertNotDestroyed(); this.assertNotDestroyed();
this.deactivate(); this.deactivate();
this.logListeners.splice(0).forEach((handle) => {
this.device.realDevice.removeLogListener(handle);
});
this.events.emit('destroy'); this.events.emit('destroy');
this.destroyed = true; this.destroyed = true;
} }

View File

@@ -497,6 +497,8 @@ export function devicePlugin(client: DevicePluginClient) {
} }
function clearLogs() { function clearLogs() {
// Non public Android specific api
(client.device.realDevice as any)?.clearLogs?.();
entries.set([]); entries.set([]);
rows.set([]); rows.set([]);
highlightedRows.set(new Set()); highlightedRows.set(new Set());