From ff3ef34784a584714bdb861c03ae25e382362616 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 21 Feb 2018 18:06:44 +0000 Subject: [PATCH] Show error modal when reloading content --- client/src/modules/contentmanager.js | 37 ++++++++++++++++++++++++---- client/src/ui/modals.js | 37 +++++++++++++++++----------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index f3b26d39..735fd19b 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -85,8 +85,9 @@ export default class { /** * Refresh locally stored content + * @param {bool} suppressErrors Suppress any errors that occur during loading of content */ - static async refreshContent() { + static async refreshContent(suppressErrors = false) { if (!this.localContent.length) return this.loadAllContent(); try { @@ -101,19 +102,45 @@ export default class { // Load if not await this.preloadContent(dir); } catch (err) { - //We don't want every plugin/theme to fail loading when one does + // We don't want every plugin/theme to fail loading when one does + this.errors.push(new ErrorEvent({ + module: this.moduleName, + message: `Failed to load ${dir}`, + err + })); + Logger.err(this.moduleName, err); } } for (let content of this.localContent) { if (directories.includes(content.dirName)) continue; - //Plugin/theme was deleted manually, stop it and remove any reference - this.unloadContent(content); + + try { + // Plugin/theme was deleted manually, stop it and remove any reference + await this.unloadContent(content); + } catch (err) { + this.errors.push(new ErrorEvent({ + module: this.moduleName, + message: `Failed to unload ${dir}`, + err + })); + + Logger.err(this.moduleName, err); + } + } + + if (this.errors.length && !suppressErrors) { + 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 = []; } return this.localContent; - } catch (err) { throw err; } diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index 3c6f16cd..64702d9a 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -85,22 +85,31 @@ export default class { return this.add({ event }, ErrorModal); } - static showContentManagerErrors() { + static showContentManagerErrors(clear = true) { // Get any errors from PluginManager and ThemeManager const errors = ([]).concat(PluginManager.errors).concat(ThemeManager.errors); - if (errors.length) return 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: errors - }); + if (errors.length) { + const modal = 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: errors + }); + + if (clear) { + PluginManager._errors = []; + ThemeManager._errors = []; + } + + return modal; + } } static settings(headertext, settings, schemes, settingsUpdated, settingUpdated, saveSettings) {