This commit is contained in:
Jiiks 2016-03-30 04:37:03 +03:00
parent 2e914032ed
commit 51b1913ab1
4 changed files with 157 additions and 66 deletions

View File

@ -1,8 +1,8 @@
/* BetterDiscordApp Entry /* BetterDiscordApp Entry
* Version: 2.1 * Version: 2.2
* Author: Jiiks | http://jiiks.net * Author: Jiiks | http://jiiks.net
* Date: 27/08/2015 - 15:51 * Date: 27/08/2015 - 15:51
* Last Update: 10/02/2015 - 02:05 GMT * Last Update: 30/03/2016
* https://github.com/Jiiks/BetterDiscordApp * https://github.com/Jiiks/BetterDiscordApp
*/ */
@ -36,7 +36,7 @@ var _dataPath;
//IDE //IDE
/*_config = { /*_config = {
"Core": { "Core": {
"Version": "0.2.5" "Version": "0.2.7"
} }
};*/ };*/
@ -60,24 +60,24 @@ BetterDiscord.prototype.initLoaders = function(){
_dataPath += "/BetterDiscord/"; _dataPath += "/BetterDiscord/";
if (!_fs.existsSync(_dataPath)) { if (!_fs.existsSync(_dataPath)) {
console.log('BetterDiscord: Creating BD Dir'); _this.getUtils().log('BetterDiscord: Creating BD Dir');
_fs.mkdirSync(_dataPath); _fs.mkdirSync(_dataPath);
} }
if (!_fs.existsSync(_dataPath + "plugins/")) { if (!_fs.existsSync(_dataPath + "plugins/")) {
console.log('BetterDiscord: Creating Plugins Dir'); _this.getUtils().log('BetterDiscord: Creating Plugins Dir');
_fs.mkdirSync(_dataPath + "plugins/"); _fs.mkdirSync(_dataPath + "plugins/");
} }
if (!_fs.existsSync(_dataPath + "themes/")) { if (!_fs.existsSync(_dataPath + "themes/")) {
console.log('BetterDiscord: Creating Themes Dir'); _this.getUtils().log('BetterDiscord: Creating Themes Dir');
_fs.mkdirSync(_dataPath + "themes/"); _fs.mkdirSync(_dataPath + "themes/");
} }
_mainWindow.webContents.executeJavaScript('var themesupport2 = true'); _mainWindow.webContents.executeJavaScript('var themesupport2 = true');
_fs.readdir(_dataPath + "plugins/", function(err, files) { _fs.readdir(_dataPath + "plugins/", function(err, files) {
if (err) { if (err) {
console.log(err); _this.getUtils().log(err);
return; return;
} }
_mainWindow.webContents.executeJavaScript('var bdplugins = {};'); _mainWindow.webContents.executeJavaScript('var bdplugins = {};');
@ -85,13 +85,13 @@ BetterDiscord.prototype.initLoaders = function(){
var plugin = _fs.readFileSync(_dataPath + "plugins/" + fileName, 'utf8'); var plugin = _fs.readFileSync(_dataPath + "plugins/" + fileName, 'utf8');
var meta = plugin.split('\n')[0]; var meta = plugin.split('\n')[0];
if (meta.indexOf('META') < 0) { if (meta.indexOf('META') < 0) {
console.log('BetterDiscord: ERROR[Plugin META not found in file: ' + fileName + ']'); _this.getUtils().log('BetterDiscord: ERROR[Plugin META not found in file: ' + fileName + ']');
return; return;
} }
var pluginVar = meta.substring(meta.lastIndexOf('//META') + 6, meta.lastIndexOf('*//')); var pluginVar = meta.substring(meta.lastIndexOf('//META') + 6, meta.lastIndexOf('*//'));
var parse = JSON.parse(pluginVar); var parse = JSON.parse(pluginVar);
var pluginName = parse['name']; var pluginName = parse['name'];
console.log('BetterDiscord: Loading Plugin: ' + pluginName); _this.getUtils().log('BetterDiscord: Loading Plugin: ' + pluginName);
_mainWindow.webContents.executeJavaScript(plugin); _mainWindow.webContents.executeJavaScript(plugin);
_mainWindow.webContents.executeJavaScript('(function() { var plugin = new ' + pluginName + '(); bdplugins[plugin.getName()] = { "plugin": plugin, "enabled": false } })();') _mainWindow.webContents.executeJavaScript('(function() { var plugin = new ' + pluginName + '(); bdplugins[plugin.getName()] = { "plugin": plugin, "enabled": false } })();')
}); });
@ -99,7 +99,7 @@ BetterDiscord.prototype.initLoaders = function(){
_fs.readdir(_dataPath + 'themes/', function(err, files) { _fs.readdir(_dataPath + 'themes/', function(err, files) {
if (err) { if (err) {
console.log(err); _this.getUtils().log(err);
return; return;
} }
_mainWindow.webContents.executeJavaScript('var bdthemes = {};'); _mainWindow.webContents.executeJavaScript('var bdthemes = {};');
@ -108,7 +108,7 @@ BetterDiscord.prototype.initLoaders = function(){
var split = theme.split('\n'); var split = theme.split('\n');
var meta = split[0]; var meta = split[0];
if (meta.indexOf('META') < 0) { if (meta.indexOf('META') < 0) {
console.log('BetterDiscord: ERROR[Theme META not found in file: ' + fileName + ']'); _this.getUtils().log('BetterDiscord: ERROR[Theme META not found in file: ' + fileName + ']');
return; return;
} }
var themeVar = meta.substring(meta.lastIndexOf('//META') + 6, meta.lastIndexOf('*//')); var themeVar = meta.substring(meta.lastIndexOf('//META') + 6, meta.lastIndexOf('*//'));
@ -117,7 +117,7 @@ BetterDiscord.prototype.initLoaders = function(){
var themeAuthor = parse['author']; var themeAuthor = parse['author'];
var themeDescription = parse['description']; var themeDescription = parse['description'];
var themeVersion = parse['version']; var themeVersion = parse['version'];
console.log('BetterDiscord: Loading Theme: ' + themeName); _this.getUtils().log('BetterDiscord: Loading Theme: ' + themeName);
split.splice(0, 1); split.splice(0, 1);
theme = split.join('\n'); theme = split.join('\n');
theme = theme.replace(/(\r\n|\n|\r)/gm, ''); theme = theme.replace(/(\r\n|\n|\r)/gm, '');
@ -225,6 +225,7 @@ BetterDiscord.prototype.init = function() {
self.getUtils().log("Latest Versions: " + _updater.LatestVersion); self.getUtils().log("Latest Versions: " + _updater.LatestVersion);
self.getUtils().log("Using CDN: " + _updater.CDN); self.getUtils().log("Using CDN: " + _updater.CDN);
self.getUtils().log("Starting up"); self.getUtils().log("Starting up");
self.updateData();
self.start(); self.start();
}); });
@ -239,7 +240,7 @@ BetterDiscord.prototype.start = function() {
}; };
BetterDiscord.prototype.quit = function(reason) { BetterDiscord.prototype.quit = function(reason) {
console.log("BetterDiscord ERR: " + reason); _this.getUtils().log("BetterDiscord ERR: " + reason);
}; };
var ipcHooked = false; var ipcHooked = false;
@ -300,12 +301,12 @@ BetterDiscord.prototype.load = function(reload) {
}; };
var loadCount = 0; var loadCount = 0;
var libCount;
var loadUs;
BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) { BetterDiscord.prototype.updateData = function() {
libCount = 9;
var libCount = 9; loadUs = {
var loadUs = {
'load-jQueryUI': { 'load-jQueryUI': {
'type': 'javascript', 'type': 'javascript',
'resource': 'jQueryUI', 'resource': 'jQueryUI',
@ -358,8 +359,27 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
'localpath': _dataPath + "/emotes_twitch_global.json", 'localpath': _dataPath + "/emotes_twitch_global.json",
'encoding': "utf8", 'encoding': "utf8",
'https': true, 'https': true,
'parse': true, 'parse': false,
'specialparser': 0 'specialparser': 0,
'fallback': 'load-emoteData-twitchGlobal-fallback',
'self': 'load-emoteData-twitchGlobal'
},
'load-emoteData-twitchGlobal-fallback': {
'type': 'emotedata',
'resource': 'Twitch Global Emotedata',
'domain': _updater.CDN,
'url': '/' + _repo + '/BetterDiscordApp/' + _hash + '/data/emotedata_twitch_global.json',
'localurl': null,
'message': 'load-emoteData-twitchSub',
'cacheable': true,
'variable': 'emotesTwitch',
'localpath': _dataPath + "/emotes_twitch_global.json",
'encoding': "utf8",
'https': true,
'parse': false,
'specialparser': 0,
'fallback': 'load-emoteData-twitchSub',
'self': 'load-emoteData-twitchGlobal-fallback'
}, },
'load-emoteData-twitchSub': { 'load-emoteData-twitchSub': {
'type': 'emotedata', 'type': 'emotedata',
@ -374,7 +394,26 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
'encoding': "utf8", 'encoding': "utf8",
'https': true, 'https': true,
'parse': true, 'parse': true,
'specialparser': 1 'specialparser': 1,
'fallback': 'load-emoteData-twitchSub-fallback',
'self': 'load-emoteData-twitchSub'
},
'load-emoteData-twitchSub-fallback': {
'type': 'emotedata',
'resource': 'Twitch Subscriber Emotedata',
'domain': _updater.CDN,
'url': '/' + _repo + '/BetterDiscordApp/' + _hash + '/data/emotedata_twitch_subscriber.json',
'localurl': null,
'message': 'load-emoteData-ffz',
'cacheable': true,
'variable': 'subEmotesTwitch',
'localpath': _dataPath + "/emotes_twitch_subscriber.json",
'encoding': "utf8",
'https': true,
'parse': true,
'specialparser': 1,
'fallback': 'load-emoteData-ffz',
'self': 'load-emoteData-twitchSub-fallback'
}, },
'load-emoteData-ffz': { 'load-emoteData-ffz': {
'type': 'emotedata', 'type': 'emotedata',
@ -389,7 +428,9 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
'encoding': "utf8", 'encoding': "utf8",
'https': true, 'https': true,
'parse': true, 'parse': true,
'specialparser': 2 'specialparser': 2,
'fallback': 'load-emoteData-bttv',
'self': 'load-emoteData-ffz'
}, },
'load-emoteData-bttv': { 'load-emoteData-bttv': {
'type': 'emotedata', 'type': 'emotedata',
@ -404,7 +445,9 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
'encoding': "utf8", 'encoding': "utf8",
'https': true, 'https': true,
'parse': false, 'parse': false,
'specialparser': 3 'specialparser': 3,
'fallback': 'load-emoteData-bttv-2',
'self': 'load-emoteData-bttv'
}, },
'load-emoteData-bttv-2': { 'load-emoteData-bttv-2': {
'type': 'emotedata', 'type': 'emotedata',
@ -419,11 +462,14 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
'encoding': "utf8", 'encoding': "utf8",
'https': true, 'https': true,
'parse': false, 'parse': false,
'specialparser': 4 'specialparser': 4,
'fallback': 'start-bd',
'self': 'load-emoteData-bttv-2'
} }
}; };
}
BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
if(loadUs.hasOwnProperty(arg)) { if(loadUs.hasOwnProperty(arg)) {
loadCount++; loadCount++;
@ -445,36 +491,22 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
_this.getUtils().sendIcpAsync(loadMe.message); _this.getUtils().sendIcpAsync(loadMe.message);
}); });
}else if(loadMe.type == 'emotedata') { }else if(loadMe.type == 'emotedata') {
if(loadMe.variable != "emotesTwitch") {
_this.getUtils().execJs('var ' + loadMe.variable + ' = {};');//jic
}
var exists = _fs.existsSync(loadMe.localpath); var exists = _fs.existsSync(loadMe.localpath);
if(exists && !_cacheExpired && loadMe.cacheable) { if(exists && !_cacheExpired && loadMe.cacheable) {
_this.getUtils().log("Reading " + loadMe.resource + " from file"); _this.loadLocalEData(loadMe);
_this.injectEmoteData(loadMe, _fs.readFileSync(loadMe.localpath, loadMe.encoding)); //_this.injectEmoteData(loadMe, _fs.readFileSync(loadMe.localpath, loadMe.encoding));
} else { } else {
_this.getUtils().log("Downloading " + loadMe.resource); _this.loadRemoteEData(loadMe);
if(loadMe.https) {
_this.getUtils().download(loadMe.domain, loadMe.url, function(data) {
var parsedEmoteData = _this.parseEmoteData(loadMe, data);
_this.saveEmoteData(loadMe, parsedEmoteData);
_this.injectEmoteData(loadMe, parsedEmoteData);
});
} else {
_this.getUtils().downloadHttp(loadMe.url, function(data) {
var parsedEmoteData = _this.parseEmoteData(loadMe, data);
_this.saveEmoteData(loadMe, parsedEmoteData);
_this.injectEmoteData(loadMe, parsedEmoteData);
});
}
} }
} }
} }
if(arg == "start-bd") { if(arg == "start-bd") {
_this.getUtils().saveLogs(_dataPath);
_this.getUtils().updateLoading("Starting Up", 100, 100); _this.getUtils().updateLoading("Starting Up", 100, 100);
_this.getUtils().execJs('var mainCore; var startBda = function() { mainCore = new Core(); mainCore.init(); }; startBda();'); _this.getUtils().execJs('var mainCore; var startBda = function() { mainCore = new Core(); mainCore.init(); }; startBda();');
@ -485,6 +517,53 @@ BetterDiscord.prototype.ipcAsyncMessage = function(event, arg) {
} }
}; };
BetterDiscord.prototype.loadRemoteEData = function(loadMe) {
_this.getUtils().log("Downloading " + loadMe.resource + " from " + loadMe.domain + loadMe.url );
if(loadMe.https) {
_this.getUtils().download(loadMe.domain, loadMe.url, function(data) {
var parsedEmoteData = _this.parseEmoteData(loadMe, data);
if(parsedEmoteData == null) {
_this.getUtils().sendIcpAsync(loadMe.fallback);
return true;
}
_this.saveEmoteData(loadMe, parsedEmoteData);
_this.injectEmoteData(loadMe, parsedEmoteData);
});
return true;
}
_this.getUtils().downloadHttp(loadMe.url, function(data) {
var parsedEmoteData = _this.parseEmoteData(loadMe, data);
_this.saveEmoteData(loadMe, parsedEmoteData);
_this.injectEmoteData(loadMe, parsedEmoteData);
});
};
BetterDiscord.prototype.loadLocalEData = function(loadMe) {
_this.getUtils().log("Reading " + loadMe.resource + " from file");
var data = _fs.readFileSync(loadMe.localpath, loadMe.encoding);
if(_this.testJSON(loadMe, data)) {
_this.injectEmoteData(loadMe, data);
} else {
_this.getUtils().log("Deleting cached file " + loadMe.resource);
_fs.unlinkSync(loadMe.localpath);
_this.getUtils().sendIcpAsync(loadMe.self);
}
};
BetterDiscord.prototype.testJSON = function(loadMe, data) {
_this.getUtils().log("Validating " + loadMe.resource);
try {
var json = JSON.parse(data);
_this.getUtils().log(loadMe.resource + " is valid");
return true;
}catch(err) {
_this.getUtils().log(loadMe.resource + " is invalid");
return false;
}
};
BetterDiscord.prototype.parseEmoteData = function(loadMe, emoteData) { BetterDiscord.prototype.parseEmoteData = function(loadMe, emoteData) {
_this.getUtils().log("Parsing: " + loadMe.resource); _this.getUtils().log("Parsing: " + loadMe.resource);
@ -494,11 +573,17 @@ BetterDiscord.prototype.parseEmoteData = function(loadMe, emoteData) {
switch(loadMe.specialparser) { switch(loadMe.specialparser) {
case 0: //Twitch Global Emotes case 0: //Twitch Global Emotes
returnData = emoteData.replace(/\$/g, "\\$").replace(/'/g, "\\'").replace(/"/g, "\\\""); //returnData = emoteData.replace(/\$/g, "\\$").replace(/'/g, "\\'").replace(/"/g, "\\\""); We don't need this anymore
return emoteData;
break; break;
case 1: //Twitch Subscriber Emotes case 1: //Twitch Subscriber Emotes
returnData = {}; returnData = {};
if(!_this.testJSON(loadMe, emoteData)) {
return null;
}
emoteData = JSON.parse(emoteData); emoteData = JSON.parse(emoteData);
var channels = emoteData["channels"]; var channels = emoteData["channels"];
for(var channel in channels) { for(var channel in channels) {
var emotes = channels[channel]["emotes"]; var emotes = channels[channel]["emotes"];
@ -516,6 +601,11 @@ BetterDiscord.prototype.parseEmoteData = function(loadMe, emoteData) {
break; break;
case 3: //BTTV Emotes case 3: //BTTV Emotes
returnData = {}; returnData = {};
if(!_this.testJSON(loadMe, emoteData)) {
return null;
}
emoteData = JSON.parse(emoteData); emoteData = JSON.parse(emoteData);
for(var emote in emoteData.emotes) { for(var emote in emoteData.emotes) {
@ -531,29 +621,23 @@ BetterDiscord.prototype.parseEmoteData = function(loadMe, emoteData) {
case 4: case 4:
returnData = emoteData; returnData = emoteData;
break; break;
} }
return returnData; return returnData;
}; };
BetterDiscord.prototype.saveEmoteData = function(loadMe, emoteData) { BetterDiscord.prototype.saveEmoteData = function(loadMe, emoteData) {
_fs.writeFileSync(loadMe.localpath, emoteData, loadMe.encoding); _fs.writeFileSync(loadMe.localpath, emoteData, loadMe.encoding);
}; };
BetterDiscord.prototype.injectEmoteData = function(loadMe, emoteData) { BetterDiscord.prototype.injectEmoteData = function(loadMe, emoteData) {
if(emoteData != null) {
if(loadMe.parse) { if(loadMe.parse) {
_this.getUtils().execJs('var ' + loadMe.variable + ' = JSON.parse(\'' + emoteData + '\');'); _this.getUtils().execJs('var ' + loadMe.variable + ' = JSON.parse(\'' + emoteData + '\');');
} else { } else {
_this.getUtils().execJs('var ' + loadMe.variable + ' = ' + emoteData + ';'); _this.getUtils().execJs('var ' + loadMe.variable + ' = ' + emoteData + ';');
}
} }
_this.getUtils().sendIcpAsync(loadMe.message); _this.getUtils().sendIcpAsync(loadMe.message);
}; };
exports.BetterDiscord = BetterDiscord; exports.BetterDiscord = BetterDiscord;

View File

@ -1,14 +1,17 @@
/* BetterDiscordApp Utils and Helper functions /* BetterDiscordApp Utils and Helper functions
* Version: 1.3 * Version: 1.4
* Author: Jiiks | http://jiiks.net * Author: Jiiks | http://jiiks.net
* Date: 25/08/2015 - 09:19 * Date: 25/08/2015 - 09:19
* Last Updated: 26/10/2015 06:11 * Last Updated: 30/03/2016
* https://github.com/Jiiks/BetterDiscordApp * https://github.com/Jiiks/BetterDiscordApp
*/ */
var https = require('https'); var https = require('https');
var http = require('http'); var http = require('http');
var _fs = require('fs');
var _mainWindow; var _mainWindow;
var eol = require('os').EOL;
var logs = "";
function Utils(mainWindow) { function Utils(mainWindow) {
_mainWindow = mainWindow; _mainWindow = mainWindow;
@ -57,7 +60,7 @@ Utils.prototype.downloadHttp = function(url, callback) {
} }
Utils.prototype.getHash = function(beta, callback) { Utils.prototype.getHash = function(beta, callback) {
var branch = beta ? "beta" : "master"; var branch = beta ? "beta" : "master";
this.download("api.github.com", "/repos/Jiiks/BetterDiscordApp/commits/"+branch+"", function(data) { this.download("api.github.com", "/repos/Jiiks/BetterDiscordApp/commits/"+branch+"", function(data) {
callback(JSON.parse(data).sha); callback(JSON.parse(data).sha);
}); });
@ -97,6 +100,10 @@ Utils.prototype.updateLoading = function(message, cur, max) {
//Logger //Logger
Utils.prototype.log = function(message) { Utils.prototype.log = function(message) {
console.log("BetterDiscord: " + message); console.log("BetterDiscord: " + message);
logs += message + eol;
}
Utils.prototype.saveLogs = function(path) {
_fs.writeFileSync(path + "/logs.log", logs);
} }
//Execute javascript //Execute javascript

View File

@ -1,6 +1,6 @@
{ {
"Core": { "Core": {
"Version": "0.2.6" "Version": "0.2.7"
}, },
"EmoteModule": { "EmoteModule": {
"Twitch":{ "Twitch":{

View File

@ -1,8 +1,8 @@
{ {
"name": "betterdiscord", "name": "betterdiscord",
"description": "Better Discord enhances Discord.", "description": "Better Discord enhances Discord.",
"version": "0.2.6", "version": "0.2.7",
"homepage": "https://github.com/Jiiks/BetterDiscordApp", "homepage": "https://github.com/Jiiks/BetterDiscordApp",
"license": "MIT", "license": "MIT",
"main": "betterdiscord.js" "main": "betterdiscord.js"
} }