diff --git a/client/src/index.js b/client/src/index.js index a2d778e7..e87fdfe8 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -10,7 +10,7 @@ import { DOM, BdUI, Modals } from 'ui'; import BdCss from './styles/index.scss'; -import { Events, CssEditor, Globals, PluginManager, ThemeManager, ModuleManager, WebpackModules, Settings } from 'modules'; +import { Events, CssEditor, Globals, ExtModuleManager, PluginManager, ThemeManager, ModuleManager, WebpackModules, Settings } from 'modules'; import { ClientLogger as Logger, ClientIPC } from 'common'; class BetterDiscord { @@ -30,6 +30,7 @@ class BetterDiscord { async init() { await Settings.loadSettings(); await ModuleManager.initModules(); + await ExtModuleManager.loadAllModules(true); await PluginManager.loadAllPlugins(true); await ThemeManager.loadAllThemes(true); Modals.showContentManagerErrors(); diff --git a/client/src/modules/extmodule.js b/client/src/modules/extmodule.js new file mode 100644 index 00000000..7973037f --- /dev/null +++ b/client/src/modules/extmodule.js @@ -0,0 +1,35 @@ +/** + * BetterDiscord External Module Base + * 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. +*/ + +export default class ExtModule { + + constructor(pluginInternals) { + this.__pluginInternals = pluginInternals; + this.__require = window.require(this.paths.mainPath); + this.hasSettings = false; + } + + get type() { return 'module' } + get configs() { return this.__pluginInternals.configs } + get info() { return this.__pluginInternals.info } + get icon() { return this.info.icon } + get paths() { return this.__pluginInternals.paths } + get main() { return this.__pluginInternals.main } + get defaultConfig() { return this.configs.defaultConfig } + get userConfig() { return this.configs.userConfig } + get id() { return this.info.id || this.info.name.replace(/[^a-zA-Z0-9-]/g, '-').replace(/--/g, '-') } + get name() { return this.info.name } + get authors() { return this.info.authors } + get version() { return this.info.version } + get pluginPath() { return this.paths.contentPath } + get dirName() { return this.paths.dirName } + get enabled() { return true } + get pluginConfig() { return this.userConfig.config || [] } +} diff --git a/client/src/modules/extmodulemanager.js b/client/src/modules/extmodulemanager.js new file mode 100644 index 00000000..a9e0f8fe --- /dev/null +++ b/client/src/modules/extmodulemanager.js @@ -0,0 +1,53 @@ +/** + * BetterDiscord External Module Manager Module + * 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 ContentManager from './contentmanager'; +import ExtModule from './extmodule'; +import { ClientLogger as Logger } from 'common'; +import { Events } from 'modules'; + +export default class extends ContentManager { + + static get localModules() { + return this.localContent; + } + + static get contentType() { + return 'module'; + } + + static get moduleName() { + return 'Ext Module Manager'; + } + + static get pathId() { + return 'modules'; + } + + static get loadAllModules() { + return this.loadAllContent; + } + + static get refreshModules() { return this.refreshContent } + + static get loadContent() { return this.loadModule } + static async loadModule(paths, configs, info, main, type) { + return new ExtModule({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName, mainPath: paths.mainPath } }); + } + + + static get findModule() { return this.findContent } + static get getModuleIndex() { return this.getContentIndex } + static get getModuleByName() { return this.getContentByName } + static get getModuleById() { return this.getContentById } + static get getModuleByPath() { return this.getContentByPath } + static get getModuleByDirName() { return this.getContentByDirName } + +} diff --git a/client/src/modules/modules.js b/client/src/modules/modules.js index 3744f96b..90f3e99c 100644 --- a/client/src/modules/modules.js +++ b/client/src/modules/modules.js @@ -1,6 +1,7 @@ export { default as Events } from './events'; export { default as Settings } from './settings'; export { default as CssEditor } from './csseditor'; +export { default as ExtModuleManager } from './extmodulemanager'; export { default as PluginManager } from './pluginmanager'; export { default as ThemeManager } from './thememanager'; export { default as Globals } from './globals'; diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index b07598d0..9ce047fd 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -11,7 +11,7 @@ import { FileUtils } from 'common'; import { Modals } from 'ui'; -export default class { +export default class Plugin { constructor(pluginInternals) { this.__pluginInternals = pluginInternals; diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js index 0ebc547f..3ad97630 100644 --- a/client/src/modules/pluginapi.js +++ b/client/src/modules/pluginapi.js @@ -10,6 +10,7 @@ import { ClientLogger as Logger } from 'common'; import Settings from './settings'; +import ExtModuleManager from './extmodulemanager'; import PluginManager from './pluginmanager'; import ThemeManager from './thememanager'; import Events from './events'; @@ -111,7 +112,7 @@ export default class PluginApi { get require() { return this.import } import(m) { - const module = PluginManager.findPlugin(m); + const module = ExtModuleManager.findModule(m); if (module && module.__require) return module.__require; return null; } diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 1cff6af5..4b3416a5 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -15,31 +15,6 @@ import Vendor from './vendor'; import { ClientLogger as Logger } from 'common'; import { Events } from 'modules'; -class Module { - - constructor(pluginInternals) { - this.__pluginInternals = pluginInternals; - this.__require = window.require(this.paths.mainPath); - this.hasSettings = false; - } - - get type() { return 'module' } - get configs() { return this.__pluginInternals.configs } - get info() { return this.__pluginInternals.info } - get icon() { return this.info.icon } - get paths() { return this.__pluginInternals.paths } - get main() { return this.__pluginInternals.main } - get defaultConfig() { return this.configs.defaultConfig } - get userConfig() { return this.configs.userConfig } - get id() { return this.info.id || this.info.name.replace(/[^a-zA-Z0-9-]/g, '-').replace(/--/g, '-') } - get name() { return this.info.name } - get authors() { return this.info.authors } - get version() { return this.info.version } - get pluginPath() { return this.paths.contentPath } - get dirName() { return this.paths.dirName } - get enabled() { return true } - get pluginConfig() { return this.userConfig.config || [] } -} export default class extends ContentManager { @@ -62,7 +37,6 @@ export default class extends ContentManager { static async loadAllPlugins(supressErrors) { const loadAll = await this.loadAllContent(supressErrors); this.localPlugins.forEach(plugin => { - if (plugin.type === 'module') return; if (plugin.enabled) plugin.start(); }); @@ -72,9 +46,6 @@ export default class extends ContentManager { static get loadContent() { return this.loadPlugin } static async loadPlugin(paths, configs, info, main, type) { - - if (type === 'module') return new Module({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName, mainPath: paths.mainPath } }); - 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, mainPath: paths.mainPath } }); return instance; diff --git a/core/src/main.js b/core/src/main.js index 837a42b3..4d073c36 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -24,6 +24,7 @@ const __DEV = { const __dataPath = path.resolve(__dirname, '..', '..', 'tests', 'data'); const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins'); const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes'); +const __modulePath = path.resolve(__dirname, '..', '..', 'tests', 'modules'); const { Utils, FileUtils, BDIpc, Config, WindowUtils, CSSEditor } = require('./modules'); const { BrowserWindow, dialog } = require('electron'); @@ -36,7 +37,8 @@ const dummyArgs = { { 'id': 'base', 'path': 'basePath' }, { 'id': 'data', 'path': __dataPath }, { 'id': 'plugins', 'path': __pluginPath }, - { 'id': 'themes', 'path': __themePath } + { 'id': 'themes', 'path': __themePath }, + { 'id': 'modules', 'path': __modulePath } ] }; diff --git a/tests/plugins/Example Module/config.json b/tests/modules/Example Module/config.json similarity index 100% rename from tests/plugins/Example Module/config.json rename to tests/modules/Example Module/config.json diff --git a/tests/plugins/Example Module/index.js b/tests/modules/Example Module/index.js similarity index 100% rename from tests/plugins/Example Module/index.js rename to tests/modules/Example Module/index.js