Alternate storage fix

This commit is contained in:
Jiiks 2017-01-09 07:41:36 +02:00
parent 9c99e8a27d
commit 6e1816d973
1 changed files with 55 additions and 35 deletions

View File

@ -6,8 +6,29 @@
* Last Update: 01/05/2016 * Last Update: 01/05/2016
* https://github.com/Jiiks/BetterDiscordApp * https://github.com/Jiiks/BetterDiscordApp
*/ */
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.75;
var supportedVersion = "0.2.5"; var supportedVersion = "0.2.5";
var mainObserver; var mainObserver;
@ -997,7 +1018,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 +1121,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 +1149,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 +1162,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,7 +1189,7 @@ 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 != undefined) {
this.favoriteEmotes = JSON.parse(atob(fe)); this.favoriteEmotes = JSON.parse(atob(fe));
} }
@ -1332,8 +1353,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 +1384,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 +1450,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 +1745,7 @@ SettingsPanel.prototype.construct = function () {
//End emote settings //End emote settings
//Custom CSS Editor //Custom CSS Editor
var ccss = atob(localStorage.getItem("bdcustomcss")); var ccss = atob(window.bdStorage.get("bdcustomcss"));
customCssEditor.applyCustomCss(ccss, true, false); customCssEditor.applyCustomCss(ccss, true, false);
settingsInner += '\ settingsInner += '\
@ -1977,8 +1997,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 +2061,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 +2349,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
} }
}; };