From 66ca32bd1d4bd743386a3eb2b6fcc3c226afa3c1 Mon Sep 17 00:00:00 2001 From: booploops <49113086+booploops@users.noreply.github.com> Date: Thu, 17 Feb 2022 22:12:22 -0800 Subject: [PATCH] frontend plugins first iteration --- src/main/base/plugins.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/base/plugins.ts b/src/main/base/plugins.ts index 3dc77b0f..ccb7f2e4 100644 --- a/src/main/base/plugins.ts +++ b/src/main/base/plugins.ts @@ -32,6 +32,7 @@ export class Plugins { if (fs.existsSync(this.userPluginsPath)) { fs.readdirSync(this.userPluginsPath).forEach(file => { + // Plugins V1 if (file.endsWith('.ts') || file.endsWith('.js')) { if (!electron.app.isPackaged) { const plugin = require(path.join(this.userPluginsPath, file)).default; @@ -50,7 +51,24 @@ export class Plugins { plugins[file] = new plugin(electron.app, utils.getStore()); } } - + } + // Plugins V2 + else if (fs.lstatSync(path.join(this.userPluginsPath, file)).isDirectory()) { + const pluginPath = path.join(this.userPluginsPath, file); + if (fs.existsSync(path.join(pluginPath, 'package.json'))) { + const plugin = require(path.join(pluginPath, "index.js")); + if (plugins[plugin.name] || plugin.name in plugins) { + console.log(`[${plugin.name}] Plugin already loaded / Duplicate Class Name`); + } else { + const pluginEnv = { + app: electron.app, + store: utils.getStore(), + utils: utils, + dir: pluginPath + } + plugins[plugin.name] = new plugin(pluginEnv); + } + } } }); }