From d122e275788d16f43b6e1a1c6658b0adb66d6f9e Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 7 Mar 2018 02:07:17 +0000 Subject: [PATCH] Add extmodules and webpack modules to plugin API --- client/src/modules/pluginapi.js | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js index 083386b6..dd07cf35 100644 --- a/client/src/modules/pluginapi.js +++ b/client/src/modules/pluginapi.js @@ -14,6 +14,7 @@ import ExtModuleManager from './extmodulemanager'; import PluginManager from './pluginmanager'; import ThemeManager from './thememanager'; import Events from './events'; +import WebpackModules from './webpackmodules'; import { SettingsSet, SettingsCategory, Setting, SettingsScheme } from 'structs'; import { Modals, DOM } from 'ui'; import SettingsModal from '../ui/components/bd/modals/SettingsModal.vue'; @@ -293,4 +294,57 @@ export default class PluginApi { }; } + /** + * ExtModules + */ + + async getModule(module_id) { + // This should require extra permissions + return await ExtModuleManager.waitForContent(module_id); + } + listModules() { + return ExtModuleManager.localContent.map(module => module.id); + } + get ExtModules() { + return { + getModule: this.getModule.bind(this), + listModules: this.listModules.bind(this) + }; + } + + /** + * WebpackModules + */ + + get webpackRequire() { + return WebpackModules.require; + } + getWebpackModule(filter, first = true) { + return WebpackModules.getModule(filter, first); + } + getWebpackModuleByName(name, fallback) { + return WebpackModules.getModuleByName(name, fallback); + } + getWebpackModuleByRegex(regex, first = true) { + return WebpackModules.getModuleByRegex(regex, first); + } + getWebpackModuleByProperties(props, first = true) { + return WebpackModules.getModuleByProps(props, first); + } + getWebpackModuleByPrototypeFields(props, first = true) { + return WebpackModules.getModuleByPrototypes(props, first); + } + get WebpackModules() { + return Object.defineProperty({ + getModule: this.getWebpackModule.bind(this), + getModuleByName: this.getWebpackModuleByName.bind(this), + getModuleByDisplayName: this.getWebpackModuleByName.bind(this), + getModuleByRegex: this.getWebpackModuleByRegex.bind(this), + getModuleByProperties: this.getWebpackModuleByProperties.bind(this), + getModuleByPrototypeFields: this.getWebpackModuleByPrototypeFields.bind(this) + }, 'require', { + get: () => this.webpackRequire + }); + } + }