Merge plugin/theme manager errors

This commit is contained in:
Samuel Elliott 2018-02-13 16:57:05 +00:00
parent 64ac3677b1
commit 8706e9ef0f
5 changed files with 40 additions and 13 deletions

View File

@ -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');
}

View File

@ -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) {

View File

@ -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();

View File

@ -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, '\\\'')}'`};`;
}
}

View File

@ -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 = []);
}