Merge pull request #10 from Jiiks/master

Pull latest changes
This commit is contained in:
DeathStrikeV 2017-02-12 09:04:55 +00:00 committed by GitHub
commit 92e992abd2
12 changed files with 304 additions and 219 deletions

View File

@ -47,6 +47,9 @@ function install() {
_functionCallSplice = 446; _functionCallSplice = 446;
_functionSplice = 547; _functionSplice = 547;
_discordPath = "/Applications/Discord.app/Contents/Resources" // Defaults to Applications directory _discordPath = "/Applications/Discord.app/Contents/Resources" // Defaults to Applications directory
} else if (_os == "linux") {
_discordPath = "/opt/DiscordCanary/resources";
_index = "/app/index.js";
} }
} }
console.log("Looking for discord resources at: " + _discordPath); console.log("Looking for discord resources at: " + _discordPath);
@ -80,8 +83,12 @@ function install() {
asar.extractAll(_discordPath + _appArchive, _discordPath + _appFolder); asar.extractAll(_discordPath + _appArchive, _discordPath + _appFolder);
console.log("Copying BetterDiscord"); console.log("Copying BetterDiscord");
if(_os == "linux") {
fs.mkdirSync(_discordPath + "/node_modules/BetterDiscord"); fs.mkdirSync(_discordPath + _appFolder + "/node_modules/BetterDiscord");
}
else {
fs.mkdirSync(_discordPath + "/node_modules/BetterDiscord");
}
wrench.copyDirSyncRecursive(__dirname + "/BetterDiscord/", _discordPath + _appFolder + "/node_modules/BetterDiscord/", {forceDelete: true}); wrench.copyDirSyncRecursive(__dirname + "/BetterDiscord/", _discordPath + _appFolder + "/node_modules/BetterDiscord/", {forceDelete: true});
@ -99,8 +106,18 @@ function install() {
console.log("Injecting index.js"); console.log("Injecting index.js");
var data = fs.readFileSync(_discordPath + _index).toString().split("\n"); var data = fs.readFileSync(_discordPath + _index).toString().split("\n");
data.splice(_importSplice, 0, 'var _betterDiscord = require(\'betterdiscord\');\n');
data.splice(_functionCallSplice, 0, splice); if(_os == "linux") {
data = data.join("\n");
data = data.replace('var _GPUSettings2 = _interopRequireDefault(_GPUSettings);','var _GPUSettings2 = _interopRequireDefault(_GPUSettings);\n\nvar _betterDiscord = require(\'BetterDiscord\');\n');
data = data.replace('mainWindow.setMenuBarVisibility(false);','mainWindow.setMenuBarVisibility(false);\n' + splice + '\n');
data = data.split("\n");
} else {
data.splice(_importSplice, 0, 'var _betterDiscord = require(\'betterdiscord\');\n');
data.splice(_functionCallSplice, 0, splice);
}
fs.writeFile(_discordPath + _index, data.join("\n"), function(err) { fs.writeFile(_discordPath + _index, data.join("\n"), function(err) {
if(err) return console.log(err); if(err) return console.log(err);

View File

@ -9,9 +9,10 @@ emoteBlacklist.prototype.onSwitch = function () {
emoteBlacklist.prototype.start = function () { emoteBlacklist.prototype.start = function () {
window.ebEnabled = true; window.ebEnabled = true;
var self = this; var self = this;
var em = localStorage["emoteBlacklist"]; var em = bdPluginStorage.get("emoteBlacklist", "blacklist");
if(em == undefined) return;
JSON.parse(em).forEach(function(emote) { if(em === null) return;
em.forEach(function(emote) {
self.remove(emote); self.remove(emote);
self.add(emote); self.add(emote);
}); });
@ -35,21 +36,20 @@ emoteBlacklist.prototype.stop = function () {
}; };
emoteBlacklist.prototype.clear = function() { emoteBlacklist.prototype.clear = function() {
var self = this; var self = this;
var em = localStorage["emoteBlacklist"]; var em = bdPluginStorage.get("emoteBlacklist", "blacklist");
if(em == undefined) return; if(em === null) return;
var em = JSON.parse(em);
em.forEach(function(emote) { em.forEach(function(emote) {
self.remove(emote); self.remove(emote);
}); });
}; };
emoteBlacklist.prototype.getSettingsPanel = function () { emoteBlacklist.prototype.getSettingsPanel = function () {
var em = localStorage["emoteBlacklist"]; var em = bdPluginStorage.get("emoteBlacklist", "blacklist");
var html = ''; var html = '';
html += '<h2>Emote Blacklist</2>'; html += '<h2>Emote Blacklist</2>';
html += '<textarea id="emoteBlistTa" style="width:100%; min-height:200px;">'; html += '<textarea id="emoteBlistTa" style="width:100%; min-height:200px;">';
if(em != undefined) { if(em !== null) {
JSON.parse(em).forEach(function(item) { em.forEach(function(item) {
html += item + "\n"; html += item + "\n";
}); });
} }
@ -64,7 +64,7 @@ emoteBlacklist.prototype.save = function() {
$("#emoteBlistTa").val().split("\n").forEach(function(item) { $("#emoteBlistTa").val().split("\n").forEach(function(item) {
blist.push(item); blist.push(item);
}); });
localStorage["emoteBlacklist"] = JSON.stringify(blist); bdPluginStorage.set("emoteBlacklist", "blacklist", blist);
if(window.ebEnabled) { if(window.ebEnabled) {
this.start(); this.start();
} }

View File

@ -1,3 +1,5 @@
Note that this whole branch is deprecated. all further development is going on here: https://github.com/Jiiks/BetterDiscordApp/tree/v2
# BetterDiscordApp # BetterDiscordApp
# If you have issues then join the BD Discord server: [Here](https://discord.gg/0Tmfo5ZbORCRqbAd) # If you have issues then join the BD Discord server: [Here](https://discord.gg/0Tmfo5ZbORCRqbAd)
@ -6,7 +8,7 @@
## All plugins must be named `*.plugin.js` and all themes must be named `*.theme.css` ## All plugins must be named `*.plugin.js` and all themes must be named `*.theme.css`
Better Discord App enhances Discord desktop app with new features. Better Discord App enhances the Discord desktop app with new features.
![ss](http://puu.sh/oIO58.png) ![ss](http://puu.sh/oIO58.png)

View File

@ -699,6 +699,7 @@
padding: 0px !important; padding: 0px !important;
padding-left: 3px !important; padding-left: 3px !important;
color: #EBEBEB; color: #EBEBEB;
z-index: 90000;
} }
.bd-minimal-chan #bd-show-channels { .bd-minimal-chan #bd-show-channels {

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
{ {
"blacklist": [ "blacklist": [
"Minecraft",
"Cannon", "Cannon",
"Barracks", "Barracks",
"Roshan", "Roshan",
@ -184,6 +185,34 @@
"Affe", "Affe",
"Baby", "Baby",
"YOUTUBE", "YOUTUBE",
"Bella" "Bella",
"Spooky",
"Spaghetti",
"Rucksack",
"Rein",
"Dirk",
"Moin",
"Heya!",
"Crossover",
"Kitsune",
"Gengar",
"Nebby",
"Uhhh",
"Runescape",
"Shitpost",
"Dunno",
"Challenge",
"Shulk",
"Peach",
"Leffen",
"STEAK",
"Lars",
"Kirby",
"Samus",
"Toad",
"Poopy",
"Alexis",
"Dante",
"Lotus"
] ]
} }

View File

@ -6,9 +6,80 @@
* Last Update: 01/05/2016 * Last Update: 01/05/2016
* https://github.com/Jiiks/BetterDiscordApp * https://github.com/Jiiks/BetterDiscordApp
*/ */
/*Localstorage fix*/
(function() {
let __fs = window.require("fs");
let __process = window.require("process");
let __platform = __process.platform;
let __dataPath = (__platform === 'win32' ? __process.env.APPDATA : __platform === 'darwin' ? __process.env.HOME + '/Library/Preferences' : process.env.HOME + '/.config') + '/BetterDiscord/';
let __data = {};
if(__fs.existsSync(`${__dataPath}localStorage.json`)) {
try {
__data = JSON.parse(__fs.readFileSync(`${__dataPath}localStorage.json`))
}catch(err) {
console.log(err);
}
} else if(__fs.existsSync("localStorage.json")) {
try {
__data = JSON.parse(__fs.readFileSync("localStorage.json"));
}catch(err) {
console.log(err);
}
}
var __ls = __data;
__ls.setItem = function(i, v) {
__ls[i] = v;
this.save();
};
__ls.getItem = function(i) {
return __ls[i] || null;
};
__ls.save = function() {
__fs.writeFileSync(`${__dataPath}/localStorage.json`, JSON.stringify(this), null, 4);
};
var __proxy = new Proxy(__ls, {
set: function(target, name, val, receiver) {
__ls[name] = val;
__ls.save();
},
get: function(target, name, receiver) {
return __ls[name] || null;
}
});
window.localStorage = __proxy;
})();
window.bdStorage = {};
window.bdStorage.get = function(i) {
return betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'storage', 'cmd': 'get', 'var': i });
};
window.bdStorage.set = function(i, v) {
betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'storage', 'cmd': 'set', 'var': i, 'data': v });
};
window.bdPluginStorage = {};
window.bdPluginStorage.get = function(pn, i) {
return betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'pluginstorage', 'cmd': 'get', 'pn': pn, 'var': i });
};
window.bdPluginStorage.set = function(pn, i, v) {
betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'pluginstorage', 'cmd': 'set', 'pn': pn, 'var': i, 'data': v });
};
betterDiscordIPC.on('asynchronous-reply', (event, arg) => {
console.log(event);
console.log(arg);
});
var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor, dMode; var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor, dMode;
var jsVersion = 1.74; var jsVersion = 1.77;
var supportedVersion = "0.2.5"; var supportedVersion = "0.2.81";
var mainObserver; var mainObserver;
@ -84,60 +155,25 @@ var defaultCookie = {
var bdchangelog = { var bdchangelog = {
"changes": { "changes": {
"0a": { "0a": {
"title": "1.73 : Native sub emotes", "title": "1.77 : Local storage proxy",
"text": "Native sub emote support disabled for now due to a critical bug", "text": "Implemented a local storage proxy for old plugin support. Do not use it for new plugins! use the bdPluginStorage.get and bdPluginStorage.set",
"img": "" "img": ""
}, },
"1a": { "0b": {
"title": "1.73 : Initial Developer Mode", "title": "1.76 : Alternate Storage",
"text": "Enable developer mode from settings!", "text": "<a target='blank' href='https://gist.github.com/Jiiks/267113ecb1685f39f4dc4646f9380d55'>https://gist.github.com/Jiiks/267113ecb1685f39f4dc4646f9380d55</a>",
"img": ""
},
"a": {
"title": "v1.72 : Public Servers",
"text": "Public servers now have categories, description, tags, dark mode and more!",
"img": ""
},
"b": {
"title": "v1.72 : Import/Export",
"text": "Import/Export buttons now disappear in themes/plugins tabs to avoid confusion",
"img": ""
},
"c": {
"title": "v1.72 : Changelog",
"text": "You can now reopen this changelog from the settings",
"img": "" "img": ""
} }
}, },
"fixes": { "fixes": {
"0a": { "0a": {
"title": "v1.74 : BetterDiscord Invite", "title": "1.77 : Custom css and favourite emote loading",
"text": "Fixed the BetterDiscord invite link in public servers", "text": "Fixed custom css and favourite emote loading when they are not present",
"img": "" "img": ""
}, },
"0b": { "0b": {
"title": "v1.74 : Dev Mode", "title": "1.76 : Alternate Storage",
"text": "Fixed dev mode breaking", "text": "Both BetterDiscord and plugins now use alternate storage",
"img": ""
},
"0c": {
"title": "v1.72 : Settings panel",
"text": "Settings panel will now show no matter how you open it!",
"img": ""
},
"0d": {
"title": "v1.72 : Fixed emote edit bug",
"text": "Edits now appear properly even with emotes!",
"img": ""
},
"0e": {
"title": "v1.72 : Public servers",
"text": "Public servers button is visible again!",
"img": ""
},
"0f": {
"title": "v1.72 : Public servers",
"text": "Updated public servers api endpoint url for fetching correct serverlist.",
"img": "" "img": ""
} }
} }
@ -997,7 +1033,7 @@ PublicServers.prototype.loadServers = function(dataset, search, clear) {
// if(source.invite_code === undefined) return; // if(source.invite_code === undefined) return;
// var icode = source.invite_code.replace(/ /g,''); // var icode = source.invite_code.replace(/ /g,'');
// icode = self.escape(icode).replace(/[^A-z0-9]/g,''); // icode = self.escape(icode).replace(/[^A-z0-9]/g,'');
var icode = source.identifier; var icode = source.identifier;
var html = '<div class="server-row">'; var html = '<div class="server-row">';
html += '<div class="server-icon" style="background-image:url(' + self.escape(source.icon) + ')"></div>'; html += '<div class="server-icon" style="background-image:url(' + self.escape(source.icon) + ')"></div>';
html += '<div class="server-info server-name">'; html += '<div class="server-info server-name">';
@ -1100,27 +1136,27 @@ PublicServers.prototype.search = function(start, clear) {
};*/ };*/
var dataset = { var dataset = {
"sort": [{ "online": "desc" }], "sort": [{ "online": "desc" }],
"from": start, "from": start,
"size": 20, "size": 20,
"query": { "query": {
"bool": { "bool": {
"must": [ "must": [
{"query_string": { {"query_string": {
"default_operator": "AND", "default_operator": "AND",
"query": sterm ? sterm : "*" "query": sterm ? sterm : "*"
}} }}
], ],
"must_not": [ "must_not": [
{"terms": { "identifier": this.filtered }} {"terms": { "identifier": this.filtered }}
] ]
} }
} }
}; };
if(this.selectedCategory != "all") { if(this.selectedCategory != "all") {
dataset.query.bool.must.push({ "match_phrase": { "categories": this.selectedCategory } }); dataset.query.bool.must.push({ "match_phrase": { "categories": this.selectedCategory } });
} }
this.loadServers(dataset, true, clear); this.loadServers(dataset, true, clear);
@ -1128,8 +1164,8 @@ PublicServers.prototype.search = function(start, clear) {
//Workaround for joining a server //Workaround for joining a server
PublicServers.prototype.joinServer = function (code) { PublicServers.prototype.joinServer = function (code) {
require('electron').shell.openExternal("https://www.discordservers.com/join/" + code); require('electron').shell.openExternal("https://www.discordservers.com/join/" + code);
this.hide(); this.hide();
}; };
PublicServers.prototype.joinServerDirect = function(code) { PublicServers.prototype.joinServerDirect = function(code) {
@ -1141,7 +1177,7 @@ PublicServers.prototype.joinServerDirect = function(code) {
}; };
PublicServers.prototype.escape = function(unsafe) { PublicServers.prototype.escape = function(unsafe) {
if(unsafe === undefined) return ""; if(unsafe === undefined) return "";
return unsafe return unsafe
.replace(/&/g, "&amp;") .replace(/&/g, "&amp;")
@ -1168,8 +1204,8 @@ QuickEmoteMenu.prototype.init = function() {
if(e.target.id != "rmenu") $("#rmenu").remove(); if(e.target.id != "rmenu") $("#rmenu").remove();
}); });
this.favoriteEmotes = {}; this.favoriteEmotes = {};
var fe = localStorage["bdfavemotes"]; var fe = bdStorage.get("bdfavemotes");
if (fe != undefined) { if (fe !== "" && fe !== null) {
this.favoriteEmotes = JSON.parse(atob(fe)); this.favoriteEmotes = JSON.parse(atob(fe));
} }
@ -1332,8 +1368,7 @@ QuickEmoteMenu.prototype.updateFavorites = function () {
this.faContainer = faContainer; this.faContainer = faContainer;
$("#bda-qem-favourite-container").replaceWith(faContainer); $("#bda-qem-favourite-container").replaceWith(faContainer);
window.bdStorage.set("bdfavemotes", btoa(JSON.stringify(this.favoriteEmotes)));
window.localStorage["bdfavemotes"] = btoa(JSON.stringify(this.favoriteEmotes));
}; };
function CustomCssEditor() { } function CustomCssEditor() { }
@ -1364,7 +1399,7 @@ attachEditor += " <\/li>";
attachEditor += " <li>"; attachEditor += " <li>";
attachEditor += " <div class=\"checkbox\" onclick=\"settingsPanel.updateSetting(this);\">"; attachEditor += " <div class=\"checkbox\" onclick=\"settingsPanel.updateSetting(this);\">";
attachEditor += " <div class=\"checkbox-inner\"><input id=\"bda-css-1\" type=\"checkbox\" "+(settingsCookie["bda-css-1"] ? "checked" : "")+"><span><\/span><\/div>"; attachEditor += " <div class=\"checkbox-inner\"><input id=\"bda-css-1\" type=\"checkbox\" "+(settingsCookie["bda-css-1"] ? "checked" : "")+"><span><\/span><\/div>";
attachEditor += " <span title=\"Autosave css to localstorage when typing\">Autosave<\/span>"; attachEditor += " <span title=\"Autosave css to storage when typing\">TEMPDISABLED<\/span>";
attachEditor += " <\/div>"; attachEditor += " <\/div>";
attachEditor += " <\/li>"; attachEditor += " <\/li>";
attachEditor += " <li>"; attachEditor += " <li>";
@ -1430,8 +1465,8 @@ CustomCssEditor.prototype.applyCustomCss = function (css, forceupdate, forcesave
$("#customcss").html(css); $("#customcss").html(css);
} }
if(forcesave || settingsCookie["bda-css-1"]) { if(forcesave) {
localStorage.setItem("bdcustomcss", btoa(css)); window.bdStorage.set("bdcustomcss", btoa(css));
} }
}; };
/* BetterDiscordApp Settings Panel JavaScript /* BetterDiscordApp Settings Panel JavaScript
@ -1725,7 +1760,11 @@ SettingsPanel.prototype.construct = function () {
//End emote settings //End emote settings
//Custom CSS Editor //Custom CSS Editor
var ccss = atob(localStorage.getItem("bdcustomcss")); var _ccss = window.bdStorage.get("bdcustomcss");
var ccss = "";
if(_ccss !== null && _ccss !== "") {
ccss = atob(_ccss);
}
customCssEditor.applyCustomCss(ccss, true, false); customCssEditor.applyCustomCss(ccss, true, false);
settingsInner += '\ settingsInner += '\
@ -1977,8 +2016,8 @@ Utils.prototype.importSettings = function() {
settingsPanel.updateSettings(); settingsPanel.updateSettings();
} }
} }
localStorage["bdcustomcss"] = obj.customCss; window.bdStorage.set("bdcustomcss", obj.customCss);
var ccss = atob(localStorage.getItem("bdcustomcss")); var ccss = window.bdStorage.get("bdcustomcss");
if (!customCssInitialized) { if (!customCssInitialized) {
customCssEditor.init(); customCssEditor.init();
customCssInitialized = true; customCssInitialized = true;
@ -2041,10 +2080,10 @@ Utils.prototype.importSettings = function() {
Utils.prototype.exportSettings = function() { Utils.prototype.exportSettings = function() {
var obj = { var obj = {
settings: settingsCookie, settings: settingsCookie,
customCss: localStorage["bdcustomcss"], customCss: window.bdStorage.get("bdcustomcss"),
plugins: pluginCookie, plugins: pluginCookie,
themes: themeCookie, themes: themeCookie,
favEmotes: window.localStorage["bdfavemotes"] favEmotes: window.bdStorage.get("bdfavemotes")
}; };
mainCore.alert("Export Settings", '<div class="form" style="width:100%;"><div class="control-group"><textarea style="min-height:150px;">'+JSON.stringify(obj)+'</textarea></div></div>'); mainCore.alert("Export Settings", '<div class="form" style="width:100%;"><div class="control-group"><textarea style="min-height:150px;">'+JSON.stringify(obj)+'</textarea></div></div>');
}; };
@ -2329,8 +2368,8 @@ BdWSocket.prototype.onOpen = function () {
var data = { var data = {
op: 2, op: 2,
d: { d: {
token: JSON.parse(localStorage.getItem('token')), token: JSON.parse(window.bdStorage.get('token')),
properties: JSON.parse(localStorage.getItem('superProperties')), properties: JSON.parse(window.bdStorage.get('superProperties')),
v: 3 v: 3
} }
}; };
@ -2572,4 +2611,4 @@ BdApi.setStatus = function (idle_since, status) {
devMode.prototype.disable = function() { devMode.prototype.disable = function() {
$(window).off("keydown.bdDevmode"); $(window).off("keydown.bdDevmode");
$(window).off("mousedown.bdDevmode") $(window).off("mousedown.bdDevmode")
}; };

102
js/main.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,7 @@
var _fs = require("fs"); var _fs = require("fs");
var _config = require("./config.json"); var _config = require("./config.json");
var _utils = require("./utils"); var _utils;
var _utils2; var _utils2;
var _bdIpc = require('electron').ipcMain; var _bdIpc = require('electron').ipcMain;
var _error = false; var _error = false;
@ -22,11 +22,64 @@ var _mainWindow;
var _cfg = {}; var _cfg = {};
var _extData = {}; var _extData = {};
var bdStorage = {};
var bdPluginStorage = {};
bdStorage.defaults = {
data: {}
};
bdPluginStorage.defaults = {
data: {}
};
function initStorage() {
if(!_fs.existsSync(_cfg.dataPath + "/bdStorage.json")) {
bdStorage.data = bdStorage.defaults.data;
_fs.writeFileSync(_cfg.dataPath + "/bdStorage.json", JSON.stringify(bdStorage, null, 4));
} else {
bdStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdStorage.json"));
}
};
bdStorage.get = function(i, m, pn) {
if(m) return bdStorage.data[i] || "";
if(bdPluginStorage[pn] !== undefined) {
return bdPluginStorage[pn][i] || undefined;
}
if(_fs.existsSync(_cfg.dataPath + "/plugins/" + pn + ".config.json")) {
bdPluginStorage[pn] = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/plugins/" + pn + ".config.json"));
return bdPluginStorage[pn][i] || undefined;
}
return undefined;
};
bdStorage.set = function(i, v, m, pn) {
if(m) {
bdStorage.data[i] = v;
_fs.writeFileSync(_cfg.dataPath + "/bdStorage.json", JSON.stringify(bdStorage.data, null, 4));
} else {
if(bdPluginStorage[pn] === undefined) bdPluginStorage[pn] = {};
bdPluginStorage[pn][i] = v;
_fs.writeFileSync(_cfg.dataPath + "/plugins/" + pn + ".config.json", JSON.stringify(bdPluginStorage[pn], null, 4));
}
return true;
};
function BetterDiscord(mainWindow) { function BetterDiscord(mainWindow) {
_mainWindow = mainWindow; _mainWindow = mainWindow;
_cfg = _config.cfg; _cfg = _config.cfg;
_cfg.version = _config.Core.Version; _cfg.version = _config.Core.Version;
_cfg.os = process.platform; _cfg.os = process.platform;
_utils = _cfg.os == "linux" ? require("./Utils") : require("./utils");
_utils2 = new _utils.Utils(mainWindow); _utils2 = new _utils.Utils(mainWindow);
hook(); hook();
createAndCheckData(); createAndCheckData();
@ -35,7 +88,7 @@ function BetterDiscord(mainWindow) {
function createAndCheckData() { function createAndCheckData() {
getUtils().log("Checking data/cache"); getUtils().log("Checking data/cache");
_cfg.dataPath = (_cfg.os == 'win32' ? process.env.APPDATA : _cfg.os == 'darwin' ? process.env.HOME + '/Library/Preferences' : '/var/local') + '/BetterDiscord/'; _cfg.dataPath = (_cfg.os == 'win32' ? process.env.APPDATA : _cfg.os == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + '/.config') + '/BetterDiscord/';
_cfg.userFile = _cfg.dataPath + 'user.json'; _cfg.userFile = _cfg.dataPath + 'user.json';
try { try {
@ -86,6 +139,7 @@ function init() {
getUtils().attempt(getHash, 3, 0, "Failed to load hash", initUpdater, function() { getUtils().attempt(getHash, 3, 0, "Failed to load hash", initUpdater, function() {
exit("Failed to load hash after 3 attempts"); exit("Failed to load hash after 3 attempts");
}); });
initStorage();
} }
function getHash(callback) { function getHash(callback) {
@ -94,11 +148,11 @@ function getHash(callback) {
_cfg.hash = JSON.parse(data).sha; _cfg.hash = JSON.parse(data).sha;
getUtils().injectVar("_bdhash", _cfg.hash); getUtils().injectVar("_bdhash", _cfg.hash);
}catch(err) { }catch(err) {
callback(false); callback(false, err);
return; return;
} }
if(_cfg.hash == undefined) { if(_cfg.hash == undefined) {
callback(false); callback(false, "_cfg.hash == undefined");
return; return;
} }
@ -111,7 +165,7 @@ function getHash(callback) {
function initUpdater() { function initUpdater() {
getUtils().log("Getting updater"); getUtils().log("Getting updater");
getUtils().attempt(getUpdater, 3, 0, "Failed to load updater", waitForDom, function() { getUtils().attempt(getUpdater, 3, 0, "Failed to load updater", waitForDom, function() {
exit("Failed to load updater after 3 attempts"); exit("Failed to load updater after 3 attempts.");
}); });
} }
@ -120,17 +174,22 @@ function getUpdater(callback) {
try { try {
_cfg.updater = JSON.parse(data); _cfg.updater = JSON.parse(data);
} catch(err) { } catch(err) {
callback(false); callback(false, err);
return; return;
} }
if(_cfg.updater == undefined) { if(_cfg.updater == undefined) {
callback(false); callback(false, "_cfg.updater == undefined");
return; return;
} }
if(_cfg.updater.LatestVersion == undefined || _cfg.updater.CDN == undefined) { if(_cfg.updater.LatestVersion == undefined) {
callback(false); callback(false, "_cfg.updater.LatestVersion == undefined");
return;
}
if(_cfg.updater.CDN == undefined) {
callback(false, "_cfg.updater.CDN == undefined");
return; return;
} }
@ -169,8 +228,8 @@ function updateExtData() {
'type': 'javascript', 'type': 'javascript',
'resource': 'Main JS', 'resource': 'Main JS',
'domain': _cfg.updater.CDN, 'domain': _cfg.updater.CDN,
'url': '//' + _cfg.updater.CDN + '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/js/main.min.js', 'url': '//' + _cfg.updater.CDN + '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/js/main.js',
'localurl': _cfg.localServer + '/BetterDiscordApp/js/main.js', 'localurl': _cfg.localServer + '/BetterDiscordApp/js/main.js?v=1.1',
'message': 'load-emoteData-twitchGlobal', 'message': 'load-emoteData-twitchGlobal',
'cacheable': false, 'cacheable': false,
'variable': null 'variable': null
@ -357,6 +416,7 @@ function load(reload) {
} }
getUtils().log("Hooking ipc async"); getUtils().log("Hooking ipc async");
_bdIpc.on('asynchronous-message', function(event, arg) { ipcAsyncMessage(event, arg); }); _bdIpc.on('asynchronous-message', function(event, arg) { ipcAsyncMessage(event, arg); });
_bdIpc.on('synchronous-message', function(event, arg) { ipcSyncMessage(event, arg); });
getUtils().log("Hooked ipc async"); getUtils().log("Hooked ipc async");
} }
initLoaders(); initLoaders();
@ -511,8 +571,32 @@ function loadApp() {
getUtils().injectJavaScriptSync("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", "load-jQueryCookie"); getUtils().injectJavaScriptSync("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", "load-jQueryCookie");
} }
function ipcAsyncMessage(event, arg) { function ipcSyncMessage(event, arg) {
if(typeof(arg) === "object") {
switch(arg.arg) {
case "storage":
if(arg.cmd == "get") {
event.returnValue = bdStorage.get(arg.var, true);
}
if(arg.cmd == "set") {
bdStorage.set(arg.var, arg.data, true);
event.returnValue = "saved";
}
break;
case "pluginstorage":
if(arg.cmd == "get") {
event.returnValue = bdStorage.get(arg.var, false, arg.pn) || null;
}
if(arg.cmd == "set") {
bdStorage.set(arg.var, arg.data, false, arg.pn);
event.returnValue = "saved";
}
break;
}
}
}
function ipcAsyncMessage(event, arg) {
if(typeof(arg) === "object") { if(typeof(arg) === "object") {
switch(arg.arg) { switch(arg.arg) {
case "opendir": case "opendir":
@ -530,6 +614,17 @@ function ipcAsyncMessage(event, arg) {
} }
getUtils().openDir(arg.path); getUtils().openDir(arg.path);
break; break;
case "storage":
if(arg.cmd == "set") {
bdStorage.set(arg.var, arg.data);
break;
}
if(arg.cmd == "get") {
var get = bdStorage.get(arg.var);
event.sender.send('asynchronous-reply', get);
break;
}
break;
} }
return; return;
} }
@ -739,4 +834,4 @@ function exit(reason) {
BetterDiscord.prototype.init = function() {}//Compatibility BetterDiscord.prototype.init = function() {}//Compatibility
exports.BetterDiscord = BetterDiscord; exports.BetterDiscord = BetterDiscord;

View File

@ -1,6 +1,6 @@
{ {
"Core": { "Core": {
"Version": "0.2.8" "Version": "0.2.82"
}, },
"EmoteModule": { "EmoteModule": {
"Twitch":{ "Twitch":{
@ -25,7 +25,7 @@
"beta": false, "beta": false,
"local": false, "local": false,
"localServer": "http://localhost", "localServer": "http://localhost",
"version": "0.2.8", "version": "0.2.82",
"updater": null, "updater": null,
"hash": null, "hash": null,
"dataPath": null, "dataPath": null,
@ -38,4 +38,4 @@
"defaultCfg": { "cache": null }, "defaultCfg": { "cache": null },
"userCfg": { "cache": null } "userCfg": { "cache": null }
} }
} }

View File

@ -24,8 +24,8 @@ var _cfg;
// Default configs if for some reason we don't receive config params // Default configs if for some reason we don't receive config params
const _defaults = { const _defaults = {
installPath: (_os.platform() === 'win32' ? process.env.APPDATA : _os.platform() === 'darwin' ? `${process.env.HOME}/Library/Preferences`: `/var/local`) + '/BetterDiscord/lib/', 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/', dataPath: (_os.platform() === 'win32' ? process.env.APPDATA : _os.platform() === 'darwin' ? `${process.env.HOME}/Library/Preferences`: `/var/local`) + '/BetterDiscord/data',
emotesEnabled: true emotesEnabled: true
}; };
@ -105,4 +105,4 @@ class Core {
} }
exports.BetterDiscord = Core; exports.BetterDiscord = Core;