diff --git a/src/Client.js b/src/Client.js index 29cb48fd1..4d2b11674 100644 --- a/src/Client.js +++ b/src/Client.js @@ -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> = + 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 = { diff --git a/src/dispatcher/notifications.js b/src/dispatcher/notifications.js index 5091174e1..8579fb15e 100644 --- a/src/dispatcher/notifications.js +++ b/src/dispatcher/notifications.js @@ -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>> = store.getState() + .plugins.clientPlugins; + + const devicePlugins: Map< + string, + Class>, + > = store.getState().plugins.devicePlugins; + + const pluginMap: Map< + string, + Class | 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> = pluginMap.get( - pluginId, - ); - + const persistingPlugin: ?Class< + FlipperPlugin<> | FlipperDevicePlugin<>, + > = pluginMap.get(pluginId); if (persistingPlugin && persistingPlugin.getActiveNotifications) { store.dispatch( setActiveNotifications({ diff --git a/src/index.js b/src/index.js index 7c04c8dda..9e9171204 100644 --- a/src/index.js +++ b/src/index.js @@ -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, diff --git a/src/plugin.js b/src/plugin.js index 02679c2aa..3e803a7cd 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -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; + static getActiveNotifications: ?( + persistedState: PersistedState, + ) => Array; // forbid instance properties that should be static title: empty; id: empty; @@ -129,13 +136,6 @@ export class FlipperPlugin extends FlipperBasePlugin< A, P, > { - static persistedStateReducer: ?( - persistedState: P, - method: string, - data: Object, - ) => $Shape

; - static getActiveNotifications: ?(persistedState: P) => Array; - constructor(props: Props<*>) { super(props); const {id} = this.constructor; diff --git a/src/plugins/crash_reporter/index.js b/src/plugins/crash_reporter/index.js index f85f48c35..1b05e5ae1 100644 --- a/src/plugins/crash_reporter/index.js +++ b/src/plugins/crash_reporter/index.js @@ -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, |}; -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. */