Make Client initialize server add-ons
Reviewed By: mweststrate Differential Revision: D34044353 fbshipit-source-id: 99bcb1559787b2a904bdd796233666a7a4783ea4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a60865f0be
commit
9113006851
@@ -12,7 +12,7 @@
|
||||
|
||||
import {PluginDefinition} from './plugin';
|
||||
import BaseDevice from './devices/BaseDevice';
|
||||
import {Logger} from 'flipper-common';
|
||||
import {Logger, FlipperServer, ServerAddOnControls} from 'flipper-common';
|
||||
import {Store} from './reducers/index';
|
||||
import {
|
||||
reportPluginFailures,
|
||||
@@ -46,6 +46,7 @@ import {
|
||||
registerFlipperDebugMessage,
|
||||
} from './chrome/FlipperMessages';
|
||||
import {waitFor} from './utils/waitFor';
|
||||
import {createServerAddOnControls} from './utils/createServerAddOnControls';
|
||||
|
||||
type Plugins = Set<string>;
|
||||
type PluginsArr = Array<string>;
|
||||
@@ -124,6 +125,8 @@ export default class Client extends EventEmitter {
|
||||
}
|
||||
> = {};
|
||||
sandyPluginStates = new Map<string /*pluginID*/, _SandyPluginInstance>();
|
||||
private readonly serverAddOnControls: ServerAddOnControls;
|
||||
private readonly flipperServer: Pick<FlipperServer, 'exec'>;
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
@@ -133,6 +136,7 @@ export default class Client extends EventEmitter {
|
||||
store: Store,
|
||||
plugins: Plugins | null | undefined,
|
||||
device: BaseDevice,
|
||||
flipperServer: Pick<FlipperServer, 'exec'>,
|
||||
) {
|
||||
super();
|
||||
this.connected.set(!!conn);
|
||||
@@ -148,6 +152,8 @@ export default class Client extends EventEmitter {
|
||||
this.broadcastCallbacks = new Map();
|
||||
this.activePlugins = new Set();
|
||||
this.device = device;
|
||||
this.flipperServer = flipperServer;
|
||||
this.serverAddOnControls = createServerAddOnControls(this.flipperServer);
|
||||
}
|
||||
|
||||
supportsPlugin(pluginId: string): boolean {
|
||||
@@ -218,6 +224,7 @@ export default class Client extends EventEmitter {
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyPluginInstance(
|
||||
this.serverAddOnControls,
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
|
||||
@@ -198,6 +198,7 @@ export default class MockFlipper {
|
||||
this._store,
|
||||
new Set(supportedPlugins),
|
||||
device,
|
||||
this.flipperServer,
|
||||
);
|
||||
client.rawCall = async (
|
||||
method: string,
|
||||
|
||||
@@ -24,10 +24,12 @@ import {
|
||||
DeviceDescription,
|
||||
FlipperServer,
|
||||
CrashLog,
|
||||
ServerAddOnControls,
|
||||
} from 'flipper-common';
|
||||
import {DeviceSpec, PluginDetails} from 'flipper-common';
|
||||
import {getPluginKey} from '../utils/pluginKey';
|
||||
import {Base64} from 'js-base64';
|
||||
import {createServerAddOnControls} from '../utils/createServerAddOnControls';
|
||||
|
||||
type PluginDefinition = _SandyPluginDefinition;
|
||||
type PluginMap = Map<string, PluginDefinition>;
|
||||
@@ -45,10 +47,12 @@ export default class BaseDevice implements Device {
|
||||
flipperServer: FlipperServer;
|
||||
isArchived = false;
|
||||
hasDevicePlugins = false; // true if there are device plugins for this device (not necessarily enabled)
|
||||
private readonly serverAddOnControls: ServerAddOnControls;
|
||||
|
||||
constructor(flipperServer: FlipperServer, description: DeviceDescription) {
|
||||
this.flipperServer = flipperServer;
|
||||
this.description = description;
|
||||
this.serverAddOnControls = createServerAddOnControls(this.flipperServer);
|
||||
}
|
||||
|
||||
get isConnected(): boolean {
|
||||
@@ -349,6 +353,7 @@ export default class BaseDevice implements Device {
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyDevicePluginInstance(
|
||||
this.serverAddOnControls,
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
|
||||
@@ -301,6 +301,7 @@ export async function handleClientConnected(
|
||||
store,
|
||||
undefined,
|
||||
device,
|
||||
server,
|
||||
);
|
||||
|
||||
console.debug(
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
import {selectPlugin, getAllClients} from '../../reducers/connections';
|
||||
import {TestIdler} from '../Idler';
|
||||
import {TestDevice} from '../../devices/TestDevice';
|
||||
import {FlipperServer} from 'flipper-common';
|
||||
|
||||
const testIdler = new TestIdler();
|
||||
|
||||
@@ -65,6 +66,14 @@ const logger = {
|
||||
};
|
||||
const mockStore = configureStore<State, {}>([])();
|
||||
|
||||
const flipperServer = {
|
||||
connect: async () => {},
|
||||
on: () => {},
|
||||
off: () => {},
|
||||
close: () => {},
|
||||
exec: () => {},
|
||||
} as FlipperServer;
|
||||
|
||||
function generateNotifications(
|
||||
id: string,
|
||||
title: string,
|
||||
@@ -725,6 +734,7 @@ test('test determinePluginsToProcess for mutilple clients having plugins present
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client2 = new Client(
|
||||
generateClientIdentifier(device1, 'app2'),
|
||||
@@ -739,6 +749,7 @@ test('test determinePluginsToProcess for mutilple clients having plugins present
|
||||
mockStore,
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client3 = new Client(
|
||||
generateClientIdentifier(device1, 'app3'),
|
||||
@@ -753,6 +764,7 @@ test('test determinePluginsToProcess for mutilple clients having plugins present
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
clientPlugins: new Map([
|
||||
@@ -812,6 +824,7 @@ test('test determinePluginsToProcess for no selected plugin present in any clien
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client2 = new Client(
|
||||
generateClientIdentifier(device1, 'app2'),
|
||||
@@ -826,6 +839,7 @@ test('test determinePluginsToProcess for no selected plugin present in any clien
|
||||
mockStore,
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
clientPlugins: new Map([
|
||||
@@ -868,6 +882,7 @@ test('test determinePluginsToProcess for multiple clients on same device', async
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client2 = new Client(
|
||||
generateClientIdentifier(device1, 'app2'),
|
||||
@@ -882,6 +897,7 @@ test('test determinePluginsToProcess for multiple clients on same device', async
|
||||
mockStore,
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
clientPlugins: new Map([['TestPlugin', TestPlugin]]),
|
||||
@@ -929,6 +945,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client2Device1 = new Client(
|
||||
generateClientIdentifier(device1, 'app2'),
|
||||
@@ -943,6 +960,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
mockStore,
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client1Device2 = new Client(
|
||||
generateClientIdentifier(device2, 'app'),
|
||||
@@ -957,6 +975,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const client2Device2 = new Client(
|
||||
generateClientIdentifier(device2, 'app2'),
|
||||
@@ -971,6 +990,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
mockStore,
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
flipperServer,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
clientPlugins: new Map([['TestPlugin', TestPlugin]]),
|
||||
@@ -1042,6 +1062,7 @@ test('test determinePluginsToProcess to ignore archived clients', async () => {
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
archivedDevice,
|
||||
flipperServer,
|
||||
);
|
||||
const archivedClient = new Client(
|
||||
generateClientIdentifier(archivedDevice, 'app'),
|
||||
@@ -1056,6 +1077,7 @@ test('test determinePluginsToProcess to ignore archived clients', async () => {
|
||||
mockStore,
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
archivedDevice,
|
||||
flipperServer,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
clientPlugins: new Map([['TestPlugin', TestPlugin]]),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {FlipperServer, ServerAddOnControls} from 'flipper-common';
|
||||
|
||||
export const createServerAddOnControls = (
|
||||
flipperServer: Pick<FlipperServer, 'exec'>,
|
||||
): ServerAddOnControls => ({
|
||||
start: (pluginName) =>
|
||||
flipperServer.exec('plugins-server-add-on-start', pluginName),
|
||||
stop: (pluginName) =>
|
||||
flipperServer.exec('plugins-server-add-on-stop', pluginName),
|
||||
});
|
||||
@@ -575,6 +575,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
||||
store,
|
||||
clientPlugins,
|
||||
archivedDevice,
|
||||
getRenderHostInstance().flipperServer,
|
||||
).initFromImport(sandyPluginStates),
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user