2016-10-31 16:36:03 +01:00
|
|
|
/* BetterDiscordApp Core
|
|
|
|
* Version: 2:1.0
|
|
|
|
* Author: Jiiks | https://jiiks.net
|
|
|
|
* Date: 31/10/2016
|
|
|
|
* Last Update: 31/10/2016
|
|
|
|
* Github: https://github.com/Jiiks/BetterDiscordApp
|
|
|
|
* Git: https://github.com/Jiiks/BetterDiscordApp.git
|
|
|
|
* License: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const
|
|
|
|
_fs = require('fs'),
|
|
|
|
_config = require('./config.json'),
|
2016-10-31 17:05:51 +01:00
|
|
|
{ _utils } = require('./utils'),
|
|
|
|
{ _logger } = require('./utils'),
|
|
|
|
{ EOL } = require('os'),
|
2016-10-31 16:57:12 +01:00
|
|
|
_os = require('os');
|
2016-10-31 16:36:03 +01:00
|
|
|
|
|
|
|
const _startDate = new Date();
|
|
|
|
|
|
|
|
var _cfg;
|
|
|
|
|
2016-10-31 17:05:51 +01:00
|
|
|
// Default configs if for some reason we don't receive config params
|
2016-10-31 16:57:12 +01:00
|
|
|
const _defaults = {
|
|
|
|
installPath: (_os.platform() === 'win32' ? process.env.APPDATA : _os.platform() === 'darwin' ? `${process.env.HOME}/Library/Preferences`: `/var/local`) + '/BetterDiscord/lib/',
|
|
|
|
dataPath: (_os.platform() === 'win32' ? process.env.APPDATA : _os.platform() === 'darwin' ? `${process.env.HOME}/Library/Preferences`: `/var/local`) + '/BetterDiscord/data/',
|
|
|
|
emotesEnabled: true
|
|
|
|
};
|
2016-10-31 16:36:03 +01:00
|
|
|
|
2016-10-31 19:33:04 +01:00
|
|
|
const _resources = {
|
|
|
|
"mainjs": {
|
|
|
|
"path": "js",
|
|
|
|
"filename": "main.js",
|
|
|
|
"var": "window.BetterDiscord"
|
|
|
|
},
|
|
|
|
"jQuery": {
|
|
|
|
"path": "vendor",
|
|
|
|
"filename": "jquery-2.2.4.min.js",
|
2016-11-02 06:38:32 +01:00
|
|
|
"var": "window.$ = window.jQuery"
|
2016-10-31 19:33:04 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var _self;
|
|
|
|
|
2016-10-31 16:36:03 +01:00
|
|
|
class Core {
|
|
|
|
|
|
|
|
constructor(args) {
|
2016-10-31 19:33:04 +01:00
|
|
|
_self = this;
|
2016-10-31 17:05:51 +01:00
|
|
|
this.continue = true;
|
|
|
|
_logger.log(`v${this.__version} Loading - OS: ${_os.platform()}`);
|
2016-10-31 16:57:12 +01:00
|
|
|
this.initConfig(args.cfg);
|
2016-10-31 16:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initConfig(args) {
|
2016-10-31 16:57:12 +01:00
|
|
|
_cfg = _config.cfg;
|
|
|
|
_cfg.installPath = args.installPath || _defaults.installPath;
|
|
|
|
_cfg.dataPath = args.dataPath || _defaults.dataPath;
|
|
|
|
_cfg.emotesEnabled = args.emotesEnabled || _defaults.emotesEnabled;
|
2016-10-31 16:36:03 +01:00
|
|
|
}
|
|
|
|
|
2016-10-31 17:05:51 +01:00
|
|
|
hook(mainWindow) {
|
|
|
|
if(mainWindow === undefined) {
|
|
|
|
this.exit("mainWindow is undefined!");
|
|
|
|
return;
|
|
|
|
}
|
2016-10-31 17:40:55 +01:00
|
|
|
this.mainWindow = mainWindow;
|
|
|
|
this.hookEvent('dom-ready', this.domReady);
|
|
|
|
}
|
|
|
|
|
|
|
|
hookEvent(event, callback) {
|
|
|
|
if(!this.continue) return;
|
|
|
|
try {
|
|
|
|
_logger.log(`Hooking ${event}`);
|
|
|
|
this.mainWindow.webContents.on(event, callback);
|
|
|
|
}catch(err) {
|
|
|
|
this.exit(`Failed to hook event ${event}. Reason: ${err}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
domReady() {
|
2016-10-31 19:33:04 +01:00
|
|
|
for(var key in _resources) {
|
|
|
|
var resource = _resources[key];
|
2016-11-01 04:42:15 +01:00
|
|
|
_utils.requireJs(`${_cfg.installPath}/${resource.path}/${resource.filename}`, resource.var, _self.mainWindow);
|
2016-10-31 19:33:04 +01:00
|
|
|
}
|
2016-11-01 04:42:15 +01:00
|
|
|
|
|
|
|
_self.pluginLoader();
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginLoader() {
|
|
|
|
|
2016-10-31 17:05:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit(reason, severity) {
|
|
|
|
this.continue = false;
|
|
|
|
// TODO show an actual error dialog for user
|
|
|
|
_logger.log(`Quitting. Reason: ${reason}`, severity || 2);
|
|
|
|
_logger.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
get __version() {
|
|
|
|
return _config.core.version;
|
|
|
|
}
|
|
|
|
|
2016-10-31 16:36:03 +01:00
|
|
|
}
|
|
|
|
|
2016-10-31 17:40:55 +01:00
|
|
|
exports.BetterDiscord = Core;
|