Themeloader
This commit is contained in:
parent
02379bd5d2
commit
c369887d2b
91
splice
91
splice
|
@ -3,8 +3,7 @@
|
||||||
_dataPath += "/BetterDiscord/";
|
_dataPath += "/BetterDiscord/";
|
||||||
|
|
||||||
mainWindow.webContents.on('dom-ready', function() {
|
mainWindow.webContents.on('dom-ready', function() {
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
if(!fs.existsSync(_dataPath)) {
|
if(!fs.existsSync(_dataPath)) {
|
||||||
console.log('BetterDiscord: Creating BD Dir');
|
console.log('BetterDiscord: Creating BD Dir');
|
||||||
fs.mkdirSync(_dataPath);
|
fs.mkdirSync(_dataPath);
|
||||||
|
@ -22,49 +21,51 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fs.readdir(_dataPath + "plugins/",function(err,files) {
|
fs.readdir(_dataPath + "plugins/",function(err,files) {
|
||||||
if (err) { console.log(err); return; }
|
if (err) { console.log(err); return; }
|
||||||
mainWindow.webContents.executeJavaScript('var bdplugins = {};');
|
mainWindow.webContents.executeJavaScript('var bdplugins = {};');
|
||||||
files.forEach(function(fileName){
|
files.forEach(function(fileName){
|
||||||
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+']');
|
console.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);
|
console.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 } })();')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
fs.readdir(_dataPath + 'themes/', function(err, files) {
|
fs.readdir(_dataPath + 'themes/', function(err, files) {
|
||||||
if (err) { console.log(err); return; }
|
if (err) { console.log(err); return; }
|
||||||
mainWindow.webContents.executeJavaScript('var bdthemes = {};');
|
mainWindow.webContents.executeJavaScript('var bdthemes = {};');
|
||||||
files.forEach(function(fileName) {
|
files.forEach(function(fileName) {
|
||||||
var theme = fs.readFileSync(_dataPath + 'themes/' + fileName, 'utf8');
|
var theme = fs.readFileSync(_dataPath + 'themes/' + fileName, 'utf8');
|
||||||
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+']');
|
console.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('*//'));
|
||||||
var parse = JSON.parse(themeVar);
|
var parse = JSON.parse(themeVar);
|
||||||
var themeName = parse['name'];
|
var themeName = parse['name'];
|
||||||
console.log('BetterDiscord: Loading Theme: ' + themeName);
|
var themeAuthor = parse['author'];
|
||||||
split.splice(0, 1);
|
var themeDescription = parse['description'];
|
||||||
theme = split.join('\n');
|
var themeVersion = parse['version'];
|
||||||
theme = theme.replace(/(\r\n|\n|\r)/gm,'');
|
console.log('BetterDiscord: Loading Theme: ' + themeName);
|
||||||
theme = theme.replace(/\s/g, '');
|
split.splice(0, 1);
|
||||||
mainWindow.webContents.executeJavaScript('var theme' + themeName + ' = "' + escape(theme) + '";');
|
theme = split.join('\n');
|
||||||
mainWindow.webContents.executeJavaScript('(function() { bdthemes[theme'+themeName+'] = false })();');
|
theme = theme.replace(/(\r\n|\n|\r)/gm,'');
|
||||||
});
|
theme = theme.replace(/\s/g, '');
|
||||||
});
|
mainWindow.webContents.executeJavaScript('(function() { bdthemes["'+themeName+'"] = { "enabled": false, "css": "'+escape(theme)+'", "description": "'+themeDescription+'", "author":"'+themeAuthor+'", "version":"'+themeVersion+'" } })();');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
_betterDiscord = new _betterDiscord.BetterDiscord(mainWindow);
|
_betterDiscord = new _betterDiscord.BetterDiscord(mainWindow);
|
||||||
|
|
Loading…
Reference in New Issue