diff --git a/lib/BetterDiscord.devp.js b/lib/BetterDiscord.devp.js
index 3ff24cdd..fe913f51 100644
--- a/lib/BetterDiscord.devp.js
+++ b/lib/BetterDiscord.devp.js
@@ -1,3 +1,5 @@
+'use strict';
+
var _fs = require("fs");
var _config = require("./config.json");
var _utils = require("./utils");
@@ -14,6 +16,7 @@ var _extData = {};
function BetterDiscord(mainWindow) {
+ console.log("WTHFHUFHEIUWHFEUIHFWIUHFEIU");
_mainWindow = mainWindow;
_cfg = _config.cfg;
@@ -22,7 +25,7 @@ function BetterDiscord(mainWindow) {
_utils2 = new _utils.Utils(mainWindow);
createAndCheckData();
-};
+}
function createAndCheckData() {
getUtils().log("Checking data/cache");
@@ -61,7 +64,7 @@ function createAndCheckData() {
getUtils().err(err);
exit(err.message);
}
-};
+}
function init() {
getUtils().log("Initializing");
@@ -90,9 +93,8 @@ function init() {
getUtils().log("Hash: " + _cfg.hash);
initUpdater();
-
});
-};
+}
function initUpdater() {
getUtils().log("Getting updater");
@@ -120,7 +122,7 @@ function initUpdater() {
updateExtData();
start();
});
-};
+}
function updateExtData() {
getUtils().log("Updating ext data");
@@ -286,19 +288,21 @@ function updateExtData() {
'self': 'load-emoteData-bttv-2'
}
};
-};
+}
function start() {
getUtils().log("Starting up");
try {
var webContents = getUtils().getWebContents();
-
+
getUtils().log("Hooking dom-ready");
webContents.on('dom-ready', domReady);
getUtils().log("Hooked dom-ready");
webContents.on('did-finish-loading', function() {
- if(domReadyHooked)return;
+ if(domReadyHooked) {
+ return;
+ }
getUtils().log("Hooking did-finish-loading failsafe");
domReady();
getUtils().log("Hooked did-finish-loading failsafe");
@@ -307,7 +311,7 @@ function start() {
}catch(err) {
exit(err);
}
-};
+}
var domReadyHooked = false;
var ipcHooked = false;
@@ -320,14 +324,12 @@ function domReady() {
}
ipcHooked = true;
load(false);
-};
+}
function load(reload) {
getUtils().log(reload ? "Reloading" : "Loading");
initLoaders();
-
-
-};
+}
function initLoaders() {
try {
@@ -339,11 +341,10 @@ function initLoaders() {
loadPlugins();
loadThemes();
-
}catch(err) {
exit(err);
}
-};
+}
function loadPlugins() {
var pluginPath = _cfg.dataPath + "plugins/";
@@ -357,8 +358,13 @@ function loadPlugins() {
var pluginErrors = [];
getUtils().injectVar("bdplugins", "{}");
+
files.forEach(function(fileName) {
- if(!fileName.endsWith(".plugin.js")) return;
+ if(!fileName.endsWith(".plugin.js")) {
+ getUtils().log("Invalid plugin detected: " + fileName);
+ return;
+ }
+
var plugin = _fs.readFileSync(pluginPath + fileName, 'utf8');
var meta = plugin.split(_eol)[0];
@@ -370,25 +376,85 @@ function loadPlugins() {
});
if(pluginErrors.length > 0) {
- getUtils().alert("The following plugins could not be loaded", pluginErrors.join("
"));
+ getUtils().alert("The following plugin(s) could not be loaded", pluginErrors.join("
"));
}
});
-};
+}
function loadThemes() {
+ var themePath = _cfg.dataPath + "themes/";
+ _fs.readdir(themePath, function(err, files) {
+ if(err) {
+ getUtils().log(err);
+ getUtils().alert(err);
+ return;
+ }
-};
+ var themeErrors = [];
+
+ getUtils().injectVar("bdthtmes", "{}");
+
+ files.forEach(function(fileName) {
+ if(!fileName.endsWith(".theme.css")) {
+ getUtils().log("Invalid theme detected " + fileName);
+ return;
+ }
+ var theme = _fs.readFileSync(themePath + fileName, 'utf8');
+ var split = theme.split(_eol);
+ var meta = split[0];
+ if(meta.indexOf('META') < 0) {
+ getUtils().warn("Theme META not found in file: " + fileName);
+ themeErrors.push(fileName + " Reason: Theme META not found");
+ return;
+ }
+ var themeVar = meta.substring(meta.lastIndexOf('//META') + 6, meta.lastIndexOf('*//'));
+ var themeInfo;
+ try {
+ themeInfo = JSON.parse(themeVar);
+ }catch(err) {
+ getUtils().warn("Failed to parse theme META in file ("+err+"): " + fileName);
+ themeErrors.push(fileName + " Reason: Failed to parse theme META (" + err + ")");
+ return;
+ }
+
+ if(themeInfo['name'] == undefined) {
+ getUtils().warn("Missing theme name in file: " + fileName);
+ themeErrors.push(fileName + " Reason: Missing theme name");
+ return;
+ }
+ if(themeInfo['author'] == undefined) {
+ getUtils().warn("Missing author name in file: " + fileName);
+ }
+ if(themeInfo['description'] == undefined) {
+ getUtils().warn("Missing description in file: " + fileName);
+ }
+ if(themeInfo['version'] == undefined) {
+ getUtils().warn("Missing version in file: " + fileName);
+ }
+
+ getUtils().log("Loading theme: " + themeInfo['name']);
+ split.splice(0, 1);
+ theme = split.join('\n');
+ theme = theme.replace(/(\r\n|\n|\r)/gm, '');
+
+ });
+
+ if(themeErrors.length > 0) {
+ getUtils().alert("The following theme(s) could not be loaded", themeErrors.join("
"));
+ }
+ });
+}
function getUtils() {
return _utils2;
-};
+}
function exit(reason) {
error = true;
getUtils().log("Exiting. Reason: " + reason);
getUtils().saveLogs(_cfg.dataPath);
getUtils().alert("Something went wrong :(", reason);
-};
+}
exports.BetterDiscord = BetterDiscord;
\ No newline at end of file
diff --git a/lib/Utils.js b/lib/Utils.js
index b4023801..4956d291 100644
--- a/lib/Utils.js
+++ b/lib/Utils.js
@@ -15,30 +15,6 @@ var logs = "";
function Utils(mainWindow) {
_mainWindow = mainWindow;
-
- //Let's inject a decent alert box
- var bdAlert = '\
-