add base plugin api and pass vendor to plugins
This commit is contained in:
parent
35338dd104
commit
4a7a9ae1db
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* BetterDiscord Plugin Api
|
||||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
||||
* All rights reserved.
|
||||
* https://betterdiscord.net
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { ClientLogger as Logger } from 'common';
|
||||
|
||||
export default class PluginApi {
|
||||
|
||||
constructor(pluginInfo) {
|
||||
this.pluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
loggerLog(message) { Logger.log(this.pluginInfo.name, message) }
|
||||
loggerErr(message) { Logger.err(this.pluginInfo.name, message) }
|
||||
loggerWarn(message) { Logger.warn(this.pluginInfo.name, message) }
|
||||
loggerInfo(message) { Logger.info(this.pluginInfo.name, message) }
|
||||
loggerDbg(message) { Logger.dbg(this.pluginInfo.name, message) }
|
||||
get Logger() {
|
||||
return {
|
||||
log: this.loggerLog.bind(this),
|
||||
err: this.loggerErr.bind(this),
|
||||
warn: this.loggerWarn.bind(this),
|
||||
info: this.loggerInfo.bind(this),
|
||||
dbg: this.loggerDbg.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
get Events() {
|
||||
return {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
import ContentManager from './contentmanager';
|
||||
import Plugin from './plugin';
|
||||
import PluginApi from './pluginapi';
|
||||
import Vendor from './vendor';
|
||||
import { ClientLogger as Logger } from 'common';
|
||||
import { Events } from 'modules';
|
||||
|
||||
|
@ -36,7 +38,7 @@ export default class extends ContentManager {
|
|||
|
||||
static get loadContent() { return this.loadPlugin }
|
||||
static async loadPlugin(paths, configs, info, main) {
|
||||
const plugin = window.require(paths.mainPath)(Plugin, {}, {});
|
||||
const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info), Vendor);
|
||||
const instance = new plugin({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName } });
|
||||
|
||||
if (instance.enabled) instance.start();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = (Plugin, Api, Vendor) => {
|
||||
|
||||
const { $, moment } = Vendor;
|
||||
const { Events } = Api;
|
||||
const { $, moment, _ } = Vendor;
|
||||
const { Events, Logger } = Api;
|
||||
|
||||
const test = 'Testing';
|
||||
|
||||
|
@ -11,12 +11,12 @@ module.exports = (Plugin, Api, Vendor) => {
|
|||
}
|
||||
|
||||
onStart() {
|
||||
console.log('Example Plugin 1 onStart');
|
||||
Logger.log('onStart');
|
||||
return true;
|
||||
}
|
||||
|
||||
onStop() {
|
||||
console.log('Example Plugin 1 onStop');
|
||||
Logger.log('onStop');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue