From 686323f53b8aa845a4752fafa1b8063f1e8c975a Mon Sep 17 00:00:00 2001 From: rzvxa Date: Wed, 4 Oct 2023 03:18:48 +0330 Subject: [PATCH] Added wireframe for plugin configuration builder --- src/main/services/pluginsService/index.ts | 9 ++++++ .../services/pluginsService/pluginBuilder.ts | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/services/pluginsService/pluginBuilder.ts diff --git a/src/main/services/pluginsService/index.ts b/src/main/services/pluginsService/index.ts index 58bf514..f92ac1b 100644 --- a/src/main/services/pluginsService/index.ts +++ b/src/main/services/pluginsService/index.ts @@ -6,6 +6,8 @@ import project from 'main/project'; import { LogLevel } from 'shared/types'; import { sanitizePath, tryGetAsync } from 'shared/utils'; +import PluginBuilder from './pluginBuilder'; + import IService from '../IService'; class PluginsService implements IService { @@ -13,14 +15,18 @@ class PluginsService implements IService { #pluginsFolder: string; + #plugins: any; + constructor(pluginsFolder: string, messageBroker: ProjectMessageBroker) { this.#messageBroker = messageBroker; this.#pluginsFolder = sanitizePath(pluginsFolder); } async init(): Promise { + this.#plugins = {}; try { await this.loadPlugins(); + console.log(this.#plugins); return true; } catch (error) { return false; @@ -87,6 +93,7 @@ class PluginsService implements IService { return `Required ${path}`; }, logger: project.logger, + builder: new PluginBuilder(), }; const script = await readFile(scriptPath, 'utf8'); @@ -94,6 +101,8 @@ class PluginsService implements IService { try { // eslint-disable-next-line no-new-func new Function(`with(this) { ${script} }`).call(context); + const plugin = context.builder.build(); + this.#plugins[pluginName] = plugin; } catch (error) { project.logger.log(LogLevel.error, ['plugin', pluginName], error); } diff --git a/src/main/services/pluginsService/pluginBuilder.ts b/src/main/services/pluginsService/pluginBuilder.ts new file mode 100644 index 0000000..0dbbf78 --- /dev/null +++ b/src/main/services/pluginsService/pluginBuilder.ts @@ -0,0 +1,31 @@ +type ConnectionInfo = { + in: number; + out: number; +}; + +type NodeInfo = { + type: string; + connection: ConnectionInfo; +}; + +export default class PluginBuilder { + #flowView: boolean = false; + + #nodes: NodeInfo | undefined = undefined; + + setFlowView(value: boolean) { + this.#flowView = value; + return this; + } + + setNodes(nodes: NodeInfo) { + this.#nodes = nodes; + return this; + } + + build() { + const flowView = this.#flowView; + const nodes = this.#nodes; + return { flowView, nodes }; + } +}