From 4a7a9ae1db95ba608535aafef8345ca0cf05ae07 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 12 Feb 2018 00:07:23 +0200 Subject: [PATCH] add base plugin api and pass vendor to plugins --- client/src/modules/pluginapi.js | 41 +++++++++++++++++++++++++++++ client/src/modules/pluginmanager.js | 4 ++- tests/plugins/Example/index.js | 8 +++--- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 client/src/modules/pluginapi.js diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js new file mode 100644 index 00000000..f424b517 --- /dev/null +++ b/client/src/modules/pluginapi.js @@ -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 { + + } + } + +} diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 4e7a7cd9..58cbcbc8 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -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(); diff --git a/tests/plugins/Example/index.js b/tests/plugins/Example/index.js index 2408f6d9..53d5c868 100644 --- a/tests/plugins/Example/index.js +++ b/tests/plugins/Example/index.js @@ -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; } }