Introduce DevicePlugin APIs
Summary: This stack introduces Sandy device plugins, they are quite similar to normal plugins, but, a devicePlugin module is organized as ``` export function supportsDevice(device): boolean export function devicePlugin(devicePluginClient) export function Component ``` Device plugins get access to the device meta data and can subscribe to the `onLogEntry` callback and `onDestroy` lifecycle. They will be able to store state just as normal plugins, but can't send or receive methods, so devicePluginClient is a bit limited. This diff only sets up most of the new data structures, and makes sure everything still compiles and no existing tests fail. To prevent this diff from becoming to big, actually loading, rendering and testing device plugins will be done in next diffs Please take a critical look at the api proposed and the (especially) the public names used :) Reviewed By: passy, nikoant Differential Revision: D22691351 fbshipit-source-id: bdbbd7f86d14b646fc9a693ad19f33583a76f26d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6083534025
commit
91ed4e31c0
@@ -7,11 +7,12 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import BaseDevice, {DeviceType, LogLevel} from './BaseDevice';
|
||||
import BaseDevice, {DeviceType} from './BaseDevice';
|
||||
import adb, {Client as ADBClient} from 'adbkit';
|
||||
import {Priority} from 'adbkit-logcat';
|
||||
import ArchivedDevice from './ArchivedDevice';
|
||||
import {createWriteStream} from 'fs';
|
||||
import {LogLevel} from 'flipper-plugin';
|
||||
|
||||
const DEVICE_RECORDING_DIR = '/sdcard/flipper_recorder';
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {DeviceLogEntry} from 'flipper-plugin';
|
||||
import BaseDevice from './BaseDevice';
|
||||
import {DeviceType, OS, DeviceShell, DeviceLogEntry} from './BaseDevice';
|
||||
import {DeviceType, OS, DeviceShell} from './BaseDevice';
|
||||
import {SupportFormRequestDetailsState} from '../reducers/supportForm';
|
||||
|
||||
function normalizeArchivedDeviceType(deviceType: DeviceType): DeviceType {
|
||||
|
||||
@@ -8,27 +8,9 @@
|
||||
*/
|
||||
|
||||
import stream from 'stream';
|
||||
import {FlipperDevicePlugin} from 'flipper';
|
||||
import {FlipperDevicePlugin, DeviceLogListener} from 'flipper';
|
||||
import {sortPluginsByName} from '../utils/pluginUtils';
|
||||
|
||||
export type LogLevel =
|
||||
| 'unknown'
|
||||
| 'verbose'
|
||||
| 'debug'
|
||||
| 'info'
|
||||
| 'warn'
|
||||
| 'error'
|
||||
| 'fatal';
|
||||
|
||||
export type DeviceLogEntry = {
|
||||
readonly date: Date;
|
||||
readonly pid: number;
|
||||
readonly tid: number;
|
||||
readonly app?: string;
|
||||
readonly type: LogLevel;
|
||||
readonly tag: string;
|
||||
readonly message: string;
|
||||
};
|
||||
import {DeviceLogEntry} from 'flipper-plugin';
|
||||
|
||||
export type DeviceShell = {
|
||||
stdout: stream.Readable;
|
||||
@@ -36,8 +18,6 @@ export type DeviceShell = {
|
||||
stdin: stream.Writable;
|
||||
};
|
||||
|
||||
export type DeviceLogListener = (entry: DeviceLogEntry) => void;
|
||||
|
||||
export type DeviceType =
|
||||
| 'emulator'
|
||||
| 'physical'
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {DeviceType, LogLevel, DeviceLogEntry} from './BaseDevice';
|
||||
import {LogLevel, DeviceLogEntry} from 'flipper-plugin';
|
||||
import {DeviceType} from './BaseDevice';
|
||||
import child_process, {ChildProcess} from 'child_process';
|
||||
import BaseDevice from './BaseDevice';
|
||||
import JSONStream from 'JSONStream';
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import BaseDevice, {LogLevel} from './BaseDevice';
|
||||
import {LogLevel} from 'flipper-plugin';
|
||||
import BaseDevice from './BaseDevice';
|
||||
import ArchivedDevice from './ArchivedDevice';
|
||||
import {EventEmitter} from 'events';
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ test('requirePlugin loads valid Sandy plugin', () => {
|
||||
});
|
||||
expect(typeof plugin.module.Component).toBe('function');
|
||||
expect(plugin.module.Component.displayName).toBe('FlipperPlugin(Sample)');
|
||||
expect(typeof plugin.module.plugin).toBe('function');
|
||||
expect(typeof plugin.asPluginModule().plugin).toBe('function');
|
||||
});
|
||||
|
||||
test('requirePlugin errors on invalid Sandy plugin', () => {
|
||||
|
||||
@@ -44,11 +44,7 @@ export {getPluginKey, getPersistedState} from './utils/pluginUtils';
|
||||
export {Idler} from './utils/Idler';
|
||||
export {Store, MiddlewareAPI, State as ReduxState} from './reducers/index';
|
||||
export {default as BaseDevice} from './devices/BaseDevice';
|
||||
export {
|
||||
DeviceLogListener,
|
||||
DeviceLogEntry,
|
||||
LogLevel,
|
||||
} from './devices/BaseDevice';
|
||||
export {DeviceLogEntry, LogLevel, DeviceLogListener} from 'flipper-plugin';
|
||||
export {shouldParseAndroidLog} from './utils/crashReporterUtility';
|
||||
export {default as isProduction} from './utils/isProduction';
|
||||
export {createTablePlugin} from './createTablePlugin';
|
||||
|
||||
@@ -101,7 +101,7 @@ test('it should initialize starred sandy plugins', async () => {
|
||||
test('it should cleanup a plugin if disabled', async () => {
|
||||
const {client, store} = await createMockFlipperWithPlugin(TestPlugin);
|
||||
|
||||
expect(TestPlugin.module.plugin).toBeCalledTimes(1);
|
||||
expect(TestPlugin.asPluginModule().plugin).toBeCalledTimes(1);
|
||||
const pluginInstance: PluginApi = client.sandyPluginStates.get(TestPlugin.id)!
|
||||
.instanceApi;
|
||||
expect(pluginInstance.destroyStub).toHaveBeenCalledTimes(0);
|
||||
@@ -150,7 +150,7 @@ test('it should not initialize a sandy plugin if not enabled', async () => {
|
||||
await client.refreshPlugins();
|
||||
// not yet enabled, so not yet started
|
||||
expect(client.sandyPluginStates.get(Plugin2.id)).toBeUndefined();
|
||||
expect(Plugin2.module.plugin).toBeCalledTimes(0);
|
||||
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(0);
|
||||
|
||||
store.dispatch(
|
||||
starPlugin({
|
||||
@@ -166,8 +166,8 @@ test('it should not initialize a sandy plugin if not enabled', async () => {
|
||||
.instanceApi as PluginApi;
|
||||
expect(client.sandyPluginStates.get(TestPlugin.id)).toBe(pluginState1); // not reinitialized
|
||||
|
||||
expect(TestPlugin.module.plugin).toBeCalledTimes(1);
|
||||
expect(Plugin2.module.plugin).toBeCalledTimes(1);
|
||||
expect(TestPlugin.asPluginModule().plugin).toBeCalledTimes(1);
|
||||
expect(Plugin2.asPluginModule().plugin).toBeCalledTimes(1);
|
||||
expect(instance.destroyStub).toHaveBeenCalledTimes(0);
|
||||
|
||||
// disable plugin again
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import {DeviceLogEntry} from '../devices/BaseDevice';
|
||||
import {DeviceLogEntry} from 'flipper-plugin';
|
||||
|
||||
export function shouldParseAndroidLog(
|
||||
entry: DeviceLogEntry,
|
||||
|
||||
Reference in New Issue
Block a user