Files
fb-admin/src/backend/PluginManager/Plugin.ts
T
2019-08-11 22:12:55 +02:00

98 lines
3.1 KiB
TypeScript

import { default as PluginManager } from "./PluginManager";
import { Plugin, socketioRPC } from "frontblock-generic/Plugin";
import * as Logger from 'log4js';
Logger.configure({
appenders:
{
"PluginManager/Plugin": { type: 'stdout' },
//app: { type: 'file', filename: 'application.log' }
},
categories:
{
default: { appenders: [ 'PluginManager/Plugin' ], level: 'debug' }
}
})
const logger = Logger.getLogger("PluginManager/Plugin")
export default class PluginManagerPlugin extends PluginManager implements Plugin{
constructor(){
super()
this.loadedPlugins[this.name] = {backend: this, frontend: this.loadFrontend(this.name)}
}
exportExtraRPCs(): socketioRPC[] {
return [
{
name: "getAvailablePluginNames",
visibility: "private",
rpc: async() => { return await this.getAvailablePluginNames() },
type: 'call'
},
{
name: "getInstalledPluginNames",
visibility: "private",
rpc: async() => { return await this.getInstalledPluginNames() },
type: 'call'
},
{
name: "getLoadedPluginNames",
visibility: "private",
rpc: async () => { return this.getLoadedPluginNames() },
type: 'call'
},{
name: "installPlugin",
visibility: "private",
rpc: async(pluginName:string) => { return await this.installPlugin(pluginName) },
type: 'call'
},
{
name: "uninstallPlugin",
visibility: "private",
rpc: async(pluginName:string) => { return await this.uninstallPlugin(pluginName) },
type: 'call'
},
{
name: "loadPlugin",
visibility: "private",
rpc: async(pluginName:string) => { return await this.loadPlugin(pluginName) },
type: 'call'
},
{
name: "unloadPlugin",
visibility: "private",
rpc: async(pluginName:string) => { return this.unloadPlugin(pluginName) },
type: 'call'
},{
name: "extractPlugin",
visibility: "private",
rpc: async(conf) => { return this.extractPlugin(conf) },
type: 'call'
},{
name: "downloadPlugin",
visibility: "private",
rpc: async(conf) => { return this.downloadPlugin(conf) },
type: 'call'
},{
name: "getConfig",
visibility: "private",
rpc: async() => { return this.conf },
type: 'call'
}
]
}
async start(): Promise<void> {
await Promise.all(this.getInstalledPluginNames().map(name => {
if(name == this.name) return
return this.loadPlugin(name)
}));
}
stop(): void {
}
}