Plugin and Theme loader splices.

This commit is contained in:
Jiiks 2015-12-12 18:29:06 +02:00
parent 4262dcf111
commit 85d947c122
9 changed files with 56 additions and 28 deletions

View File

@ -36,10 +36,6 @@
<Reference Include="asardotnet">
<HintPath>..\..\..\..\VSProjects\asardotnet\asardotnet\bin\Release\asardotnet.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />

View File

@ -1,13 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BetterDiscordWI.panels

View File

@ -175,6 +175,54 @@ namespace BetterDiscordWI.panels
AppendLog("Splicing function call");
lines.Add(line);
lines.Add("betterDiscord(mainWindow);");
AppendLog("Splicing plugin&theme loaders");
lines.Add(" mainWindow.webContents.on('dom-ready', function() {");
lines.Add(" var fs = require('fs');");
lines.Add(" fs.readdir('G:/BetterDiscord/plugins/',function(err,files) {");
lines.Add(" if (err) { console.log(err); return; } ");
lines.Add(" mainWindow.webContents.executeJavaScript('var bdplugins = {};');");
lines.Add(" files.forEach(function(fileName){");
lines.Add(" var plugin = fs.readFileSync('G:/BetterDiscord/plugins/' + fileName,'utf8');");
lines.Add(" var meta = plugin.split('\\n')[0];");
lines.Add(" if(meta.indexOf('META') < 0) {");
lines.Add(" console.log('BetterDiscord: ERROR[Plugin META not found in file: '+fileName+']');");
lines.Add(" return;");
lines.Add(" }");
lines.Add(" var pluginVar = meta.substring(meta.lastIndexOf('//META')+6, meta.lastIndexOf('*//'));");
lines.Add(" var parse = JSON.parse(pluginVar);");
lines.Add(" var pluginName = parse['name'];");
lines.Add(" console.log('BetterDiscord: Loading Plugin: ' + pluginName);");
lines.Add(" mainWindow.webContents.executeJavaScript(plugin);");
lines.Add(" mainWindow.webContents.executeJavaScript('(function() { var plugin = new '+pluginName+'(); bdplugins[plugin.getName()] = { \"plugin\": plugin, \"enabled\": false } })();')");
lines.Add(" });");
lines.Add(" });");
lines.Add("\n");
lines.Add(" fs.readdir('G:/BetterDiscord/themes/', function(err, files) {");
lines.Add(" if (err) { console.log(err); return; }");
lines.Add(" mainWindow.webContents.executeJavaScript('var bdthemes = {};');");
lines.Add(" files.forEach(function(fileName) {");
lines.Add(" var theme = fs.readFileSync('G:/BetterDiscord/themes/' + fileName, 'utf8');");
lines.Add(" var split = theme.split('\\n');");
lines.Add(" var meta = split[0];");
lines.Add(" if(meta.indexOf('META') < 0) {");
lines.Add(" console.log('BetterDiscord: ERROR[Theme META not found in file: '+fileName+']');");
lines.Add(" return;");
lines.Add(" }");
lines.Add(" var themeVar = meta.substring(meta.lastIndexOf('//META')+6, meta.lastIndexOf('*//'));");
lines.Add(" var parse = JSON.parse(themeVar);");
lines.Add(" var themeName = parse['name'];");
lines.Add(" console.log('BetterDiscord: Loading Theme: ' + themeName);");
lines.Add(" split.splice(0, 1);");
lines.Add(" theme = split.join('\\n');");
lines.Add(" theme = theme.replace(/(\\r\\n|\\n|\\r)/gm,'');");
lines.Add(" theme = theme.replace(/\\s/g, '');");
lines.Add(" mainWindow.webContents.executeJavaScript('var theme' + themeName + ' = \"' + escape(theme) + '\";');");
lines.Add(" mainWindow.webContents.executeJavaScript('(function() { bdthemes[theme'+themeName+'] = false })();');");
lines.Add(" });");
lines.Add(" });");
lines.Add(" });\n");
}
else if (line.Contains("main();"))
{

View File

@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms;
namespace BetterDiscordWI.panels
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -36,7 +36,7 @@ var settings = {
"Emote Auto Capitalization": { "id": "bda-es-4", "info": "Autocapitalize emote commands", "implemented": true },
"Override Default Emotes": { "id": "bda-es-5", "info": "Override default emotes", "implemented": false },
"Show Names": { "id": "bda-es-6", "info": "Show emote names on hover", "implemented": true }
};
}
var links = {
"Jiiks.net": { "text": "Jiiks.net", "href": "http://jiiks.net", "target": "_blank" },
@ -417,7 +417,6 @@ EmoteModule.prototype.getNodes = function(node) {
var bemotes = [];
var spoilered = [];
//TODO Edited emotes
EmoteModule.prototype.injectEmote = function(node) {
if(typeof emotesTwitch === 'undefined') return;
@ -1054,7 +1053,7 @@ SettingsPanel.prototype.construct = function() {
' <thead><tr><th>Name</th><th>Description</th><th>Author</th><th>Version</th><th></th></tr></thead><tbody>';
$.each(plugins, function() {
$.each(bdplugins, function() {
var plugin = this["plugin"];
settingsInner += '' +
@ -1245,7 +1244,7 @@ PluginModule.prototype.loadPlugins = function() {
this.loadPluginData();
$.each(plugins, function() {
$.each(bdplugins, function() {
var plugin = this["plugin"];
plugin.load();
@ -1272,10 +1271,10 @@ PluginModule.prototype.handlePlugin = function(checkbox) {
cb.prop("checked", enabled);
if(enabled) {
plugins[id]["plugin"].start();
bdplugins[id]["plugin"].start();
pluginCookie[id] = true;
} else {
plugins[id]["plugin"].stop();
bdplugins[id]["plugin"].stop();
pluginCookie[id] = false;
}
@ -1328,8 +1327,8 @@ BdApi.clearCSS = function(id) {
//Get another plugin
//name = name of plugin
BdApi.getPlugin = function(name) {
if(plugins.hasOwnProperty(name)) {
return plugins[name]["plugin"];
if(bdplugins.hasOwnProperty(name)) {
return bdplugins[name]["plugin"];
}
return null;
};