2018-01-10 21:48:10 +01:00
|
|
|
/**
|
|
|
|
* BetterDiscord Client Core
|
2018-01-29 19:15:58 +01:00
|
|
|
* 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.
|
2018-01-29 19:15:58 +01:00
|
|
|
* https://betterdiscord.net
|
2018-01-10 21:48:10 +01:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
2018-01-27 15:40:35 +01:00
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-01-10 21:48:10 +01:00
|
|
|
*/
|
|
|
|
|
2018-08-22 09:53:20 +02:00
|
|
|
import { DOM, BdUI, BdMenu, Modals, Reflection, Toasts, Notifications, BdContextMenu, DiscordContextMenu } from 'ui';
|
2018-01-29 18:34:31 +01:00
|
|
|
import BdCss from './styles/index.scss';
|
2018-08-12 17:10:22 +02:00
|
|
|
import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache } from 'modules';
|
2018-08-01 22:08:45 +02:00
|
|
|
import { ClientLogger as Logger, ClientIPC, Utils } from 'common';
|
2018-08-11 08:06:28 +02:00
|
|
|
import { BuiltinManager, EmoteModule, ReactDevtoolsModule, VueDevtoolsModule, TrackingProtection, E2EE } from 'builtin';
|
2018-03-21 01:16:42 +01:00
|
|
|
import electron from 'electron';
|
2018-03-21 16:57:10 +01:00
|
|
|
import path from 'path';
|
2018-08-20 17:30:41 +02:00
|
|
|
import { setTimeout } from 'timers';
|
2018-03-20 22:11:11 +01:00
|
|
|
|
2018-03-22 17:25:06 +01:00
|
|
|
const tests = typeof PRODUCTION === 'undefined';
|
2018-03-14 10:11:08 +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-03-22 03:19:25 +01:00
|
|
|
Logger.file = tests ? path.resolve(__dirname, '..', '..', 'tests', 'log.txt') : path.join(__dirname, 'log.txt');
|
2018-06-27 00:25:43 +02:00
|
|
|
Logger.trimLogFile();
|
2018-03-21 16:57:10 +01:00
|
|
|
Logger.log('main', 'BetterDiscord starting');
|
|
|
|
|
2018-03-16 01:54:50 +01:00
|
|
|
this._bd = {
|
2018-08-22 09:53:20 +02:00
|
|
|
DOM, BdUI, BdMenu, Modals, Reflection, Toasts, Notifications, BdContextMenu, DiscordContextMenu,
|
2018-03-20 22:11:11 +01:00
|
|
|
|
|
|
|
Events, CssEditor, Globals, Settings, Database, Updater,
|
|
|
|
ModuleManager, PluginManager, ThemeManager, ExtModuleManager,
|
2018-03-16 01:54:50 +01:00
|
|
|
Vendor,
|
2018-03-20 22:11:11 +01:00
|
|
|
|
2018-06-10 23:21:09 +02:00
|
|
|
WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi,
|
2018-03-20 22:11:11 +01:00
|
|
|
EmoteModule,
|
2018-08-06 12:31:49 +02:00
|
|
|
BdWebApi,
|
|
|
|
Connectivity,
|
2018-08-12 17:10:22 +02:00
|
|
|
Cache,
|
2018-04-13 20:50:31 +02:00
|
|
|
Logger, ClientIPC, Utils,
|
|
|
|
|
|
|
|
plugins: PluginManager.localContent,
|
|
|
|
themes: ThemeManager.localContent,
|
2018-05-28 02:42:59 +02:00
|
|
|
extmodules: ExtModuleManager.localContent,
|
|
|
|
|
|
|
|
__filename, __dirname,
|
|
|
|
module: Globals.require.cache[__filename],
|
|
|
|
require: Globals.require,
|
2018-05-28 05:16:41 +02:00
|
|
|
webpack_require: __webpack_require__, // eslint-disable-line no-undef
|
2018-05-28 02:42:59 +02:00
|
|
|
get discord_require() { return WebpackModules.require }
|
2018-03-16 01:54:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const developermode = Settings.getSetting('core', 'advanced', 'developer-mode');
|
|
|
|
if (developermode.value) window._bd = this._bd;
|
|
|
|
developermode.on('setting-updated', event => {
|
|
|
|
if (event.value) window._bd = this._bd;
|
|
|
|
else if (window._bd) delete window._bd;
|
|
|
|
});
|
2018-03-07 20:57:00 +01:00
|
|
|
|
2018-03-21 01:16:42 +01:00
|
|
|
const debuggerkeybind = Settings.getSetting('core', 'advanced', 'debugger-keybind');
|
|
|
|
debuggerkeybind.on('keybind-activated', () => {
|
|
|
|
const currentWindow = electron.remote.getCurrentWindow();
|
|
|
|
if (currentWindow.isDevToolsOpened()) return eval('debugger;');
|
|
|
|
currentWindow.openDevTools();
|
|
|
|
setTimeout(() => eval('debugger;'), 1000);
|
|
|
|
});
|
|
|
|
|
2018-01-29 18:34:31 +01:00
|
|
|
DOM.injectStyle(BdCss, 'bdmain');
|
2018-03-12 16:48:29 +01:00
|
|
|
this.globalReady = this.globalReady.bind(this);
|
|
|
|
Events.on('global-ready', this.globalReady);
|
|
|
|
Globals.initg();
|
2018-01-29 18:56:48 +01:00
|
|
|
}
|
|
|
|
|
2018-08-22 19:37:39 +02:00
|
|
|
globalReady() {
|
|
|
|
BdUI.initUiEvents();
|
|
|
|
this.vueInstance = BdUI.injectUi();
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
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();
|
2018-08-22 19:37:39 +02:00
|
|
|
BuiltinManager.initAll();
|
|
|
|
|
|
|
|
if (tests) this.initTests();
|
2018-03-20 22:11:11 +01:00
|
|
|
|
2018-03-08 07:25:51 +01:00
|
|
|
if (!ignoreExternal) {
|
|
|
|
await ExtModuleManager.loadAllModules(true);
|
|
|
|
await PluginManager.loadAllPlugins(true);
|
|
|
|
await ThemeManager.loadAllThemes(true);
|
|
|
|
}
|
2018-03-20 22:11:11 +01:00
|
|
|
|
2018-03-07 09:12:44 +01:00
|
|
|
Events.emit('ready');
|
|
|
|
Events.emit('discord-ready');
|
2018-08-20 17:30:41 +02:00
|
|
|
|
2018-08-22 19:37:39 +02:00
|
|
|
if (!Settings.get('core', 'advanced', 'ignore-content-manager-errors'))
|
|
|
|
Modals.showContentManagerErrors();
|
|
|
|
} catch (err) {
|
|
|
|
Logger.err('main', ['FAILED TO LOAD!', err]);
|
|
|
|
}
|
|
|
|
}
|
2018-08-22 11:08:56 +02:00
|
|
|
|
2018-08-22 19:37:39 +02:00
|
|
|
initTests() {
|
|
|
|
function showDummyNotif() { // eslint-disable-line no-inner-declarations
|
|
|
|
Notifications.add('Dummy Notification', [
|
2018-08-22 11:08:56 +02:00
|
|
|
{
|
2018-08-22 19:37:39 +02:00
|
|
|
text: 'Show Again', onClick: function () {
|
|
|
|
setTimeout(showDummyNotif, 5000);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Ignore', onClick: function () {
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-22 11:08:56 +02:00
|
|
|
}
|
|
|
|
]);
|
2018-03-07 09:12:44 +01:00
|
|
|
}
|
2018-08-22 19:37:39 +02:00
|
|
|
showDummyNotif();
|
2018-01-30 16:59:27 +01:00
|
|
|
|
2018-08-22 19:37:39 +02:00
|
|
|
DiscordContextMenu.add([
|
|
|
|
{
|
|
|
|
text: 'Hello',
|
|
|
|
onClick: () => { Toasts.info('Hello!'); }
|
|
|
|
}
|
|
|
|
]);
|
2018-01-25 12:03:12 +01:00
|
|
|
}
|
2018-03-16 01:54:50 +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 {
|
2018-03-20 22:11:11 +01:00
|
|
|
let instance;
|
2018-03-16 01:54:50 +01:00
|
|
|
Events.on('autopatcher', () => instance = new BetterDiscord());
|
2018-03-13 23:34:03 +01:00
|
|
|
ReactAutoPatcher.autoPatch().then(() => Events.emit('autopatcher'));
|
2018-01-29 19:15:58 +01:00
|
|
|
}
|