BetterDiscordApp-v1/lib/BetterDiscord.js

96 lines
3.5 KiB
JavaScript
Raw Normal View History

2015-08-28 09:52:36 +02:00
/* BetterDiscordApp Entry
2015-08-30 12:11:02 +02:00
* Version: 1.2
2015-08-28 09:52:36 +02:00
* Author: Jiiks | http://jiiks.net
* Date: 27/08/2015 - 15:51
2015-08-30 12:11:02 +02:00
* Last Update: 30/08/2015 - 13:10
2015-08-28 09:52:36 +02:00
* https://github.com/Jiiks/BetterDiscordApp
*/
2015-08-27 14:38:54 +02:00
2015-08-28 09:52:36 +02:00
var _config = require("./config.json");
var _utils = require("./utils");
2015-08-29 21:20:11 +02:00
var _version;
2015-08-28 09:52:36 +02:00
var _mainWindow;
2015-08-29 21:20:11 +02:00
var _updater;
var _hash;
2015-08-28 09:52:36 +02:00
function BetterDiscord(mainWindow) {
_mainWindow = mainWindow;
2015-08-29 21:20:11 +02:00
_version = _config.Core.Version;
2015-08-28 09:52:36 +02:00
_utils = new _utils.Utils(mainWindow);
}
BetterDiscord.prototype.getUtils = function() {
return _utils;
2015-08-27 14:38:54 +02:00
}
BetterDiscord.prototype.init = function() {
2015-08-28 09:52:36 +02:00
var self = this;
2015-08-29 21:20:11 +02:00
//Get latest commit hash
this.getUtils().getHash(function(hash) {
_hash = hash;
self.getUtils().log("Latest Hash: " + _hash);
//Get updater
self.getUtils().download("raw.githubusercontent.com", "/Jiiks/BetterDiscordApp/"+hash+"/updater.json", function(updater) {
_updater = JSON.parse(updater);
self.getUtils().log("Latest Version: " + _updater.LatestVersion);
self.getUtils().log("CDN: " + _updater.CDN);
self.start();
});
});
return;
2015-08-27 14:38:54 +02:00
}
2015-08-29 21:20:11 +02:00
BetterDiscord.prototype.start = function() {
var self = this;
this.getUtils().log(" v" + _version + " Initialized");
if(_updater.LatestVersion > _version) {
this.getUtils().log("Update available!");
}
//Event handlers
self.getUtils().getWebContents().on('did-finish-load', function() {
});
self.getUtils().getWebContents().on('dom-ready', function() {
if(_updater.LatestVersion > _version) self.getUtils().execJs('alert("An update for BetterDiscord is available(v'+ _updater.LatestVersion +')! Download the latest version from GitHub!")');
2015-08-29 21:20:11 +02:00
//Version var
self.getUtils().execJs('var version = "'+_version+'"');
//Load jquery
self.getUtils().injectJavaScript("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js");
//CSS
self.getUtils().execJs('function injectMainCss() { $(\'head\').append( \'<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/\/'+_updater.CDN+'\/Jiiks\/BetterDiscordApp\/'+_hash+'\/css\/main.min.css\">\' ) }');
self.getUtils().execJs('var deferCount = 0; function defer() { if(window.jQuery) { injectMainCss() } else { setTimeout( function() { if(deferCount < 100) { deferCount++; defer(); } else { alert("BetterDiscord failed to load :( try restarting Discord. code:0x01"); } }, 100 ); } } deferCount = 0; defer();');
self.getUtils().injectJavaScript("//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js", true);
2015-08-31 15:20:33 +02:00
self.getUtils().injectJavaScript("//" + _updater.CDN + "/Jiiks/BetterDiscordApp/"+_hash+"/js/main.min.js", true);
2015-08-30 12:11:02 +02:00
2015-08-30 12:36:12 +02:00
self.getUtils().download(_updater.CDN , "/Jiiks/BetterDiscordApp/"+_hash+"/emotedata_twitch.json", function(emotedata) {
self.getUtils().execJs('var emotesTwitch = JSON.parse(\''+emotedata+'\');');
self.getUtils().download(_updater.CDN , "/Jiiks/BetterDiscordApp/"+_hash+"/emotedata_ffz.json", function(emotedata) {
2015-08-31 15:45:14 +02:00
self.getUtils().execJs('var emotesFfz = JSON.parse(\''+emotedata+'\');');
2015-08-30 12:36:12 +02:00
});
2015-08-30 12:11:02 +02:00
});
2015-08-29 21:20:11 +02:00
//Start BDA
2015-08-31 15:36:28 +02:00
self.getUtils().execJs('var mainCore; var startBda = function() { mainCore = new Core(); mainCore.init(); }');
2015-08-29 21:20:11 +02:00
self.getUtils().execJs("function startDefer() { if(window.Core && window.jQuery && $.cookie){ startBda(); } else { setTimeout(function() { startDefer(); }, 100) } } startDefer(); ")
});
}
2015-08-28 09:52:36 +02:00
exports.BetterDiscord = BetterDiscord;