Cleanup and some code reuse between Device- and normal Plugins
Summary: Introducing a base abstract class (blegh) to share some life cycle management between Device- and normal plugins. Cleaned up the test utils a bit as well + some old TODO's that now have been taken care of Reviewed By: nikoant Differential Revision: D22727089 fbshipit-source-id: 507816f1bfdbc6e7e71d4bd365b881b6710ca917
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b9c9e89b53
commit
642261c0d0
@@ -15,7 +15,7 @@ import {
|
||||
SandyDevicePluginInstance,
|
||||
SandyPluginDefinition,
|
||||
} from 'flipper-plugin';
|
||||
import {DevicePluginMap} from '../plugin';
|
||||
import {DevicePluginMap, FlipperDevicePlugin} from '../plugin';
|
||||
|
||||
export type DeviceShell = {
|
||||
stdout: stream.Readable;
|
||||
@@ -179,18 +179,22 @@ export default class BaseDevice {
|
||||
const plugins = Array.from(devicePlugins.values());
|
||||
plugins.sort(sortPluginsByName);
|
||||
for (const plugin of plugins) {
|
||||
if (plugin instanceof SandyPluginDefinition) {
|
||||
if (plugin.asDevicePluginModule().supportsDevice(this as any)) {
|
||||
this.devicePlugins.push(plugin.id);
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new SandyDevicePluginInstance(this, plugin),
|
||||
); // TODO: pass initial state if applicable
|
||||
}
|
||||
} else {
|
||||
if (plugin.supportsDevice(this)) {
|
||||
this.devicePlugins.push(plugin.id);
|
||||
}
|
||||
this.loadDevicePlugin(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
loadDevicePlugin(plugin: typeof FlipperDevicePlugin | SandyPluginDefinition) {
|
||||
if (plugin instanceof SandyPluginDefinition) {
|
||||
if (plugin.asDevicePluginModule().supportsDevice(this as any)) {
|
||||
this.devicePlugins.push(plugin.id);
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new SandyDevicePluginInstance(this, plugin),
|
||||
); // TODO T70582933: pass initial state if applicable
|
||||
}
|
||||
} else {
|
||||
if (plugin.supportsDevice(this)) {
|
||||
this.devicePlugins.push(plugin.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,6 @@ const requirePluginInternal = (
|
||||
|
||||
if (pluginDetails.flipperSDKVersion) {
|
||||
// Sandy plugin
|
||||
// TODO: suppor device Plugins T68738317
|
||||
return new SandyPluginDefinition(pluginDetails, plugin);
|
||||
} else {
|
||||
// classic plugin
|
||||
|
||||
@@ -23,7 +23,7 @@ const WelcomeScreen = isHeadless()
|
||||
import NotificationScreen from '../chrome/NotificationScreen';
|
||||
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
|
||||
import SupportRequestDetails from '../fb-stubs/SupportRequestDetails';
|
||||
import {getPluginKey} from '../utils/pluginUtils';
|
||||
import {getPluginKey, isDevicePluginDefinition} from '../utils/pluginUtils';
|
||||
import {deconstructClientId} from '../utils/clientUtils';
|
||||
import {FlipperDevicePlugin, PluginDefinition, isSandyPlugin} from '../plugin';
|
||||
import {RegisterPluginAction} from './plugins';
|
||||
@@ -393,20 +393,10 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
|
||||
// plugins are registered after creating the base devices, so update them
|
||||
const plugins = action.payload;
|
||||
plugins.forEach((plugin) => {
|
||||
// TODO: T68738317 support sandy device plugin
|
||||
if (
|
||||
!isSandyPlugin(plugin) &&
|
||||
plugin.prototype instanceof FlipperDevicePlugin
|
||||
) {
|
||||
if (isDevicePluginDefinition(plugin)) {
|
||||
// smell: devices are mutable
|
||||
state.devices.forEach((device) => {
|
||||
// @ts-ignore
|
||||
if (plugin.supportsDevice(device)) {
|
||||
device.devicePlugins = [
|
||||
...(device.devicePlugins || []),
|
||||
plugin.id,
|
||||
];
|
||||
}
|
||||
device.loadDevicePlugin(plugin);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -662,7 +662,7 @@ async function getStoreExport(
|
||||
const newPluginState = metadata.pluginStates;
|
||||
|
||||
// TODO: support async export like fetchMetaData T68683476
|
||||
// TODO: support device plugins T68738317
|
||||
// TODO: support device plugins T70582933
|
||||
const pluginStates2 = pluginsToProcess
|
||||
? exportSandyPluginStates(pluginsToProcess)
|
||||
: {};
|
||||
|
||||
@@ -128,7 +128,6 @@ export function processMessagesLater(
|
||||
case isSelected && getPendingMessages(store, pluginKey).length === 0:
|
||||
processMessagesImmediately(store, pluginKey, plugin, messages);
|
||||
break;
|
||||
// TODO: support SandyDevicePlugin T68738317
|
||||
case isSelected:
|
||||
case plugin instanceof SandyPluginInstance:
|
||||
case plugin instanceof FlipperDevicePlugin:
|
||||
|
||||
Reference in New Issue
Block a user