From 8706e9ef0f9a47249fe5f6f5aa32f45738d37aa8 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Tue, 13 Feb 2018 16:57:05 +0000 Subject: [PATCH] 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 = []); }