diff --git a/src/main/ipc/invokes/getFileTypes.ts b/src/main/ipc/invokes/getFileTypes.ts index 72c56a6..e4725b2 100644 --- a/src/main/ipc/invokes/getFileTypes.ts +++ b/src/main/ipc/invokes/getFileTypes.ts @@ -6,8 +6,8 @@ export default async function getFileTypes( event: IpcMainInvokeEvent, // eslint-disable-next-line @typescript-eslint/no-unused-vars _: undefined -): Promise { - const pluginsService = project.pluginsService; - const fileTypes = pluginsService.getFileTypePlugins(); - return ['ok']; +): Promise { + const { pluginsService } = project; + const fileTypePlugins = pluginsService.getFileTypePlugins(); + return fileTypePlugins; } diff --git a/src/main/services/pluginsService/index.ts b/src/main/services/pluginsService/index.ts index 4b29c9a..81e7914 100644 --- a/src/main/services/pluginsService/index.ts +++ b/src/main/services/pluginsService/index.ts @@ -6,7 +6,7 @@ import project from 'main/project'; import { LogLevel } from 'shared/types'; import { sanitizePath, tryGetAsync } from 'shared/utils'; -import PluginApi from './pluginApi'; +import PluginApi, { PluginConfig } from './pluginApi'; import IService from '../IService'; @@ -15,15 +15,15 @@ class PluginsService implements IService { #pluginsFolder: string; - #plugins: any; + #plugins: { [name: string]: PluginConfig }; constructor(pluginsFolder: string, messageBroker: ProjectMessageBroker) { this.#messageBroker = messageBroker; this.#pluginsFolder = sanitizePath(pluginsFolder); + this.#plugins = {}; } async init(): Promise { - this.#plugins = {}; try { await this.loadPlugins(); return true; @@ -87,7 +87,11 @@ class PluginsService implements IService { // TODO: consider better naming getFileTypePlugins() { const plugins = this.#plugins; - console.log(plugins); + const result = Object.entries(plugins) + .filter((kv) => kv[1].flowView.fileType !== null) + .map((kv) => kv[0]) + .map((key) => plugins[key]); + return result; } // eslint-disable-next-line class-methods-use-this diff --git a/src/main/services/pluginsService/pluginApi.ts b/src/main/services/pluginsService/pluginApi.ts index 9d85242..84a4dc5 100644 --- a/src/main/services/pluginsService/pluginApi.ts +++ b/src/main/services/pluginsService/pluginApi.ts @@ -1,18 +1,27 @@ -type ConnectionInfo = { +export type ConnectionInfo = { in: number; out: number; }; -type NodeInfo = { +export type NodeInfo = { type: string; connection: ConnectionInfo; }; +export type FlowViewConfig = { + fileType: string; + nodes: NodeInfo[]; +}; + +export type PluginConfig = { + flowView: FlowViewConfig; +}; + // builder.flowView.setFileType('xxx') // *.xxx // builder.flowView.setNodes(xxx) // builder.globalShortcut.setShortcutAction(yyy) -class FlowViewBuilder { +export class FlowViewBuilder { #fileType: string | null = null; #nodes: NodeInfo[] | null = null; @@ -28,10 +37,10 @@ class FlowViewBuilder { } // TODO: making these build functions private can help with a well constructed API - build() { + build(): FlowViewConfig { const fileType = this.#fileType; const nodes = this.#nodes; - return { fileType, nodes }; + return { fileType: fileType || '', nodes: nodes || [] }; } } @@ -42,7 +51,7 @@ export default class PluginBuilder { this.flowView = new FlowViewBuilder(); } - build() { + build(): PluginConfig { const flowViewBuilder = this.flowView; const flowView = flowViewBuilder.build(); return { flowView }; diff --git a/src/renderer/components/Tab/TabView.tsx b/src/renderer/components/Tab/TabView.tsx index 1a5079f..cc0a2c1 100644 --- a/src/renderer/components/Tab/TabView.tsx +++ b/src/renderer/components/Tab/TabView.tsx @@ -45,7 +45,8 @@ export default function TabView({ tabId }: TabViewProps) { [dispatch, tabId] ); const dispatchFileView = () => { - console.log(fileTypes, 'fileTypes') + console.log(fileTypes, 'fileTypes'); + console.log(fileTypes[tabData.extension], '??'); if (tabData.extension === 'xflow') { return ; }