BetterDiscordApp-v2/client/src/index.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-01-10 21:48:10 +01:00
/**
* BetterDiscord Client Core
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
2018-01-10 21:48:10 +01:00
* All rights reserved.
* https://betterdiscord.net
2018-01-10 21:48:10 +01:00
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
2018-01-10 21:48:10 +01:00
*/
2018-02-13 17:57:05 +01:00
import { DOM, BdUI, Modals } from 'ui';
2018-01-29 18:34:31 +01:00
import BdCss from './styles/index.scss';
2018-03-12 03:38:03 +01:00
import { Events, CssEditor, Globals, ExtModuleManager, PluginManager, ThemeManager, ModuleManager, WebpackModules, Settings, Database, DiscordApi } from 'modules';
2018-02-11 15:59:55 +01:00
import { ClientLogger as Logger, ClientIPC } from 'common';
import { EmoteModule } from 'builtin';
2018-03-10 16:35:02 +01:00
const ignoreExternal = false;
2018-01-11 00:46:05 +01:00
2018-01-10 21:48:10 +01:00
class BetterDiscord {
2018-01-31 14:35:22 +01:00
2018-01-10 21:48:10 +01:00
constructor() {
2018-02-14 16:26:48 +01:00
window.discordApi = DiscordApi;
2018-03-07 09:12:44 +01:00
window.bddb = Database;
2018-02-14 21:15:27 +01:00
window.bdglobals = Globals;
2018-02-11 15:59:55 +01:00
window.ClientIPC = ClientIPC;
2018-02-07 17:02:27 +01:00
window.css = CssEditor;
window.pm = PluginManager;
window.tm = ThemeManager;
2018-02-02 13:45:06 +01:00
window.events = Events;
window.wpm = WebpackModules;
2018-02-12 16:19:11 +01:00
window.bdsettings = Settings;
2018-02-13 17:57:05 +01:00
window.bdmodals = Modals;
2018-02-15 18:00:21 +01:00
window.bdlogs = Logger;
window.emotes = EmoteModule;
2018-03-08 16:37:38 +01:00
window.dom = DOM;
2018-01-29 18:34:31 +01:00
DOM.injectStyle(BdCss, 'bdmain');
2018-01-29 18:56:48 +01:00
Events.on('global-ready', this.globalReady.bind(this));
}
2018-01-30 16:59:27 +01:00
async init() {
2018-03-07 09:12:44 +01:00
try {
await Database.init();
await Settings.loadSettings();
await ModuleManager.initModules();
Modals.showContentManagerErrors();
if (!ignoreExternal) {
await ExtModuleManager.loadAllModules(true);
await PluginManager.loadAllPlugins(true);
await ThemeManager.loadAllThemes(true);
}
if (!Settings.get('core', 'advanced', 'ignore-content-manager-errors'))
Modals.showContentManagerErrors();
2018-03-07 09:12:44 +01:00
Events.emit('ready');
Events.emit('discord-ready');
2018-03-10 04:05:12 +01:00
EmoteModule.observe();
2018-03-07 09:12:44 +01:00
} catch (err) {
Logger.err('main', ['FAILED TO LOAD!', err]);
2018-03-07 09:12:44 +01:00
}
2018-01-30 16:59:27 +01:00
}
2018-01-29 18:56:48 +01:00
globalReady() {
2018-01-31 16:45:25 +01:00
BdUI.initUiEvents();
2018-01-29 19:00:31 +01:00
this.vueInstance = BdUI.injectUi();
this.init();
2018-01-25 12:03:12 +01:00
}
2018-01-10 21:48:10 +01:00
}
2018-01-11 00:07:35 +01:00
if (window.BetterDiscord) {
2018-01-11 07:02:11 +01:00
Logger.log('main', 'Attempting to inject again?');
2018-01-11 00:07:35 +01:00
} else {
let bdInstance = new BetterDiscord();
}