From ba0ba4b2cec475c4766e66c66e2411a184354dbf Mon Sep 17 00:00:00 2001 From: Jiiks Date: Wed, 10 Jan 2018 22:25:27 +0200 Subject: [PATCH] Base module --- core/src/modules/bdipc.js | 11 ++++------- core/src/modules/config.js | 6 ++---- core/src/modules/modulebase.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 core/src/modules/modulebase.js diff --git a/core/src/modules/bdipc.js b/core/src/modules/bdipc.js index 5215997c..c9fd7d46 100644 --- a/core/src/modules/bdipc.js +++ b/core/src/modules/bdipc.js @@ -7,17 +7,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +const { Module } = require('./modulebase'); const { ipcMain } = require('electron'); -class BDIpcEvent { +class BDIpcEvent extends Module { constructor(event, args) { - this.bindings(); + super(args); this.ipcEvent = event; - this.args = args; - this.__eid = args.__eid; - delete this.args.__eid; } bindings() { @@ -26,8 +24,7 @@ class BDIpcEvent { } send(message) { - console.log(this.__eid); - this.ipcEvent.sender.send(this.__eid, message); + this.ipcEvent.sender.send(this.args.__eid, message); } reply(message) { diff --git a/core/src/modules/config.js b/core/src/modules/config.js index 4f1cd5dc..cb73e865 100644 --- a/core/src/modules/config.js +++ b/core/src/modules/config.js @@ -8,11 +8,9 @@ * LICENSE file in the root directory of this source tree. */ -class Config { +const { Module } = require('./modulebase'); - constructor(args) { - this.args = args; - } +class Config extends Module { get version() { return this.args.version; diff --git a/core/src/modules/modulebase.js b/core/src/modules/modulebase.js new file mode 100644 index 00000000..42ad1b07 --- /dev/null +++ b/core/src/modules/modulebase.js @@ -0,0 +1,34 @@ +/** + * 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*/ + +class Module { + + constructor(args) { + this.__ = { + state: args, + args + } + this.init(); + } + + init() { + if (this.bindings) this.bindings(); + if (this.setInitialState) this.setInitialState(this.state); + } + + set args(t) {} + get args() { return this.__.args; } + get state() { return this.__.state; } + +} + +module.exports = { Module }; \ No newline at end of file