Install plugin from marketplace if not available
Summary: For the Flipper Server Companion, if a plugin is being requested which is not yet installed, try to install it first from the marketplace. Reviewed By: passy Differential Revision: D37716962 fbshipit-source-id: d618fbc597f82b540dbb02e8ffc296dcee9e1eb9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c91c766b12
commit
18854ce5fc
@@ -21,6 +21,7 @@ import {BaseDevice} from 'flipper-frontend-core';
|
|||||||
import {_SandyPluginDefinition} from 'flipper-plugin';
|
import {_SandyPluginDefinition} from 'flipper-plugin';
|
||||||
import {isAtom} from 'flipper-plugin';
|
import {isAtom} from 'flipper-plugin';
|
||||||
import {HeadlessClient} from './HeadlessClient';
|
import {HeadlessClient} from './HeadlessClient';
|
||||||
|
import {FlipperServerCompanionEnv} from './init';
|
||||||
|
|
||||||
const companionEvents: Array<keyof FlipperCompanionEvents> = [
|
const companionEvents: Array<keyof FlipperCompanionEvents> = [
|
||||||
'companion-plugin-state-update',
|
'companion-plugin-state-update',
|
||||||
@@ -48,8 +49,9 @@ export class FlipperServerCompanion {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly flipperServer: FlipperServer,
|
private readonly flipperServer: FlipperServer,
|
||||||
private readonly logger: Logger,
|
private readonly logger: Logger,
|
||||||
loadablePluginsArr: ReadonlyArray<_SandyPluginDefinition>,
|
private readonly env: FlipperServerCompanionEnv,
|
||||||
) {
|
) {
|
||||||
|
const loadablePluginsArr = env.pluginInitializer.initialPlugins;
|
||||||
for (const loadablePlugin of loadablePluginsArr) {
|
for (const loadablePlugin of loadablePluginsArr) {
|
||||||
this.loadablePlugins.set(loadablePlugin.id, loadablePlugin);
|
this.loadablePlugins.set(loadablePlugin.id, loadablePlugin);
|
||||||
}
|
}
|
||||||
@@ -176,6 +178,30 @@ export class FlipperServerCompanion {
|
|||||||
return newDevice;
|
return newDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async loadPluginIfNeeded(pluginId: string) {
|
||||||
|
if (!this.loadablePlugins.has(pluginId)) {
|
||||||
|
console.info(
|
||||||
|
'FlipperServerCompanion.loadPluginIfNeeded -> plugin not found, attempt to install from marketplace',
|
||||||
|
);
|
||||||
|
|
||||||
|
const plugin = await this.flipperServer.exec(
|
||||||
|
'plugins-install-from-marketplace',
|
||||||
|
pluginId,
|
||||||
|
);
|
||||||
|
if (plugin) {
|
||||||
|
const sandyPlugin = await this.env.pluginInitializer.installPlugin(
|
||||||
|
plugin,
|
||||||
|
);
|
||||||
|
if (sandyPlugin) {
|
||||||
|
console.info(
|
||||||
|
'FlipperServerCompanion.loadPluginIfNeeded -> plugin successfully installed',
|
||||||
|
);
|
||||||
|
this.loadablePlugins.set(pluginId, sandyPlugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private emit<T extends keyof FlipperCompanionEvents>(
|
private emit<T extends keyof FlipperCompanionEvents>(
|
||||||
event: T,
|
event: T,
|
||||||
data: FlipperCompanionEvents[T],
|
data: FlipperCompanionEvents[T],
|
||||||
@@ -241,6 +267,8 @@ export class FlipperServerCompanion {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
'companion-plugin-start': async (clientId, pluginId) => {
|
'companion-plugin-start': async (clientId, pluginId) => {
|
||||||
|
await this.loadPluginIfNeeded(pluginId);
|
||||||
|
|
||||||
const client = await this.createHeadlessClientIfNeeded(clientId);
|
const client = await this.createHeadlessClientIfNeeded(clientId);
|
||||||
|
|
||||||
const pluginInstance = client.sandyPluginStates.get(pluginId);
|
const pluginInstance = client.sandyPluginStates.get(pluginId);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export function attachSocketServer(
|
|||||||
flipperServerCompanion = new FlipperServerCompanion(
|
flipperServerCompanion = new FlipperServerCompanion(
|
||||||
server,
|
server,
|
||||||
getLogger(),
|
getLogger(),
|
||||||
companionEnv.pluginInitializer.initialPlugins,
|
companionEnv,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user