BetterDiscordApp-v2/client/src/modules/globals.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

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.
*/
import Module from './module';
import Events from './events';
import { ClientIPC } from 'bdipc';
export default new class extends Module {
constructor(args) {
super(args);
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
}
first() {
2018-01-30 14:25:35 +01:00
(async() => {
const config = await ClientIPC.send('getConfig');
this.setState(config);
2018-01-30 16:59:27 +01:00
// This is for Discord to stop error reporting :3
window.BetterDiscord = {
'version': config.version,
'v': config.version
};
window.jQuery = {};
2018-02-02 13:45:06 +01:00
if (window.__bd) {
this.setState(window.__bd);
window.__bd = {
setWS: this.setWS
}
2018-01-30 14:25:35 +01:00
}
2018-02-02 13:45:06 +01:00
Events.emit('global-ready');
2018-01-30 14:25:35 +01:00
Events.emit('socket-created', this.state.wsHook);
2018-02-02 13:45:06 +01:00
})();
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-01-30 14:25:35 +01:00
return this.state[name];
2018-01-30 14:20:24 +01:00
}
}