Merge remote-tracking branch 'upstream/master' into add-setting-events

# Conflicts:
#	client/src/modules/pluginapi.js
This commit is contained in:
Samuel Elliott 2018-02-13 23:07:46 +00:00
commit d3c3de5a79
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
10 changed files with 97 additions and 33 deletions

View File

@ -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();

View File

@ -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 || [] }
}

View File

@ -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 }
}

View File

@ -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';

View File

@ -11,7 +11,7 @@
import { FileUtils } from 'common';
import { Modals } from 'ui';
export default class {
export default class Plugin {
constructor(pluginInternals) {
this.__pluginInternals = pluginInternals;

View File

@ -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;
}

View File

@ -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;

View File

@ -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 }
]
};