diff --git a/src/main/base/plugins.ts b/src/main/base/plugins.ts new file mode 100644 index 00000000..6e5aebfe --- /dev/null +++ b/src/main/base/plugins.ts @@ -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; + } + +} \ No newline at end of file diff --git a/src/main/index.ts b/src/main/index.ts index 6a2532e2..7ef76e08 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -8,6 +8,9 @@ import {app} from 'electron'; import {Win} from "./base/win"; import {ConfigStore} from "./base/store"; import {AppEvents} from "./base/app"; +// import PluginHandler from "./base/plugins"; + +// const test = new PluginHandler(); const config = new ConfigStore(); const App = new AppEvents(config.store); diff --git a/src/main/plugins/examplePlugin.ts b/src/main/plugins/examplePlugin.ts new file mode 100644 index 00000000..8a8d6d30 --- /dev/null +++ b/src/main/plugins/examplePlugin.ts @@ -0,0 +1,33 @@ +export default class ExamplePlugin { + + public name: string = 'examplePlugin'; + public description: string = 'Example plugin'; + public version: string = '1.0.0'; + public author: string = 'Example author'; + + constructor() { + this.name = 'coolPlugin'; + this.description = 'A pretty cool plugin'; + this.version = '1.0.0'; + this.author = 'Core'; + } + + onStart(): void { + console.log('Example plugin started'); + } + + onReady(): void { + console.log('Example plugin ready'); + } + + onStop(): void { + console.log('Example plugin stopped'); + } + + OnPlaybackStateChanged(attributes: object): void { + } + + OnMediaStateChanged(attributes: object): void { + } + +} \ No newline at end of file