From 3807f237324f9d170b12523c9e345eac7bfab629 Mon Sep 17 00:00:00 2001 From: rzvxa Date: Wed, 11 Oct 2023 03:22:32 +0330 Subject: [PATCH] WIP commit, Migrating to new plugin API --- src/main/services/pluginsService/index.ts | 16 ++++++++++------ src/main/services/pluginsService/pluginApi.ts | 13 +++++++------ src/renderer/components/Tab/TabView.tsx | 2 +- src/shared/types/fileTypeMap.ts | 6 ++++-- src/shared/types/plugin/pluginConfig.ts | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/services/pluginsService/index.ts b/src/main/services/pluginsService/index.ts index a47fd8e..589f6f9 100644 --- a/src/main/services/pluginsService/index.ts +++ b/src/main/services/pluginsService/index.ts @@ -3,7 +3,7 @@ import { fsUtils } from 'main/utils'; import { ProjectMessageBroker } from 'main/project/projectMessageBroker'; import project from 'main/project'; -import { LogLevel } from 'shared/types'; +import { LogLevel, FileTypeMap } from 'shared/types'; import { PluginConfig } from 'shared/types/plugin'; import { sanitizePath, tryGetAsync } from 'shared/utils'; @@ -88,11 +88,15 @@ class PluginsService implements IService { // TODO: consider better naming getFileTypePlugins() { const plugins = this.#plugins; - const result = Object.fromEntries( - Object.entries(plugins) - .filter((kv) => kv[1].flowView.fileType !== null) - .map((kv) => [kv[1].flowView.fileType, kv[1]]) - ); + + const result: FileTypeMap = {}; + + Object.entries(plugins).forEach(([_key, plug]) => { + plug.flowViews.forEach((fv) => { + result[fv.fileType] = fv; + }); + }); + return result; } diff --git a/src/main/services/pluginsService/pluginApi.ts b/src/main/services/pluginsService/pluginApi.ts index 0e42807..9b9dbae 100644 --- a/src/main/services/pluginsService/pluginApi.ts +++ b/src/main/services/pluginsService/pluginApi.ts @@ -33,15 +33,16 @@ export class FlowViewBuilder { } export default class PluginBuilder { - flowView: FlowViewBuilder; + #flowViews: FlowViewBuilder[] = []; - constructor() { - this.flowView = new FlowViewBuilder(); + addFlowView(): FlowViewBuilder { + const flowView = new FlowViewBuilder(); + this.#flowViews.push(flowView); + return flowView; } build(): PluginConfig { - const flowViewBuilder = this.flowView; - const flowView = flowViewBuilder.build(); - return { flowView }; + const flowViews = this.#flowViews.map((builder) => builder.build()); + return { flowViews }; } } diff --git a/src/renderer/components/Tab/TabView.tsx b/src/renderer/components/Tab/TabView.tsx index 82b3ff9..a3a985e 100644 --- a/src/renderer/components/Tab/TabView.tsx +++ b/src/renderer/components/Tab/TabView.tsx @@ -53,7 +53,7 @@ export default function TabView({ tabId }: TabViewProps) { ); } else { diff --git a/src/shared/types/fileTypeMap.ts b/src/shared/types/fileTypeMap.ts index e8b6d68..33c6e73 100644 --- a/src/shared/types/fileTypeMap.ts +++ b/src/shared/types/fileTypeMap.ts @@ -1,3 +1,5 @@ -import { PluginConfig } from './plugin'; +import { FlowViewConfig } from './plugin'; +// import { PluginConfig } from './plugin'; -export type FileTypeMap = { [name: string]: PluginConfig }; +export type FileTypeMap = { [name: string]: FlowViewConfig }; +// export type FileTypeMap = { [name: string]: PluginConfig }; diff --git a/src/shared/types/plugin/pluginConfig.ts b/src/shared/types/plugin/pluginConfig.ts index e0066ac..04ddf9a 100644 --- a/src/shared/types/plugin/pluginConfig.ts +++ b/src/shared/types/plugin/pluginConfig.ts @@ -14,5 +14,5 @@ export type FlowViewConfig = { }; export type PluginConfig = { - flowView: FlowViewConfig; + flowViews: FlowViewConfig[]; };