baseline plugin system (Non-functional)

This commit is contained in:
Core 2022-01-10 09:40:40 +00:00
parent 312a5a7b70
commit 576f44fa86
3 changed files with 79 additions and 0 deletions

43
src/main/base/plugins.ts Normal file
View file

@ -0,0 +1,43 @@
import * as fs from 'fs';
import * as path from 'path';
import * as electron from 'electron'
export default class PluginHandler {
private basePluginsPath = path.join(__dirname, '../plugins');
private userPluginsPath = path.join(electron.app.getPath('userData'), 'plugins');
private pluginsList: any = [];
constructor() {
this.pluginsList = this.getPlugins();
console.log(this.pluginsList);
}
public getPlugins(): any {
let plugins: any = [];
if (fs.existsSync(this.basePluginsPath)) {
fs.readdirSync(this.basePluginsPath).forEach(file => {
if (file.endsWith('.ts') || file.endsWith('.js')) {
const plugin = require(path.join(this.basePluginsPath, file));
plugins.push(new plugin());
}
});
}
if (fs.existsSync(this.userPluginsPath)) {
fs.readdirSync(this.userPluginsPath).forEach(file => {
if (file.endsWith('.ts') || file.endsWith('.js')) {
const plugin = require(path.join(this.userPluginsPath, file));
console.log(plugin);
plugins.push(new plugin());
}
});
}
return plugins;
}
}