Update PluginRepo.plugin.js

This commit is contained in:
Mirco Wittrien 2019-03-26 12:32:04 +01:00
parent d7c544abf0
commit e0569528ca
1 changed files with 52 additions and 17 deletions

View File

@ -3,7 +3,7 @@
class PluginRepo {
getName () {return "PluginRepo";}
getVersion () {return "1.7.4";}
getVersion () {return "1.7.5";}
getAuthor () {return "DevilBro";}
@ -11,7 +11,7 @@ class PluginRepo {
initConstructor () {
this.changelog = {
"fixed":[["BDContextMenu","Fixed compatibility with the newest version of BDContextMenu"]]
"fixed":[["Loading Issues","Fixed loading issues with Zerthox's plugins and fixed issues where an unloadable plugin would harshly slow down the loading process"]]
};
this.patchModules = {
@ -327,7 +327,7 @@ class PluginRepo {
item = item[item.length-1];
var settingsContextEntry = BDFDB.htmlToElement(this.settingsContextEntryMarkup);
settingsContextEntry.addEventListener("click", () => {
if (!this.loading.is) instance._reactInternalFiber.return.memoizedProps.closeContextMenu();
if (!this.loading.is) BDFDB.closeContextMenu(menu);
this.openPluginRepoModal();
});
item.parentElement.insertBefore(settingsContextEntry, item.nextElementSibling);
@ -746,20 +746,55 @@ class PluginRepo {
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 instPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null;
if (instPlugin && instPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase() && instPlugin.getVersion() != plugin.getVersion) outdated++;
webview.getWebContents().executeJavaScript(`
try {
var getString = (obj) => {
var string = "";
if (typeof obj == "string") string = obj;
else if (obj && obj.props) {
if (typeof obj.props.children == "string") string = obj.props.children;
else if (Array.isArray(obj.props.children)) for (let c of obj.props.children) string += typeof c == "string" ? c : getString(c);
}
return string;
};
var WebModulesFind = (filter) => {
const id = "PluginRepo-WebModules";
const req = typeof(global.window.webpackJsonp) == "function" ? global.window.webpackJsonp([], {[id]: (module, exports, req) => exports.default = req}, [id]).default : global.window.webpackJsonp.push([[], {[id]: (module, exports, req) => module.exports = req}, [[id]]]);
delete req.m[id];
delete req.c[id];
for (let m in req.c) {
if (req.c.hasOwnProperty(m)) {
var module = req.c[m].exports;
if (module && module.__esModule && module.default && filter(module.default)) return module.default;
if (module && filter(module)) return module;
}
}
};
var WebModulesFindByProperties = (properties) => {
return WebModulesFind(module => properties.every(prop => module[prop] !== undefined));
};
global.BDV2 = {};
global.BDV2.react = WebModulesFindByProperties(['createElement', 'cloneElement']);
global.BDV2.reactDom = WebModulesFindByProperties(['render', 'findDOMNode']);
var p = new ` + name + `();
var data = {
"getName":getString(p.getName()),
"getAuthor":getString(p.getAuthor()),
"getVersion":getString(p.getVersion()),
"getDescription":getString(p.getDescription())
};
Promise.resolve(data);
}
catch (err) {
Promise.resolve(null);
}`
).then(plugin => {
if (plugin) {
plugin.url = url;
this.loadedPlugins[url] = plugin;
var instPlugin = window.bdplugins[plugin.getName] ? window.bdplugins[plugin.getName].plugin : null;
if (instPlugin && instPlugin.getAuthor().toUpperCase() == plugin.getAuthor.toUpperCase() && instPlugin.getVersion() != plugin.getVersion) outdated++;
}
webview.getWebContents().reload();
webviewrunning = false;
runInWebview();