2018-01-30 14:20:24 +01:00
|
|
|
/**
|
|
|
|
* BetterDiscord Globals Module
|
|
|
|
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
|
|
|
* All rights reserved.
|
|
|
|
* https://betterdiscord.net
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
import sparkplug from 'sparkplug';
|
2018-03-21 21:52:42 +01:00
|
|
|
import { ClientIPC } from 'common';
|
2018-01-30 14:20:24 +01:00
|
|
|
import Module from './module';
|
|
|
|
import Events from './events';
|
|
|
|
|
|
|
|
export default new class extends Module {
|
|
|
|
|
|
|
|
constructor(args) {
|
|
|
|
super(args);
|
2018-05-28 02:42:59 +02:00
|
|
|
|
2018-06-10 23:40:46 +02:00
|
|
|
// webpack replaces this with the normal require function
|
2018-05-28 05:16:41 +02:00
|
|
|
// eslint-disable-next-line no-undef
|
2018-05-28 02:42:59 +02:00
|
|
|
this.require = __non_webpack_require__;
|
2018-03-12 16:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initg() {
|
2018-01-30 14:20:24 +01:00
|
|
|
this.first();
|
|
|
|
}
|
|
|
|
|
|
|
|
bindings() {
|
|
|
|
this.first = this.first.bind(this);
|
2018-01-30 14:25:35 +01:00
|
|
|
this.setWS = this.setWS.bind(this);
|
|
|
|
this.getObject = this.getObject.bind(this);
|
2018-01-30 14:20:24 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 03:13:32 +01:00
|
|
|
async first() {
|
|
|
|
const config = await ClientIPC.send('getConfig');
|
|
|
|
this.setState({ config });
|
|
|
|
|
|
|
|
// This is for Discord to stop error reporting :3
|
|
|
|
window.BetterDiscord = {
|
|
|
|
version: config.version,
|
|
|
|
v: config.version
|
|
|
|
};
|
|
|
|
window.jQuery = {};
|
|
|
|
|
|
|
|
if (sparkplug.bd) {
|
|
|
|
this.setState({ bd: sparkplug.bd });
|
|
|
|
sparkplug.bd.setWS = this.setWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Events.emit('global-ready');
|
|
|
|
Events.emit('socket-created', this.state.wsHook);
|
2018-01-30 14:25:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setWS(wSocket) {
|
|
|
|
const state = this.state;
|
|
|
|
state.wsHook = wSocket;
|
|
|
|
this.setState(state);
|
|
|
|
Events.emit('socket-created');
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:27:39 +01:00
|
|
|
getObject(name) {
|
2018-03-20 22:11:11 +01:00
|
|
|
return this.config[name] || this.bd[name];
|
2018-01-30 14:20:24 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
get bd() {
|
|
|
|
return this.state.bd;
|
|
|
|
}
|
|
|
|
|
|
|
|
get localStorage() {
|
|
|
|
return this.bd.localStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
get webSocket() {
|
|
|
|
return this.bd.wsHook;
|
|
|
|
}
|
|
|
|
|
|
|
|
get WebSocket() {
|
|
|
|
return this.bd.wsOrig;
|
|
|
|
}
|
|
|
|
|
|
|
|
get ignited() {
|
|
|
|
return this.bd.ignited;
|
|
|
|
}
|
|
|
|
|
|
|
|
get config() {
|
|
|
|
return this.state.config;
|
|
|
|
}
|
|
|
|
|
|
|
|
get paths() {
|
|
|
|
return this.config.paths;
|
2018-03-19 17:45:20 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
getPath(id) {
|
|
|
|
return this.paths.find(path => path.id === id).path;
|
2018-03-19 17:45:20 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 22:11:11 +01:00
|
|
|
get version() {
|
|
|
|
return this.config.version;
|
2018-03-19 17:45:20 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 14:20:24 +01:00
|
|
|
}
|