From 031e93185ae44a927f205c0d6dc8caa1d476a225 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Tue, 30 Jan 2018 13:14:16 +0200 Subject: [PATCH] Css editor and ipc module --- client/src/index.js | 4 +- client/src/modules/csseditor.js | 26 ++++++++ client/src/modules/index.js | 1 + client/src/ui/components/BdSettings.vue | 16 ++++- client/src/ui/components/bd/CssEditor.vue | 64 ++++++++++++++----- client/src/ui/components/bd/EmoteSettings.vue | 27 ++++++++ client/src/ui/components/bd/UISettings.vue | 27 ++++++++ client/src/ui/components/bd/index.js | 3 + client/src/ui/dom.js | 5 ++ common/modules/bdipc.js | 53 +++++++++++++++ common/modules/index.js | 1 + 11 files changed, 208 insertions(+), 19 deletions(-) create mode 100644 client/src/modules/csseditor.js create mode 100644 client/src/ui/components/bd/EmoteSettings.vue create mode 100644 client/src/ui/components/bd/UISettings.vue create mode 100644 common/modules/bdipc.js create mode 100644 common/modules/index.js diff --git a/client/src/index.js b/client/src/index.js index 073d2e15..9e7c305a 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -10,10 +10,12 @@ import { DOM, BdUI } from './ui'; import BdCss from './styles/index.scss'; -import { Events } from './modules'; +import { Events, CssEditor } from './modules'; class BetterDiscord { constructor() { + window.DOM = DOM; + window.cssEditorTest = CssEditor; DOM.injectStyle(BdCss, 'bdmain'); Events.on('global-ready', this.globalReady.bind(this)); Events.emit('global-ready'); // Emit for now diff --git a/client/src/modules/csseditor.js b/client/src/modules/csseditor.js new file mode 100644 index 00000000..0721f7aa --- /dev/null +++ b/client/src/modules/csseditor.js @@ -0,0 +1,26 @@ +/** + * BetterDiscord CSS Editor 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 { ClientIPC } from '../../../common/modules'; +import { DOM } from '../ui'; + +export default class { + + static async show() { + const t = await ClientIPC.send('openCssEditor', {}); + if (t === 1) ClientIPC.send('setCss', { css: DOM.getStyleCss('bd-customcss') }); + + ClientIPC.on('bd-update-css', this.updateCss); + } + + static updateCss(e, css) { + DOM.injectStyle(css, 'bd-customcss'); + } +} diff --git a/client/src/modules/index.js b/client/src/modules/index.js index 73d1f3df..63af24e5 100644 --- a/client/src/modules/index.js +++ b/client/src/modules/index.js @@ -1,2 +1,3 @@ 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/ui/components/BdSettings.vue b/client/src/ui/components/BdSettings.vue index 8276916f..330fed33 100644 --- a/client/src/ui/components/BdSettings.vue +++ b/client/src/ui/components/BdSettings.vue @@ -45,7 +45,7 @@ // Imports import { Settings } from '../../modules'; import { SidebarView, Sidebar, SidebarItem, ContentColumn } from './sidebar'; - import { CoreSettings } from './bd'; + import { CoreSettings, UISettings, EmoteSettings } from './bd'; import { SvgX } from './common'; // Constants @@ -79,7 +79,7 @@ }, components: { SidebarView, Sidebar, SidebarItem, ContentColumn, - CoreSettings, + CoreSettings, UISettings, EmoteSettings, SvgX }, methods: { @@ -109,6 +109,18 @@ const item = this.sidebarItems.find(item => item.contentid === s); if (!item) return false; return item.id === this.lastActiveIndex; + }, + enableSetting(cat, id) { + switch (cat) { + case 'core': + return this.coreSettings.find(setting => setting.id === id).enabled = true; + } + }, + disableSetting(cat, id) { + switch (cat) { + case 'core': + return this.coreSettings.find(setting => setting.id === id).enabled = false; + } } } } diff --git a/client/src/ui/components/bd/CssEditor.vue b/client/src/ui/components/bd/CssEditor.vue index 08f2e45d..0e8a992a 100644 --- a/client/src/ui/components/bd/CssEditor.vue +++ b/client/src/ui/components/bd/CssEditor.vue @@ -8,28 +8,60 @@ * LICENSE file in the root directory of this source tree. */ -