From 85db5af65556bcb074fa14bd8acad22809910068 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Tue, 30 Jan 2018 15:20:24 +0200 Subject: [PATCH] Module resolves and base pluginmanager --- client/src/index.js | 4 +- client/src/modules/csseditor.js | 4 +- client/src/modules/globals.js | 30 +++++++++++++ client/src/modules/index.js | 3 -- client/src/modules/module.js | 45 +++++++++++++++++++ client/src/modules/modules.js | 5 +++ client/src/modules/pluginmanager.js | 21 +++++++++ client/src/ui/components/BdSettings.vue | 2 +- .../src/ui/components/BdSettingsWrapper.vue | 2 +- client/src/ui/components/bd/CssEditor.vue | 2 +- client/src/ui/{index.js => ui.js} | 0 client/webpack.config.js | 8 +++- common/modules/{index.js => common.js} | 0 13 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 client/src/modules/globals.js delete mode 100644 client/src/modules/index.js create mode 100644 client/src/modules/module.js create mode 100644 client/src/modules/modules.js create mode 100644 client/src/modules/pluginmanager.js rename client/src/ui/{index.js => ui.js} (100%) rename common/modules/{index.js => common.js} (100%) diff --git a/client/src/index.js b/client/src/index.js index 9e7c305a..b8d74459 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -8,9 +8,9 @@ * LICENSE file in the root directory of this source tree. */ -import { DOM, BdUI } from './ui'; +import { DOM, BdUI } from 'ui'; import BdCss from './styles/index.scss'; -import { Events, CssEditor } from './modules'; +import { Events, CssEditor, Globals } from 'modules'; class BetterDiscord { constructor() { diff --git a/client/src/modules/csseditor.js b/client/src/modules/csseditor.js index 5463889a..b77c08f3 100644 --- a/client/src/modules/csseditor.js +++ b/client/src/modules/csseditor.js @@ -8,8 +8,8 @@ * LICENSE file in the root directory of this source tree. */ -import { ClientIPC } from '../../../common/modules'; -import { DOM } from '../ui'; +import { ClientIPC } from 'common'; +import { DOM } from 'ui'; export default class { diff --git a/client/src/modules/globals.js b/client/src/modules/globals.js new file mode 100644 index 00000000..ee2476b3 --- /dev/null +++ b/client/src/modules/globals.js @@ -0,0 +1,30 @@ +/** + * BetterDiscord Globals 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 Module from './module'; +import Events from './events'; +import { ClientIPC } from 'bdipc'; + +export default new class extends Module { + + constructor(args) { + super(args); + this.first(); + } + + bindings() { + this.first = this.first.bind(this); + } + + first() { + + } + +} diff --git a/client/src/modules/index.js b/client/src/modules/index.js deleted file mode 100644 index 63af24e5..00000000 --- a/client/src/modules/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as Events } from './events'; -export { default as Settings } from './settings'; -export { default as CssEditor } from './csseditor'; \ No newline at end of file diff --git a/client/src/modules/module.js b/client/src/modules/module.js new file mode 100644 index 00000000..c6750d7f --- /dev/null +++ b/client/src/modules/module.js @@ -0,0 +1,45 @@ +/** + * BetterDiscord Module Base + * Copyright (c) 2015-present JsSucks - https://github.com/JsSucks + * All rights reserved. + * https://github.com/JsSucks - 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. +*/ + +/* +Base Module that every non-static module should extend +*/ + +export default class Module { + + constructor(args) { + this.__ = { + state: args || {}, + args + } + this.setState = this.setState.bind(this); + this.init(); + } + + init() { + if (this.bindings) this.bindings(); + if (this.setInitialState) this.setInitialState(this.state); + if (this.events) this.events(); + } + + setState(newState) { + const oldState = this.state; + Object.assign(this.state, newState); + if (this.stateChanged) this.stateChanged(oldState, newState); + } + + set args(t) { } + get args() { return this.__.args; } + + + set state(state) { return this.__.state = state; } + get state() { return this.__.state; } + +} diff --git a/client/src/modules/modules.js b/client/src/modules/modules.js new file mode 100644 index 00000000..021039cb --- /dev/null +++ b/client/src/modules/modules.js @@ -0,0 +1,5 @@ +export { default as Events } from './events'; +export { default as Settings } from './settings'; +export { default as CssEditor } from './csseditor'; +export { default as PluginManager } from './pluginmanager'; +export { default as Globals } from './globals'; \ No newline at end of file diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js new file mode 100644 index 00000000..499e85aa --- /dev/null +++ b/client/src/modules/pluginmanager.js @@ -0,0 +1,21 @@ +/** + * BetterDiscord Plugin 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 Globals from './globals'; + +const localPlugins = []; + +export default class { + + static get localPlugins() { + return localPlugins; + } + +} diff --git a/client/src/ui/components/BdSettings.vue b/client/src/ui/components/BdSettings.vue index d944cbb1..85aa42e2 100644 --- a/client/src/ui/components/BdSettings.vue +++ b/client/src/ui/components/BdSettings.vue @@ -43,7 +43,7 @@