2018-01-10 20:19:34 +01:00
|
|
|
|
/**
|
|
|
|
|
* BetterDiscord Core Entry
|
|
|
|
|
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
* https://github.com/JsSucks - 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-01-10 23:15:31 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DEVELOPMENT VARIABLES
|
|
|
|
|
*/
|
|
|
|
|
const __DEV = {
|
2018-01-10 23:41:57 +01:00
|
|
|
|
TESTING: false,
|
|
|
|
|
clientScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js"
|
2018-01-10 23:15:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules');
|
|
|
|
|
const { BrowserWindow } = require('electron');
|
2018-01-10 17:02:29 +01:00
|
|
|
|
|
|
|
|
|
const Common = {};
|
|
|
|
|
|
|
|
|
|
const dummyArgs = {
|
|
|
|
|
'version': '0.3.1',
|
|
|
|
|
'paths': [
|
|
|
|
|
{ 'base': 'basePath' },
|
|
|
|
|
{ 'plugins': 'pluginsPath' },
|
|
|
|
|
{ 'themes': 'themesPath' }
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Comms {
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.initListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initListeners() {
|
|
|
|
|
BDIpc.on('bd-getConfig', o => {
|
|
|
|
|
o.reply(Common.Config.config);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BDIpc.on('bd-readFile', this.readFile);
|
|
|
|
|
BDIpc.on('bd-readJson', o => this.readFile(o, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async readFile(o, json) {
|
|
|
|
|
const { path } = o.args;
|
|
|
|
|
try {
|
|
|
|
|
const readFile = json ? await FileUtils.readJsonFromFile(path) : await FileUtils.readFile(path);
|
|
|
|
|
o.reply(readFile);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
o.reply(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BetterDiscord {
|
|
|
|
|
|
|
|
|
|
constructor(args) {
|
2018-01-10 23:41:57 +01:00
|
|
|
|
this.injectScripts = this.injectScripts.bind(this);
|
2018-01-10 17:02:29 +01:00
|
|
|
|
Common.Config = new Config(args || dummyArgs);
|
|
|
|
|
this.comms = new Comms();
|
2018-01-10 23:15:31 +01:00
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
|
const window = await this.waitForWindow();
|
|
|
|
|
this.windowUtils = new WindowUtils({ window });
|
2018-01-10 23:41:57 +01:00
|
|
|
|
|
|
|
|
|
this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true));
|
|
|
|
|
|
2018-01-10 23:15:31 +01:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (__DEV) {
|
2018-01-10 23:41:57 +01:00
|
|
|
|
this.<EFBFBD>njectScripts();
|
2018-01-10 23:15:31 +01:00
|
|
|
|
}
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async waitForWindow() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const defer = setInterval(() => {
|
|
|
|
|
const windows = BrowserWindow.getAllWindows();
|
|
|
|
|
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
|
|
|
|
resolve(windows[0]);
|
|
|
|
|
clearInterval(defer);
|
|
|
|
|
return;
|
2018-01-10 23:41:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (windows.length === 1 && windows[0].webContents.getURL().includes("discordapp.com")) {
|
2018-01-10 23:15:31 +01:00
|
|
|
|
resolve(windows[0]);
|
|
|
|
|
clearInterval(defer);
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
});
|
2018-01-10 17:02:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 23:41:57 +01:00
|
|
|
|
injectScripts(reload) {
|
|
|
|
|
if (__DEV) {
|
|
|
|
|
this.windowUtils.injectScript(__DEV.clientScriptPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 17:02:29 +01:00
|
|
|
|
get fileUtils() { return FileUtils; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
BetterDiscord
|
|
|
|
|
}
|