From 994faf94d6cbbed0fe1deb94a0aaad0612b5173a Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 20 Mar 2018 21:11:11 +0000 Subject: [PATCH] Refactor Vue injector and sparkplug and move contributors to data --- client/package.json | 3 - client/src/builtin/EmoteComponent.vue | 5 +- client/src/builtin/EmoteModule.js | 11 ++-- client/src/data/contributors.json | 65 +++++++++++++++++++ client/src/data/user.settings.default.json | 1 - client/src/index.js | 40 +++++------- client/src/modules/globals.js | 57 +++++++++++----- client/src/modules/modulemanager.js | 8 ++- client/src/modules/modules.js | 22 ++++--- client/src/ui/automanip.js | 24 +++---- client/src/ui/components/bd/BdBadge.vue | 8 +-- .../src/ui/components/bd/BdMessageBadge.vue | 6 +- .../src/ui/components/common/Autocomplete.vue | 3 +- client/src/ui/profilebadges.js | 56 ++++++---------- client/src/ui/vueinjector.js | 13 +++- client/webpack.config.js | 7 +- core/src/sparkplug.js | 26 ++++++-- 17 files changed, 219 insertions(+), 136 deletions(-) create mode 100644 client/src/data/contributors.json diff --git a/client/package.json b/client/package.json index 6e536f09..aee1ddf3 100644 --- a/client/package.json +++ b/client/package.json @@ -15,9 +15,6 @@ "url": "https://github.com/Jiiks/BetterDiscordApp.git" }, "private": false, - "devDependencies": { - - }, "scripts": { "build": "webpack --progress --colors", "watch": "webpack --progress --colors --watch" diff --git a/client/src/builtin/EmoteComponent.vue b/client/src/builtin/EmoteComponent.vue index 3561ad70..98cd63a1 100644 --- a/client/src/builtin/EmoteComponent.vue +++ b/client/src/builtin/EmoteComponent.vue @@ -9,11 +9,10 @@ data() { return { favourite: false - } + }; }, props: ['src', 'name'], - methods: { - }, + methods: {}, beforeMount() { // Check favourite state } diff --git a/client/src/builtin/EmoteModule.js b/client/src/builtin/EmoteModule.js index 0a02c41a..7c901607 100644 --- a/client/src/builtin/EmoteModule.js +++ b/client/src/builtin/EmoteModule.js @@ -131,12 +131,11 @@ export default class { } const { bdemoteName, bdemoteSrc } = root.dataset; if (!bdemoteName || !bdemoteSrc) return; - VueInjector.inject( - root, - DOM.createElement('span'), - { EmoteComponent }, - `` - ); + VueInjector.inject(root, { + components: { EmoteComponent }, + data: { src: bdemoteSrc, name: bdemoteName }, + template: '' + }, DOM.createElement('span')); root.classList.add('bd-is-emote'); } diff --git a/client/src/data/contributors.json b/client/src/data/contributors.json new file mode 100644 index 00000000..bcdd89ec --- /dev/null +++ b/client/src/data/contributors.json @@ -0,0 +1,65 @@ +[ + { + "__user": "Jiiks#5000", + "id": "81388395867156480", + "developer": true, + "webdev": true, + "contributor": true + }, + { + "__user": "Pohky#0156", + "id": "98003542823944192", + "developer": true, + "webdev": false, + "contributor": true + }, + { + "__user": "Hammock#3110", + "id": "138850472541814784", + "developer": false, + "webdev": true, + "contributor": true + }, + { + "__user": "Zerebos#7790", + "id": "249746236008169473", + "developer": true, + "webdev": false, + "contributor": true + }, + { + "__user": "Pierce#1337", + "id": "125367412370440192", + "developer": true, + "webdev": false, + "contributor": true + }, + { + "__user": "Samuel Elliott#2764", + "id": "284056145272766465", + "developer": true, + "webdev": false, + "contributor": true + }, + { + "__user": "Lilian Tedone#6223", + "id": "184021060562321419", + "developer": false, + "webdev": false, + "contributor": true + }, + { + "__user": "samfun123#8972", + "id": "76052829285916672", + "developer": false, + "webdev": false, + "contributor": true + }, + { + "__user": "samogot#4379", + "id": "171005991272316937", + "developer": false, + "webdev": false, + "contributor": true + } +] diff --git a/client/src/data/user.settings.default.json b/client/src/data/user.settings.default.json index 49efdfdc..2b49c23a 100644 --- a/client/src/data/user.settings.default.json +++ b/client/src/data/user.settings.default.json @@ -91,7 +91,6 @@ { "id": "css", "text": "CSS Editor", - "hidden": true, "settings": [ { "category": "default", diff --git a/client/src/index.js b/client/src/index.js index 94307dc5..f7a74b6e 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -10,9 +10,10 @@ import { DOM, BdUI, Modals, Reflection } from 'ui'; import BdCss from './styles/index.scss'; -import { Patcher, MonkeyPatch, Vendor, Events, CssEditor, Globals, ExtModuleManager, PluginManager, ThemeManager, ModuleManager, WebpackModules, Settings, Database, ReactComponents, ReactAutoPatcher, DiscordApi } from 'modules'; +import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactAutoPatcher, DiscordApi } from 'modules'; import { ClientLogger as Logger, ClientIPC, Utils } from 'common'; import { EmoteModule } from 'builtin'; + const ignoreExternal = false; const DEV = true; @@ -20,29 +21,16 @@ class BetterDiscord { constructor() { this._bd = { - DOM, - BdUI, - Modals, - Reflection, - Patcher, - MonkeyPatch, + DOM, BdUI, Modals, Reflection, + + Events, CssEditor, Globals, Settings, Database, Updater, + ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, - Events, - CssEditor, - Globals, - ExtModuleManager, - PluginManager, - ThemeManager, - ModuleManager, - WebpackModules, - Settings, - Database, - ReactComponents, - DiscordApi, - Logger, - ClientIPC, - Utils, - EmoteModule + + WebpackModules, Patcher, MonkeyPatch, ReactComponents, DiscordApi, + EmoteModule, + + Logger, ClientIPC, Utils }; const developermode = Settings.getSetting('core', 'advanced', 'developer-mode'); @@ -63,14 +51,16 @@ class BetterDiscord { await Database.init(); await Settings.loadSettings(); await ModuleManager.initModules(); - Modals.showContentManagerErrors(); + if (!ignoreExternal) { await ExtModuleManager.loadAllModules(true); await PluginManager.loadAllPlugins(true); await ThemeManager.loadAllThemes(true); } + if (!Settings.get('core', 'advanced', 'ignore-content-manager-errors')) Modals.showContentManagerErrors(); + Events.emit('ready'); Events.emit('discord-ready'); EmoteModule.observe(); @@ -90,7 +80,7 @@ class BetterDiscord { if (window.BetterDiscord) { Logger.log('main', 'Attempting to inject again?'); } else { - let instance = null; + let instance; Events.on('autopatcher', () => instance = new BetterDiscord()); ReactAutoPatcher.autoPatch().then(() => Events.emit('autopatcher')); } diff --git a/client/src/modules/globals.js b/client/src/modules/globals.js index 50b3dbb8..4971ec2a 100644 --- a/client/src/modules/globals.js +++ b/client/src/modules/globals.js @@ -8,9 +8,10 @@ * LICENSE file in the root directory of this source tree. */ +import sparkplug from 'sparkplug'; +import { ClientIPC } from 'bdipc'; import Module from './module'; import Events from './events'; -import { ClientIPC } from 'bdipc'; export default new class extends Module { @@ -31,20 +32,18 @@ export default new class extends Module { first() { (async() => { const config = await ClientIPC.send('getConfig'); - this.setState(config); + this.setState({ config }); // This is for Discord to stop error reporting :3 window.BetterDiscord = { - 'version': config.version, - 'v': config.version + version: config.version, + v: config.version }; window.jQuery = {}; - if (window.__bd) { - this.setState(window.__bd); - window.__bd = { - setWS: this.setWS - } + if (sparkplug.bd) { + this.setState({ bd: sparkplug.bd }); + sparkplug.bd.setWS = this.setWS; } Events.emit('global-ready'); @@ -60,19 +59,43 @@ export default new class extends Module { } getObject(name) { - return this.state[name]; + return this.config[name] || this.bd[name]; + } + + get bd() { + return this.state.bd; + } + + get localStorage() { + return this.bd.localStorage; + } + + get webSocket() { + return this.bd.wsHook; + } + + get WebSocket() { + return this.bd.wsOrig; + } + + get ignited() { + return this.bd.ignited; + } + + get config() { + return this.state.config; + } + + get paths() { + return this.config.paths; } getPath(id) { - return this.state.paths.find(path => path.id === id).path; + return this.paths.find(path => path.id === id).path; } - static get paths() { - return this.state.paths; - } - - static get version() { - return this.state.version; + get version() { + return this.config.version; } } diff --git a/client/src/modules/modulemanager.js b/client/src/modules/modulemanager.js index 209f32bf..c1f69d51 100644 --- a/client/src/modules/modulemanager.js +++ b/client/src/modules/modulemanager.js @@ -8,12 +8,14 @@ * LICENSE file in the root directory of this source tree. */ -/*Module Manager initializes all modules when everything is ready*/ - +import { ClientLogger as Logger } from 'common'; import { Events, SocketProxy, EventHook, CssEditor } from 'modules'; import { ProfileBadges } from 'ui'; import Updater from './updater'; +/** + * Module Manager initializes all modules when everything is ready + */ export default class { static get modules() { @@ -31,7 +33,7 @@ export default class { try { if (module.init && module.init instanceof Function) module.init(); } catch (err) { - console.log(`Failed to initialize module: ${err}`); + Logger.err('Module Manager', ['Failed to initialize module:', err]); } } return true; diff --git a/client/src/modules/modules.js b/client/src/modules/modules.js index 8bd1b7eb..f885fcdb 100644 --- a/client/src/modules/modules.js +++ b/client/src/modules/modules.js @@ -1,19 +1,23 @@ 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 Globals } from './globals'; +export { default as Settings } from './settings'; +export { default as Database } from './database'; +export { default as Updater } from './updater'; + +export { default as ModuleManager } from './modulemanager'; export { default as PluginManager } from './pluginmanager'; export { default as ThemeManager } from './thememanager'; -export { default as Globals } from './globals'; +export { default as ExtModuleManager } from './extmodulemanager'; +export { default as Permissions } from './permissionmanager'; + +export { default as EventsWrapper } from './eventswrapper'; export { default as Vendor } from './vendor'; + export * from './webpackmodules'; -export { default as ModuleManager } from './modulemanager'; +export * from './patcher'; +export * from './reactcomponents'; export { default as EventListener } from './eventlistener'; export { default as SocketProxy } from './socketproxy'; export { default as EventHook } from './eventhook'; -export { default as Permissions } from './permissionmanager'; -export { default as Database } from './database'; -export { default as EventsWrapper } from './eventswrapper'; export { default as DiscordApi } from './discordapi'; -export * from './patcher'; -export * from './reactcomponents'; diff --git a/client/src/ui/automanip.js b/client/src/ui/automanip.js index 0eb69629..7331f66c 100644 --- a/client/src/ui/automanip.js +++ b/client/src/ui/automanip.js @@ -128,13 +128,11 @@ export default class extends EventListener { if (markup.ets) { const etsRoot = document.createElement('span'); markup.clone.appendChild(etsRoot); - VueInjector.inject( - etsRoot, - DOM.createElement('span', null, 'test'), - { EditedTimeStamp }, - ``, - true - ); + VueInjector.inject(etsRoot, { + components: { EditedTimeStamp }, + data: { ets: markup.ets }, + template: '' + }); } Events.emit('ui:mutable:.markup', markup.clone); @@ -214,12 +212,10 @@ export default class extends EventListener { const parent = document.querySelector('[class*="channelTextArea"] > [class*="inner"]'); if (!parent) return; parent.append(root); - VueInjector.inject( - root, - DOM.createElement('span'), - { Autocomplete }, - ``, - true - ); + VueInjector.inject(root, { + components: { Autocomplete }, + data: { initial: e.target.value }, + template: '' + }); } } diff --git a/client/src/ui/components/bd/BdBadge.vue b/client/src/ui/components/bd/BdBadge.vue index 2c82a62d..969f8692 100644 --- a/client/src/ui/components/bd/BdBadge.vue +++ b/client/src/ui/components/bd/BdBadge.vue @@ -9,11 +9,11 @@ */ diff --git a/client/src/ui/components/bd/BdMessageBadge.vue b/client/src/ui/components/bd/BdMessageBadge.vue index c4258d5b..29e88adc 100644 --- a/client/src/ui/components/bd/BdMessageBadge.vue +++ b/client/src/ui/components/bd/BdMessageBadge.vue @@ -10,9 +10,9 @@