Crash reporter plugin

Summary: This diff adds a static function `onRegisterDevice` which is being called whenever an  device gets registered. This callback is used to add loglisterner for android. I even moved the logic of iOS from `onRegisterPlugin` to this callback. The reason for not adding android log listener in `onRegisterPlugin` was that there were cases when baseDevice was not yet registered before calling `onRegisterPlugin`. For android, I want the instance of `BaseDevice` so that I can add logListener on it.

Reviewed By: danielbuechele

Differential Revision: D13563282

fbshipit-source-id: b5be40f3dbc808bdaeabae28423c563cf2345a22
This commit is contained in:
Pritesh Nandgaonkar
2019-01-09 10:40:22 -08:00
committed by Facebook Github Bot
parent c6efea991d
commit 0048fc6e4a
7 changed files with 109 additions and 38 deletions

View File

@@ -0,0 +1,44 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import type {Store} from '../reducers/index.js';
import {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js';
import type BaseDevice from '../devices/BaseDevice.js';
import {setPluginState} from '../reducers/pluginStates.js';
import {getPersistedState} from '../utils/pluginUtils.js';
export function registerDeviceCallbackOnPlugins(
store: Store,
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
clientPlugins: Map<string, Class<FlipperPlugin<>>>,
device: BaseDevice,
) {
const callRegisterDeviceHook = plugin => {
if (plugin.onRegisterDevice) {
plugin.onRegisterDevice(
store,
device,
(pluginKey: string, newPluginState: any) => {
const persistedState = getPersistedState(
pluginKey,
plugin,
store.getState().pluginStates,
);
if (newPluginState && newPluginState !== persistedState) {
store.dispatch(
setPluginState({
pluginKey,
state: newPluginState,
}),
);
}
},
);
}
};
devicePlugins.forEach(callRegisterDeviceHook);
clientPlugins.forEach(callRegisterDeviceHook);
}