baseline plugin system (Non-functional)
This commit is contained in:
parent
312a5a7b70
commit
576f44fa86
3 changed files with 79 additions and 0 deletions
43
src/main/base/plugins.ts
Normal file
43
src/main/base/plugins.ts
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,9 @@ import {app} from 'electron';
|
||||||
import {Win} from "./base/win";
|
import {Win} from "./base/win";
|
||||||
import {ConfigStore} from "./base/store";
|
import {ConfigStore} from "./base/store";
|
||||||
import {AppEvents} from "./base/app";
|
import {AppEvents} from "./base/app";
|
||||||
|
// import PluginHandler from "./base/plugins";
|
||||||
|
|
||||||
|
// const test = new PluginHandler();
|
||||||
|
|
||||||
const config = new ConfigStore();
|
const config = new ConfigStore();
|
||||||
const App = new AppEvents(config.store);
|
const App = new AppEvents(config.store);
|
||||||
|
|
33
src/main/plugins/examplePlugin.ts
Normal file
33
src/main/plugins/examplePlugin.ts
Normal file
|
@ -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 {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue