Summary: Adds an argument to the headless Flipper to print the list of available plugins. Added `--list-plugins`. Currently the startFlipper function is not scalable enough to add new arguments and its implementation. I am planning to tackle this with the list of Actions which will be closure. So adding a new argument with its implementation will be just appending a closure at the correct location in an array. Will work on that in the later diff stacked on the current one. Reviewed By: jknoxville Differential Revision: D15789778 fbshipit-source-id: 91ba472617d593c3490bb932590a06d83597cba7
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
import type BaseDevice from '../devices/BaseDevice.js';
|
|
import {FlipperDevicePlugin, FlipperPlugin} from '../plugin.js';
|
|
import type {State as PluginStatesState} from '../reducers/pluginStates.js';
|
|
import {pluginsClassMap} from './exportData.js';
|
|
import type {State as PluginsState} from '../reducers/plugins.js';
|
|
import type {PluginDefinition} from '../dispatcher/plugins';
|
|
|
|
export function getPluginKey(
|
|
selectedApp: ?string,
|
|
baseDevice: ?BaseDevice,
|
|
pluginID: string,
|
|
): string {
|
|
if (selectedApp) {
|
|
return `${selectedApp}#${pluginID}`;
|
|
}
|
|
if (baseDevice) {
|
|
// If selected App is not defined, then the plugin is a device plugin
|
|
return `${baseDevice.serial}#${pluginID}`;
|
|
}
|
|
return `unknown#${pluginID}`;
|
|
}
|
|
|
|
export function getPersistedState<PersistedState>(
|
|
pluginKey: string,
|
|
persistingPlugin: ?Class<
|
|
| FlipperPlugin<*, *, PersistedState>
|
|
| FlipperDevicePlugin<*, *, PersistedState>,
|
|
>,
|
|
pluginStates: PluginStatesState,
|
|
): ?PersistedState {
|
|
if (!persistingPlugin) {
|
|
return null;
|
|
}
|
|
|
|
const persistedState: PersistedState = {
|
|
...persistingPlugin.defaultPersistedState,
|
|
...pluginStates[pluginKey],
|
|
};
|
|
return persistedState;
|
|
}
|
|
|
|
export function getActivePluginNames(plugins: PluginsState): Array<string> {
|
|
let pluginsMap: Map<
|
|
string,
|
|
Class<FlipperDevicePlugin<> | FlipperPlugin<>>,
|
|
> = pluginsClassMap(plugins);
|
|
|
|
let arr: Array<PluginDefinition> = plugins.disabledPlugins.concat(
|
|
plugins.gatekeepedPlugins,
|
|
);
|
|
arr.forEach((plugin: PluginDefinition) => {
|
|
if (pluginsMap.has(plugin.name)) {
|
|
pluginsMap.delete(plugin.name);
|
|
}
|
|
});
|
|
|
|
plugins.failedPlugins.forEach((plugin: [PluginDefinition, string]) => {
|
|
if (plugin[0] && plugin[0].name && pluginsMap.has(plugin[0].name)) {
|
|
pluginsMap.delete(plugin[0].name);
|
|
}
|
|
});
|
|
return [...pluginsMap.keys()];
|
|
}
|