fixed problems with PluginRepo
This commit is contained in:
parent
fb1b4c27fe
commit
9711b03ff6
|
@ -221,7 +221,7 @@ class PluginRepo {
|
||||||
|
|
||||||
getDescription () {return "Allows you to look at all plugins from the plugin repo and download them on the fly. Repo button is in the plugins settings.";}
|
getDescription () {return "Allows you to look at all plugins from the plugin repo and download them on the fly. Repo button is in the plugins settings.";}
|
||||||
|
|
||||||
getVersion () {return "1.5.5";}
|
getVersion () {return "1.5.6";}
|
||||||
|
|
||||||
getAuthor () {return "DevilBro";}
|
getAuthor () {return "DevilBro";}
|
||||||
|
|
||||||
|
@ -652,7 +652,8 @@ class PluginRepo {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPlugins () {
|
loadPlugins () {
|
||||||
var getPluginInfo, outdated = 0, i = 0;
|
var getPluginInfo, createWebview, runInWebview;
|
||||||
|
var webview, webviewrunning = false, webviewqueue = [], outdated = 0, i = 0;
|
||||||
var tags = ["getName", "getVersion", "getAuthor", "getDescription"];
|
var tags = ["getName", "getVersion", "getAuthor", "getDescription"];
|
||||||
var seps = ["\"", "\'", "\`"];
|
var seps = ["\"", "\'", "\`"];
|
||||||
let request = require("request");
|
let request = require("request");
|
||||||
|
@ -662,21 +663,22 @@ class PluginRepo {
|
||||||
this.grabbedPlugins = result.split("\n");
|
this.grabbedPlugins = result.split("\n");
|
||||||
this.foundPlugins = this.grabbedPlugins.concat(BDFDB.loadData("ownlist", this, "ownlist") || []);
|
this.foundPlugins = this.grabbedPlugins.concat(BDFDB.loadData("ownlist", this, "ownlist") || []);
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
createWebview().then((webview) => {
|
getPluginInfo(() => {
|
||||||
getPluginInfo(webview, () => {
|
var finishCounter = 0, finishInterval = setInterval(() => {
|
||||||
this.loading = false;
|
if ((webviewqueue.length == 0 && !webviewrunning) || finishCounter > 300) {
|
||||||
console.log("PluginRepo: Finished fetching Plugins.");
|
clearInterval(finishInterval);
|
||||||
if (document.querySelector(".bd-pluginrepobutton")) BDFDB.showToast(`Finished fetching Plugins.`, {type:"success"});
|
if (typeof webview != "undefined") webview.remove();
|
||||||
if (outdated > 0) {
|
this.loading = false;
|
||||||
var text = `${outdated} of your Plugins ${outdated == 1 ? "is" : "are"} outdated. Check:`;
|
console.log("PluginRepo: Finished fetching Plugins.");
|
||||||
var bar = BDFDB.createNotificationsBar(text,{type:"danger",btn:"PluginRepo",selector:"pluginrepo-notice"});
|
if (document.querySelector(".bd-pluginrepobutton")) BDFDB.showToast(`Finished fetching Plugins.`, {type:"success"});
|
||||||
$(bar).on("click." + this.getName(), BDFDB.dotCN.noticebutton, (e) => {
|
if (outdated > 0) {
|
||||||
this.openPluginRepoModal(true);
|
var text = `${outdated} of your Plugins ${outdated == 1 ? "is" : "are"} outdated. Check:`;
|
||||||
e.delegateTarget.querySelector(BDFDB.dotCN.noticedismiss).click();
|
var bar = BDFDB.createNotificationsBar(text,{type:"danger",btn:"PluginRepo",selector:"pluginrepo-notice"});
|
||||||
});
|
$(bar).on("click." + this.getName(), BDFDB.dotCN.noticebutton, (e) => {
|
||||||
}
|
this.openPluginRepoModal(true);
|
||||||
setTimeout(() => {
|
e.delegateTarget.querySelector(BDFDB.dotCN.noticedismiss).click();
|
||||||
webview.remove();
|
});
|
||||||
|
}
|
||||||
if (BDFDB.myData.id == "278543574059057154") {
|
if (BDFDB.myData.id == "278543574059057154") {
|
||||||
let wrongUrls = [];
|
let wrongUrls = [];
|
||||||
for (let url of this.foundPlugins) if (url && !this.loadedPlugins[url] && !wrongUrls.includes(url)) wrongUrls.push(url);
|
for (let url of this.foundPlugins) if (url && !this.loadedPlugins[url] && !wrongUrls.includes(url)) wrongUrls.push(url);
|
||||||
|
@ -689,13 +691,14 @@ class PluginRepo {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},10000);
|
}
|
||||||
});
|
else finishCounter++;
|
||||||
|
},1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getPluginInfo = (webview, callback) => {
|
getPluginInfo = (callback) => {
|
||||||
if (i >= this.foundPlugins.length) {
|
if (i >= this.foundPlugins.length) {
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
|
@ -737,47 +740,61 @@ class PluginRepo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let name = body.replace(new RegExp("\\s*\:\\s*", "g"), ":").split('"name":"');
|
webviewqueue.push({body, url});
|
||||||
if (name.length > 1 && webview) {
|
runInWebview();
|
||||||
name = name[1].split('"')[0];
|
|
||||||
webview.getWebContents().executeJavaScript(body).then(() => {
|
|
||||||
webview.getWebContents().executeJavaScript(`
|
|
||||||
var p = new ` + name + `();
|
|
||||||
var data = {
|
|
||||||
"getName":p.getName(),
|
|
||||||
"getAuthor":p.getAuthor(),
|
|
||||||
"getVersion":p.getVersion(),
|
|
||||||
"getDescription":p.getDescription()
|
|
||||||
};
|
|
||||||
Promise.resolve(data);`
|
|
||||||
).then((plugin) => {
|
|
||||||
plugin.url = url;
|
|
||||||
this.loadedPlugins[url] = plugin;
|
|
||||||
var installedPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null;
|
|
||||||
if (installedPlugin && installedPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase() && installedPlugin.getVersion() != plugin.getVersion) outdated++;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
getPluginInfo(webview, callback);
|
getPluginInfo(callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWebview () {
|
createWebview = () => {
|
||||||
return new Promise(function(callback) {
|
return new Promise(function(callback) {
|
||||||
var webview;
|
if (typeof webview != "undefined") webview.remove();
|
||||||
|
webviewrunning = true;
|
||||||
webview = document.createElement("webview");
|
webview = document.createElement("webview");
|
||||||
webview.src = "https://discordapp.com/";
|
webview.src = "https://discordapp.com/";
|
||||||
webview.setAttribute("webview-PluginRepo", null);
|
webview.setAttribute("webview-PluginRepo", null);
|
||||||
webview.style.setProperty("visibility", "hidden");
|
webview.style.setProperty("visibility", "hidden");
|
||||||
webview.addEventListener("dom-ready", () => {
|
webview.addEventListener("dom-ready", () => {
|
||||||
callback(webview);
|
callback();
|
||||||
});
|
});
|
||||||
document.body.appendChild(webview);
|
document.body.appendChild(webview);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runInWebview = () => {
|
||||||
|
if (webviewrunning) return;
|
||||||
|
let webviewdata = webviewqueue.shift();
|
||||||
|
if (!webviewdata) return;
|
||||||
|
createWebview().then(() => {
|
||||||
|
let {body, url} = webviewdata;
|
||||||
|
let name = body.replace(new RegExp("\\s*\:\\s*", "g"), ":").split('"name":"');
|
||||||
|
if (name.length > 1) {
|
||||||
|
name = name[1].split('"')[0];
|
||||||
|
webview.getWebContents().executeJavaScript(body).then(() => {
|
||||||
|
webview.getWebContents().executeJavaScript(`
|
||||||
|
var p = new ` + name + `();
|
||||||
|
var data = {
|
||||||
|
"getName":p.getName(),
|
||||||
|
"getAuthor":p.getAuthor(),
|
||||||
|
"getVersion":p.getVersion(),
|
||||||
|
"getDescription":p.getDescription()
|
||||||
|
};
|
||||||
|
Promise.resolve(data);`
|
||||||
|
).then((plugin) => {
|
||||||
|
plugin.url = url;
|
||||||
|
this.loadedPlugins[url] = plugin;
|
||||||
|
var installedPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null;
|
||||||
|
if (installedPlugin && installedPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase() && installedPlugin.getVersion() != plugin.getVersion) outdated++;
|
||||||
|
webviewrunning = false;
|
||||||
|
runInWebview();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForNewPlugins () {
|
checkForNewPlugins () {
|
||||||
|
|
Loading…
Reference in New Issue