Make crash reporter plugin device only

Summary: Makes a crash reporter plugin as a device plugin

Reviewed By: passy

Differential Revision: D13203954

fbshipit-source-id: 02ef2aff05d5a240eaff588f9b515d3d610fc182
This commit is contained in:
Pritesh Nandgaonkar
2018-11-29 06:57:22 -08:00
committed by Facebook Github Bot
parent 7ffdb36cc5
commit 14431e6b76
5 changed files with 35 additions and 22 deletions

View File

@@ -5,7 +5,7 @@
* @format
*/
import type {FlipperPlugin} from './plugin.js';
import type {FlipperPlugin, FlipperBasePlugin} from './plugin.js';
import type {App} from './App.js';
import type Logger from './fb-stubs/Logger.js';
import type {Store} from './reducers/index.js';
@@ -153,10 +153,9 @@ export default class Client extends EventEmitter {
const params = data.params;
invariant(params, 'expected params');
const persistingPlugin: ?Class<
FlipperPlugin<>,
> = this.store.getState().plugins.clientPlugins.get(params.api);
const persistingPlugin: ?Class<FlipperBasePlugin<>> =
this.store.getState().plugins.clientPlugins.get(params.api) ||
this.store.getState().plugins.devicePlugins.get(params.api);
if (persistingPlugin && persistingPlugin.persistedStateReducer) {
const pluginKey = `${this.id}#${params.api}`;
const persistedState = {

View File

@@ -8,7 +8,7 @@
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {PluginNotification} from '../reducers/notifications';
import type {FlipperPlugin} from '../plugin.js';
import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js';
import {ipcRenderer} from 'electron';
import {selectPlugin} from '../reducers/connections';
@@ -82,7 +82,20 @@ export default (store: Store, logger: Logger) => {
store.subscribe(() => {
const {notifications, pluginStates} = store.getState();
const pluginMap = store.getState().plugins.clientPlugins;
const clientPlugins: Map<string, Class<FlipperPlugin<>>> = store.getState()
.plugins.clientPlugins;
const devicePlugins: Map<
string,
Class<FlipperDevicePlugin<>>,
> = store.getState().plugins.devicePlugins;
const pluginMap: Map<
string,
Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
//$FlowFixMe Flow complains that FlipperPlugin and FlipperDevicePlugin are incompatible, where as we have already mentioned the type of the class it can take in the type
> = new Map([...clientPlugins, ...devicePlugins]);
Object.keys(pluginStates).forEach(key => {
if (knownPluginStates.get(key) !== pluginStates[key]) {
@@ -90,10 +103,9 @@ export default (store: Store, logger: Logger) => {
const split = key.split('#');
const pluginId = split.pop();
const client = split.join('#');
const persistingPlugin: ?Class<FlipperPlugin<>> = pluginMap.get(
pluginId,
);
const persistingPlugin: ?Class<
FlipperPlugin<> | FlipperDevicePlugin<>,
> = pluginMap.get(pluginId);
if (persistingPlugin && persistingPlugin.getActiveNotifications) {
store.dispatch(
setActiveNotifications({

View File

@@ -8,7 +8,6 @@
export {default as styled} from 'react-emotion';
export * from './ui/index.js';
export * from './utils/index.js';
export {default as GK} from './fb-stubs/GK.js';
export {
FlipperBasePlugin,

View File

@@ -55,7 +55,14 @@ export class FlipperBasePlugin<
static keyboardActions: ?KeyboardActions;
static screenshot: ?string;
static defaultPersistedState: PersistedState;
static persistedStateReducer: ?(
persistedState: PersistedState,
method: string,
data: Object,
) => $Shape<PersistedState>;
static getActiveNotifications: ?(
persistedState: PersistedState,
) => Array<Notification>;
// forbid instance properties that should be static
title: empty;
id: empty;
@@ -129,13 +136,6 @@ export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
A,
P,
> {
static persistedStateReducer: ?(
persistedState: P,
method: string,
data: Object,
) => $Shape<P>;
static getActiveNotifications: ?(persistedState: P) => Array<Notification>;
constructor(props: Props<*>) {
super(props);
const {id} = this.constructor;

View File

@@ -6,7 +6,7 @@
* @flow
*/
import {FlipperPlugin} from 'flipper';
import {FlipperDevicePlugin, Device} from 'flipper';
import type {Notification} from '../../plugin';
type Crash = {|
@@ -19,7 +19,7 @@ type PersistedState = {|
crashes: Array<Crash>,
|};
export default class extends FlipperPlugin {
export default class CrashReporterPlugin extends FlipperDevicePlugin {
static title = 'Crash Reporter';
static id = 'CrashReporter';
static icon = 'apps';
@@ -28,6 +28,9 @@ export default class extends FlipperPlugin {
crashes: [],
};
static supportsDevice(device: Device) {
return device.os === 'iOS' || device.os === 'Android';
}
/*
* Reducer to process incoming "send" messages from the mobile counterpart.
*/