SonarPlugin > FlipperPlugin

Summary:
Renaming:
- `SonarPlugin` > `FlipperPlugin`
- `SonarBasePlugin` > `FlipperBasePlugin`
- `SonarDevicePlugin` > `FlipperDevicePlugin`

Reviewed By: passy

Differential Revision: D9851075

fbshipit-source-id: d59df6952a42eb493c86c38895216c9985f1e14b
This commit is contained in:
Daniel Büchele
2018-09-18 06:38:12 -07:00
committed by Facebook Github Bot
parent 47ec499973
commit 2e2924c979
17 changed files with 54 additions and 46 deletions

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import type {SonarPlugin} from './plugin.js'; import type {FlipperPlugin} from './plugin.js';
import type {App} from './App.js'; import type {App} from './App.js';
import type Logger from './fb-stubs/Logger.js'; import type Logger from './fb-stubs/Logger.js';
@@ -88,7 +88,7 @@ export default class Client extends EventEmitter {
|}, |},
>; >;
supportsPlugin(Plugin: Class<SonarPlugin<>>): boolean { supportsPlugin(Plugin: Class<FlipperPlugin<>>): boolean {
return this.plugins.includes(Plugin.id); return this.plugins.includes(Plugin.id);
} }

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import type {SonarBasePlugin} from './plugin.js'; import type {FlipperBasePlugin} from './plugin.js';
import {devicePlugins} from './device-plugins/index.js'; import {devicePlugins} from './device-plugins/index.js';
import plugins from './plugins/index.js'; import plugins from './plugins/index.js';
@@ -70,7 +70,7 @@ export function setupMenuBar() {
// collect all keyboard actions from all plugins // collect all keyboard actions from all plugins
const registeredActions: Set<?KeyboardAction> = new Set( const registeredActions: Set<?KeyboardAction> = new Set(
[...devicePlugins, ...plugins] [...devicePlugins, ...plugins]
.map((plugin: Class<SonarBasePlugin<>>) => plugin.keyboardActions || []) .map((plugin: Class<FlipperBasePlugin<>>) => plugin.keyboardActions || [])
.reduce((acc: KeyboardActions, cv) => acc.concat(cv), []) .reduce((acc: KeyboardActions, cv) => acc.concat(cv), [])
.map( .map(
(action: DefaultKeyboardAction | KeyboardAction) => (action: DefaultKeyboardAction | KeyboardAction) =>
@@ -133,7 +133,7 @@ function appendMenuItem(
} }
} }
export function activateMenuItems(activePlugin: SonarBasePlugin<>) { export function activateMenuItems(activePlugin: FlipperBasePlugin<>) {
// disable all keyboard actions // disable all keyboard actions
for (const item of menuItems) { for (const item of menuItems) {
item[1].enabled = false; item[1].enabled = false;

View File

@@ -4,13 +4,13 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* @format * @format
*/ */
import type {SonarPlugin, SonarBasePlugin} from './plugin.js'; import type {FlipperPlugin, FlipperBasePlugin} from './plugin.js';
import type LogManager from './fb-stubs/Logger'; import type LogManager from './fb-stubs/Logger';
import type Client from './Client.js'; import type Client from './Client.js';
import type BaseDevice from './devices/BaseDevice.js'; import type BaseDevice from './devices/BaseDevice.js';
import type {Props as PluginProps} from './plugin'; import type {Props as PluginProps} from './plugin';
import {SonarDevicePlugin} from './plugin.js'; import {FlipperDevicePlugin} from './plugin.js';
import { import {
ErrorBoundary, ErrorBoundary,
Component, Component,
@@ -55,7 +55,7 @@ type Props = {
}; };
type State = { type State = {
activePlugin: ?Class<SonarBasePlugin<>>, activePlugin: ?Class<FlipperBasePlugin<>>,
target: Client | BaseDevice | null, target: Client | BaseDevice | null,
pluginKey: string, pluginKey: string,
}; };
@@ -63,7 +63,7 @@ type State = {
function computeState(props: Props): State { function computeState(props: Props): State {
// plugin changed // plugin changed
let activePlugin = devicePlugins.find( let activePlugin = devicePlugins.find(
(p: Class<SonarDevicePlugin<>>) => p.id === props.selectedPlugin, (p: Class<FlipperDevicePlugin<>>) => p.id === props.selectedPlugin,
); );
let target = props.selectedDevice; let target = props.selectedDevice;
let pluginKey = 'unknown'; let pluginKey = 'unknown';
@@ -74,7 +74,7 @@ function computeState(props: Props): State {
(client: Client) => client.id === props.selectedApp, (client: Client) => client.id === props.selectedApp,
); );
activePlugin = plugins.find( activePlugin = plugins.find(
(p: Class<SonarPlugin<>>) => p.id === props.selectedPlugin, (p: Class<FlipperPlugin<>>) => p.id === props.selectedPlugin,
); );
if (!activePlugin || !target) { if (!activePlugin || !target) {
throw new Error( throw new Error(
@@ -92,7 +92,7 @@ function computeState(props: Props): State {
} }
class PluginContainer extends Component<Props, State> { class PluginContainer extends Component<Props, State> {
plugin: ?SonarBasePlugin<>; plugin: ?FlipperBasePlugin<>;
constructor(props: Props) { constructor(props: Props) {
super(); super();
@@ -109,7 +109,7 @@ class PluginContainer extends Component<Props, State> {
} }
} }
refChanged = (ref: ?SonarBasePlugin<>) => { refChanged = (ref: ?FlipperBasePlugin<>) => {
if (this.plugin) { if (this.plugin) {
this.plugin._teardown(); this.plugin._teardown();
this.plugin = null; this.plugin = null;

View File

@@ -6,9 +6,9 @@
*/ */
import type { import type {
SonarPlugin, FlipperPlugin,
SonarDevicePlugin, FlipperDevicePlugin,
SonarBasePlugin, FlipperBasePlugin,
} from '../plugin.js'; } from '../plugin.js';
import type BaseDevice from '../devices/BaseDevice.js'; import type BaseDevice from '../devices/BaseDevice.js';
import type Client from '../Client.js'; import type Client from '../Client.js';
@@ -97,7 +97,7 @@ function PluginIcon({
class PluginSidebarListItem extends Component<{ class PluginSidebarListItem extends Component<{
onClick: () => void, onClick: () => void,
isActive: boolean, isActive: boolean,
plugin: Class<SonarBasePlugin<>>, plugin: Class<FlipperBasePlugin<>>,
app?: ?string, app?: ?string,
}> { }> {
render() { render() {
@@ -185,7 +185,7 @@ class MainSidebar extends Component<MainSidebarProps> {
{selectedDevice && {selectedDevice &&
devicePlugins devicePlugins
.filter(selectedDevice.supportsPlugin) .filter(selectedDevice.supportsPlugin)
.map((plugin: Class<SonarDevicePlugin<>>) => ( .map((plugin: Class<FlipperDevicePlugin<>>) => (
<PluginSidebarListItem <PluginSidebarListItem
key={plugin.id} key={plugin.id}
isActive={plugin.id === selectedPlugin} isActive={plugin.id === selectedPlugin}
@@ -212,10 +212,10 @@ class MainSidebar extends Component<MainSidebarProps> {
<SidebarHeader>{client.query.app}</SidebarHeader> <SidebarHeader>{client.query.app}</SidebarHeader>
{plugins {plugins
.filter( .filter(
(p: Class<SonarPlugin<>>) => (p: Class<FlipperPlugin<>>) =>
client.plugins.indexOf(p.id) > -1, client.plugins.indexOf(p.id) > -1,
) )
.map((plugin: Class<SonarPlugin<>>) => ( .map((plugin: Class<FlipperPlugin<>>) => (
<PluginSidebarListItem <PluginSidebarListItem
key={plugin.id} key={plugin.id}
isActive={ isActive={

View File

@@ -14,7 +14,7 @@ import type {
import {FlexColumn, Button, SonarSidebar} from 'sonar'; import {FlexColumn, Button, SonarSidebar} from 'sonar';
import textContent from './utils/textContent.js'; import textContent from './utils/textContent.js';
import createPaste from './utils/createPaste.js'; import createPaste from './utils/createPaste.js';
import {SonarPlugin, SearchableTable} from 'sonar'; import {FlipperPlugin, SearchableTable} from 'sonar';
type ID = string; type ID = string;
@@ -58,7 +58,7 @@ type Actions<T> = AppendAndUpdateAction<T> | ResetAndUpdateAction<T>;
* the client in an unknown state. * the client in an unknown state.
*/ */
export function createTablePlugin<T: RowData>(props: Props<T>) { export function createTablePlugin<T: RowData>(props: Props<T>) {
return class extends SonarPlugin<State<T>, Actions<T>> { return class extends FlipperPlugin<State<T>, Actions<T>> {
static title = props.title; static title = props.title;
static id = props.id; static id = props.id;
static icon = props.icon; static icon = props.icon;

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import {SonarDevicePlugin} from 'sonar'; import {FlipperDevicePlugin} from 'sonar';
var adb = require('adbkit-fb'); var adb = require('adbkit-fb');
import { import {
@@ -98,7 +98,7 @@ function formatFrequency(freq) {
} }
} }
export default class CPUFrequencyTable extends SonarDevicePlugin<CPUState> { export default class CPUFrequencyTable extends FlipperDevicePlugin<CPUState> {
static id = 'DeviceCPU'; static id = 'DeviceCPU';
static title = 'CPU'; static title = 'CPU';
static icon = 'underline'; static icon = 'underline';

View File

@@ -5,13 +5,13 @@
* @format * @format
*/ */
import type {SonarDevicePlugin} from '../plugin.js'; import type {FlipperDevicePlugin} from '../plugin.js';
import {GK} from 'sonar'; import {GK} from 'sonar';
import logs from './logs/index.js'; import logs from './logs/index.js';
import cpu from './cpu/index.js'; import cpu from './cpu/index.js';
const plugins: Array<Class<SonarDevicePlugin<any>>> = [logs]; const plugins: Array<Class<FlipperDevicePlugin<any>>> = [logs];
if (GK.get('sonar_uiperf')) { if (GK.get('sonar_uiperf')) {
plugins.push(cpu); plugins.push(cpu);

View File

@@ -25,7 +25,7 @@ import {
FlexColumn, FlexColumn,
Glyph, Glyph,
SonarSidebar, SonarSidebar,
SonarDevicePlugin, FlipperDevicePlugin,
SearchableTable, SearchableTable,
styled, styled,
} from 'sonar'; } from 'sonar';
@@ -238,7 +238,7 @@ function pad(chunk: mixed, len: number): string {
return str; return str;
} }
export default class LogTable extends SonarDevicePlugin< export default class LogTable extends FlipperDevicePlugin<
State, State,
Actions, Actions,
PersistedState, PersistedState,

View File

@@ -6,7 +6,7 @@
*/ */
import type stream from 'stream'; import type stream from 'stream';
import {SonarDevicePlugin} from 'sonar'; import {FlipperDevicePlugin} from 'sonar';
export type LogLevel = export type LogLevel =
| 'unknown' | 'unknown'
@@ -69,7 +69,7 @@ export default class BaseDevice {
return os.toLowerCase() === this.os.toLowerCase(); return os.toLowerCase() === this.os.toLowerCase();
} }
supportsPlugin = (DevicePlugin: Class<SonarDevicePlugin<>>): boolean => { supportsPlugin = (DevicePlugin: Class<FlipperDevicePlugin<>>): boolean => {
return this.supportedPlugins.includes(DevicePlugin.id); return this.supportedPlugins.includes(DevicePlugin.id);
}; };

View File

@@ -10,7 +10,11 @@ export * from './ui/index.js';
export * from './utils/index.js'; export * from './utils/index.js';
export {default as GK} from './fb-stubs/GK.js'; export {default as GK} from './fb-stubs/GK.js';
export {SonarBasePlugin, SonarPlugin, SonarDevicePlugin} from './plugin.js'; export {
FlipperBasePlugin,
FlipperPlugin,
FlipperDevicePlugin,
} from './plugin.js';
export {createTablePlugin} from './createTablePlugin.js'; export {createTablePlugin} from './createTablePlugin.js';
export {default as SonarSidebar} from './chrome/SonarSidebar.js'; export {default as SonarSidebar} from './chrome/SonarSidebar.js';

View File

@@ -31,7 +31,7 @@ export type Props<T> = {
target: PluginTarget, target: PluginTarget,
}; };
export class SonarBasePlugin< export class FlipperBasePlugin<
State = *, State = *,
Actions = *, Actions = *,
PersistedState = *, PersistedState = *,
@@ -84,7 +84,7 @@ export class SonarBasePlugin<
} }
} }
export class SonarDevicePlugin<S = *, A = *, P = *> extends SonarBasePlugin< export class FlipperDevicePlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
S, S,
A, A,
P, P,
@@ -101,7 +101,11 @@ export class SonarDevicePlugin<S = *, A = *, P = *> extends SonarBasePlugin<
} }
} }
export class SonarPlugin<S = *, A = *, P = *> extends SonarBasePlugin<S, A, P> { export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
S,
A,
P,
> {
constructor(props: Props<*>) { constructor(props: Props<*>) {
super(props); super(props);
const {id} = this.constructor; const {id} = this.constructor;

View File

@@ -9,7 +9,7 @@ import {GK} from 'sonar';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import * as Sonar from 'sonar'; import * as Sonar from 'sonar';
import {SonarPlugin, SonarBasePlugin} from '../plugin.js'; import {FlipperPlugin, FlipperBasePlugin} from '../plugin.js';
import {remote} from 'electron'; import {remote} from 'electron';
const plugins = new Map(); const plugins = new Map();
@@ -54,7 +54,7 @@ bundledPlugins
})) }))
.forEach(addIfNotAdded); .forEach(addIfNotAdded);
const exportedPlugins: Array<Class<SonarPlugin<>>> = Array.from( const exportedPlugins: Array<Class<FlipperPlugin<>>> = Array.from(
plugins.values(), plugins.values(),
) )
.map(plugin => { .map(plugin => {
@@ -78,7 +78,7 @@ const exportedPlugins: Array<Class<SonarPlugin<>>> = Array.from(
} }
}) })
.filter(Boolean) .filter(Boolean)
.filter(plugin => plugin.prototype instanceof SonarBasePlugin) .filter(plugin => plugin.prototype instanceof FlipperBasePlugin)
.sort((a, b) => (a.title || '').localeCompare(b.title || '')); .sort((a, b) => (a.title || '').localeCompare(b.title || ''));
export default exportedPlugins; export default exportedPlugins;

View File

@@ -12,7 +12,7 @@ import {
FlexRow, FlexRow,
FlexColumn, FlexColumn,
Toolbar, Toolbar,
SonarPlugin, FlipperPlugin,
ElementsInspector, ElementsInspector,
InspectorSidebar, InspectorSidebar,
LoadingIndicator, LoadingIndicator,
@@ -186,7 +186,7 @@ class LayoutSearchInput extends Component<
} }
} }
export default class Layout extends SonarPlugin<InspectorState> { export default class Layout extends FlipperPlugin<InspectorState> {
static title = 'Layout'; static title = 'Layout';
static id = 'Inspector'; static id = 'Inspector';
static icon = 'target'; static icon = 'target';

View File

@@ -14,7 +14,7 @@ import {
Sidebar, Sidebar,
Toolbar, Toolbar,
Checkbox, Checkbox,
SonarPlugin, FlipperPlugin,
Button, Button,
styled, styled,
} from 'sonar'; } from 'sonar';
@@ -53,7 +53,7 @@ const ToolbarItem = styled(FlexRow)({
marginLeft: '8px', marginLeft: '8px',
}); });
export default class LeakCanary extends SonarPlugin<State> { export default class LeakCanary extends FlipperPlugin<State> {
static title = 'LeakCanary'; static title = 'LeakCanary';
static id = 'LeakCanary'; static id = 'LeakCanary';
static icon = 'bird'; static icon = 'bird';

View File

@@ -18,7 +18,7 @@ import {
SonarSidebar, SonarSidebar,
styled, styled,
} from 'sonar'; } from 'sonar';
import {SonarPlugin, SearchableTable} from 'sonar'; import {FlipperPlugin, SearchableTable} from 'sonar';
import RequestDetails from './RequestDetails.js'; import RequestDetails from './RequestDetails.js';
import {URL} from 'url'; import {URL} from 'url';
@@ -109,7 +109,7 @@ const TextEllipsis = styled(Text)({
paddingTop: 4, paddingTop: 4,
}); });
export default class extends SonarPlugin<State, *, PersistedState> { export default class extends FlipperPlugin<State, *, PersistedState> {
static title = 'Network'; static title = 'Network';
static id = 'Network'; static id = 'Network';
static icon = 'internet'; static icon = 'internet';

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import {SonarPlugin} from 'sonar'; import {FlipperPlugin} from 'sonar';
import {FlexColumn} from 'sonar'; import {FlexColumn} from 'sonar';
import {ButtonGroup, Button, styled, colors} from 'sonar'; import {ButtonGroup, Button, styled, colors} from 'sonar';
@@ -31,7 +31,7 @@ const ButtonContainer = styled(FlexColumn)({
padding: 20, padding: 20,
}); });
export default class SandboxView extends SonarPlugin<SandboxState> { export default class SandboxView extends FlipperPlugin<SandboxState> {
state = { state = {
sandboxes: [], sandboxes: [],
customSandbox: '', customSandbox: '',

View File

@@ -15,7 +15,7 @@ import {
DataInspector, DataInspector,
styled, styled,
} from 'sonar'; } from 'sonar';
import {SonarPlugin} from 'sonar'; import {FlipperPlugin} from 'sonar';
const {clone} = require('lodash'); const {clone} = require('lodash');
@@ -66,7 +66,7 @@ const ChangelogColumn = styled(FlexColumn)({
padding: '16px', padding: '16px',
}); });
export default class extends SonarPlugin<SharedPreferencesState> { export default class extends FlipperPlugin<SharedPreferencesState> {
static title = 'Shared Preferences Viewer'; static title = 'Shared Preferences Viewer';
static id = 'Preferences'; static id = 'Preferences';