From 64ac3677b116320f11a4a183f03aa83c2503064f Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 13 Feb 2018 16:44:07 +0000 Subject: [PATCH 01/10] Add modal manager --- client/src/modules/contentmanager.js | 5 +- .../src/styles/partials/generic/modals.scss | 13 ++++ client/src/ui/components/bd/BdModals.vue | 66 +++++++------------ .../ui/components/bd/modals/BasicModal.vue | 31 +++++++++ .../ui/components/bd/modals/ErrorModal.vue | 47 +++++++++++++ client/src/ui/modals.js | 66 +++++++++++++++++++ client/src/ui/ui.js | 1 + 7 files changed, 186 insertions(+), 43 deletions(-) create mode 100644 client/src/ui/components/bd/modals/BasicModal.vue create mode 100644 client/src/ui/components/bd/modals/ErrorModal.vue create mode 100644 client/src/ui/modals.js diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index 0659d372..22afb863 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -13,6 +13,7 @@ import { FileUtils, ClientLogger as Logger } from 'common'; import path from 'path'; import { Events } from 'modules'; import { Error } from 'structs'; +import { Modals } from 'ui'; export default class { @@ -48,8 +49,8 @@ export default class { } if (this.errors.length) { - Events.emit('bd-error', { - header: `${this.moduleName} - one or more ${this.contentType}(s) failed to load`, + Modals.error({ + header: `${this.moduleName} - ${this.errors.length} ${this.contentType}${this.errors.length !== 1 ? 's' : ''} failed to load`, module: this.moduleName, type: 'err', content: this.errors diff --git a/client/src/styles/partials/generic/modals.scss b/client/src/styles/partials/generic/modals.scss index 2ae89057..a2dca7ff 100644 --- a/client/src/styles/partials/generic/modals.scss +++ b/client/src/styles/partials/generic/modals.scss @@ -16,6 +16,19 @@ } } +.bd-modal-wrap { + transition: all 0.2s ease; + width: 100%; + height: 100%; + position: absolute; + z-index: 9000; + + .bd-modal-close-area { + width: 100%; + height: 100%; + } +} + .bd-modal { position: fixed; align-content: space-around; diff --git a/client/src/ui/components/bd/BdModals.vue b/client/src/ui/components/bd/BdModals.vue index 61e7995f..e95d9306 100644 --- a/client/src/ui/components/bd/BdModals.vue +++ b/client/src/ui/components/bd/BdModals.vue @@ -8,66 +8,50 @@ * LICENSE file in the root directory of this source tree. */ - diff --git a/client/src/ui/components/bd/modals/ErrorModal.vue b/client/src/ui/components/bd/modals/ErrorModal.vue new file mode 100644 index 00000000..8764248b --- /dev/null +++ b/client/src/ui/components/bd/modals/ErrorModal.vue @@ -0,0 +1,47 @@ + + + diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js new file mode 100644 index 00000000..7cbc1bc6 --- /dev/null +++ b/client/src/ui/modals.js @@ -0,0 +1,66 @@ +/** + * BetterDiscord Modals + * 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 { FileUtils } from 'common'; +import { Events } from 'modules'; +import BasicModal from './components/bd/modals/BasicModal.vue'; +import ErrorModal from './components/bd/modals/ErrorModal.vue'; + +export default class Modals { + + static add(modal, component) { + modal.component = modal.component || { + template: '', + components: { 'custom-modal': component }, + data() { return { modal }; }, + created() { modal.vue = this; } + }; + modal.closing = false; + modal.close = () => this.close(modal); + + this.stack.push(modal); + Events.emit('bd-refresh-modals'); + return modal; + } + + static close(modal) { + return new Promise((resolve, reject) => { + modal.closing = true; + setTimeout(() => { + this._stack = this.stack.filter(m => m !== modal); + Events.emit('bd-refresh-modals'); + resolve(); + }, 200); + }); + } + + static closeAll() { + for (let modal of this.stack) + modal.close(); + } + + static closeLast() { + if (!this.stack.length) return; + this.stack[this.stack.length - 1].close(); + } + + static basic(title, text) { + return this.add({ title, text }, BasicModal); + } + + static error(event) { + return this.add({ event }, ErrorModal); + } + + static get stack() { + return this._stack ? this._stack : (this._stack = []); + } + +} diff --git a/client/src/ui/ui.js b/client/src/ui/ui.js index e17a542e..4a24e0cb 100644 --- a/client/src/ui/ui.js +++ b/client/src/ui/ui.js @@ -1,4 +1,5 @@ export { default as DOM } from './dom'; export { default as BdUI } from './bdui'; export { default as VueInjector } from './vueinjector'; +export { default as Modals } from './modals'; export { default as ProfileBadges } from './profilebadges'; From 8706e9ef0f9a47249fe5f6f5aa32f45738d37aa8 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 13 Feb 2018 16:57:05 +0000 Subject: [PATCH 02/10] Merge plugin/theme manager errors --- client/src/index.js | 8 +++++--- client/src/modules/contentmanager.js | 6 +++--- client/src/modules/pluginmanager.js | 6 +++--- client/src/modules/thememanager.js | 12 ++++++++++-- client/src/ui/modals.js | 21 +++++++++++++++++++-- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/client/src/index.js b/client/src/index.js index 3eb55a0c..a2d778e7 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -8,7 +8,7 @@ * LICENSE file in the root directory of this source tree. */ -import { DOM, BdUI } from 'ui'; +import { DOM, BdUI, Modals } from 'ui'; import BdCss from './styles/index.scss'; import { Events, CssEditor, Globals, PluginManager, ThemeManager, ModuleManager, WebpackModules, Settings } from 'modules'; import { ClientLogger as Logger, ClientIPC } from 'common'; @@ -22,6 +22,7 @@ class BetterDiscord { window.events = Events; window.wpm = WebpackModules; window.bdsettings = Settings; + window.bdmodals = Modals; DOM.injectStyle(BdCss, 'bdmain'); Events.on('global-ready', this.globalReady.bind(this)); } @@ -29,8 +30,9 @@ class BetterDiscord { async init() { await Settings.loadSettings(); await ModuleManager.initModules(); - await PluginManager.loadAllPlugins(); - await ThemeManager.loadAllThemes(); + await PluginManager.loadAllPlugins(true); + await ThemeManager.loadAllThemes(true); + Modals.showContentManagerErrors(); Events.emit('ready'); Events.emit('discord-ready'); } diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index 22afb863..a4835847 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -29,7 +29,7 @@ export default class { return this._contentPath ? this._contentPath : (this._contentPath = Globals.getObject('paths').find(path => path.id === this.pathId).path); } - static async loadAllContent() { + static async loadAllContent(supressErrors) { try { await FileUtils.ensureDirectory(this.contentPath); const directories = await FileUtils.listDirectory(this.contentPath); @@ -48,15 +48,15 @@ export default class { } } - if (this.errors.length) { + if (this.errors.length && !supressErrors) { Modals.error({ header: `${this.moduleName} - ${this.errors.length} ${this.contentType}${this.errors.length !== 1 ? 's' : ''} failed to load`, module: this.moduleName, type: 'err', content: this.errors }); + this._errors = []; } - this._errors = []; return this.localContent; } catch (err) { diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 1b640850..1cff6af5 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -52,15 +52,15 @@ export default class extends ContentManager { } static get moduleName() { - return 'PluginManager'; + return 'Plugin Manager'; } static get pathId() { return 'plugins'; } - static async loadAllPlugins() { - const loadAll = await this.loadAllContent(); + static async loadAllPlugins(supressErrors) { + const loadAll = await this.loadAllContent(supressErrors); this.localPlugins.forEach(plugin => { if (plugin.type === 'module') return; if (plugin.enabled) plugin.start(); diff --git a/client/src/modules/thememanager.js b/client/src/modules/thememanager.js index 8cee8f98..b8bf9740 100644 --- a/client/src/modules/thememanager.js +++ b/client/src/modules/thememanager.js @@ -132,6 +132,14 @@ export default class ThemeManager extends ContentManager { return this.localContent; } + static get contentType() { + return 'theme'; + } + + static get moduleName() { + return 'Theme Manager'; + } + static get pathId() { return 'themes'; } @@ -195,11 +203,11 @@ export default class ThemeManager extends ContentManager { } if (typeof value === 'boolean' || typeof value === 'number') { - return `$${name}: ${value};`; + return `$${name}: ${value};`; } if (typeof value === 'string') { - return `$${name}: ${setting.scss_raw ? value : `'${setting.value.replace(/\\/g, '\\\\').replace(/'/g, '\\\'')}'`};`; + return `$${name}: ${setting.scss_raw ? value : `'${setting.value.replace(/\\/g, '\\\\').replace(/'/g, '\\\'')}'`};`; } } diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index 7cbc1bc6..8f1dd151 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -9,11 +9,11 @@ */ import { FileUtils } from 'common'; -import { Events } from 'modules'; +import { Events, PluginManager, ThemeManager } from 'modules'; import BasicModal from './components/bd/modals/BasicModal.vue'; import ErrorModal from './components/bd/modals/ErrorModal.vue'; -export default class Modals { +export default class { static add(modal, component) { modal.component = modal.component || { @@ -59,6 +59,23 @@ export default class Modals { return this.add({ event }, ErrorModal); } + static showContentManagerErrors() { + // Get any errors from PluginManager and ThemeManager + this.error({ + header: + (PluginManager.errors.length && ThemeManager.errors.length ? '' : + (PluginManager.errors.length ? PluginManager.moduleName : ThemeManager.moduleName) + ' - ') + + (PluginManager.errors.length ? `${PluginManager.errors.length} ${PluginManager.contentType}${PluginManager.errors.length !== 1 ? 's' : ''}` : '') + + (PluginManager.errors.length && ThemeManager.errors.length ? ' and ' : '') + + (ThemeManager.errors.length ? `${ThemeManager.errors.length} ${ThemeManager.contentType}${ThemeManager.errors.length !== 1 ? 's' : ''}` : '') + + ' failed to load', + module: (PluginManager.errors.length && ThemeManager.errors.length ? 'Content Manager' : + (PluginManager.errors.length ? PluginManager.moduleName : ThemeManager.moduleName)), + type: 'err', + content: ([]).concat(PluginManager.errors).concat(ThemeManager.errors) + }); + } + static get stack() { return this._stack ? this._stack : (this._stack = []); } From 21a8554d6f7d25cc722f5b47ba963a10d2866681 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 13 Feb 2018 17:03:51 +0000 Subject: [PATCH 03/10] =?UTF-8?q?Change=20lower=20modals=E2=80=99=20opacit?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/ui/components/bd/BdModals.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/ui/components/bd/BdModals.vue b/client/src/ui/components/bd/BdModals.vue index e95d9306..95dbc461 100644 --- a/client/src/ui/components/bd/BdModals.vue +++ b/client/src/ui/components/bd/BdModals.vue @@ -12,7 +12,7 @@
-
+
From 3b66d320e8a5ebb12caa19e63c2ee7f770d974a1 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 13 Feb 2018 17:06:09 +0000 Subject: [PATCH 04/10] Move plugin/theme settings modals to the modal manager --- client/src/ui/components/bd/PluginsView.vue | 12 +++--------- client/src/ui/components/bd/ThemesView.vue | 11 ++--------- .../bd/{ => modals}/PluginSettingsModal.vue | 16 +++++++++------- .../bd/{ => modals}/ThemeSettingsModal.vue | 14 ++++++++------ client/src/ui/modals.js | 10 ++++++++++ 5 files changed, 32 insertions(+), 31 deletions(-) rename client/src/ui/components/bd/{ => modals}/PluginSettingsModal.vue (92%) rename client/src/ui/components/bd/{ => modals}/ThemeSettingsModal.vue (92%) diff --git a/client/src/ui/components/bd/PluginsView.vue b/client/src/ui/components/bd/PluginsView.vue index 49eb7574..306bd84b 100644 --- a/client/src/ui/components/bd/PluginsView.vue +++ b/client/src/ui/components/bd/PluginsView.vue @@ -32,28 +32,26 @@
- diff --git a/client/src/ui/components/bd/ThemesView.vue b/client/src/ui/components/bd/ThemesView.vue index e4176e4f..c98f389b 100644 --- a/client/src/ui/components/bd/ThemesView.vue +++ b/client/src/ui/components/bd/ThemesView.vue @@ -32,29 +32,26 @@
- diff --git a/client/src/ui/components/bd/PluginSettingsModal.vue b/client/src/ui/components/bd/modals/PluginSettingsModal.vue similarity index 92% rename from client/src/ui/components/bd/PluginSettingsModal.vue rename to client/src/ui/components/bd/modals/PluginSettingsModal.vue index 7fd96a94..779ce746 100644 --- a/client/src/ui/components/bd/PluginSettingsModal.vue +++ b/client/src/ui/components/bd/modals/PluginSettingsModal.vue @@ -10,8 +10,7 @@