From 2341448de21e9dbbd2339afd7f3f8f6eaf908eb4 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Sun, 26 Jun 2022 18:27:12 -0400 Subject: [PATCH] Add more sanity checks --- renderer/src/modules/pluginmanager.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/renderer/src/modules/pluginmanager.js b/renderer/src/modules/pluginmanager.js index ab421db9..c65f5ae8 100644 --- a/renderer/src/modules/pluginmanager.js +++ b/renderer/src/modules/pluginmanager.js @@ -9,7 +9,6 @@ import Events from "./emitter"; import Toasts from "../ui/toasts"; import Modals from "../ui/modals"; import SettingsRenderer from "../ui/settings"; -import Utilities from "./utilities"; const path = require("path"); const vm = require("vm"); @@ -91,18 +90,18 @@ export default new class PluginManager extends AddonManager { const isValid = typeof(addon.exports) === "function"; if (!isValid) return new AddonError(addon.name || addon.filename, addon.filename, "Plugin not a valid format.", {message: "Plugins should be either a function or a class", stack: ""}, this.prefix); - const isClass = Utilities.isClass(addon.exports); const PluginClass = addon.exports; const meta = Object.assign({}, addon); delete meta.exports; - const thePlugin = isClass ? new PluginClass(meta) : addon.exports(meta); + const thePlugin = PluginClass.prototype ? new PluginClass(meta) : addon.exports(meta); if (!thePlugin.start || !thePlugin.stop) return new AddonError(addon.name || addon.filename, addon.filename, "Missing start or stop function.", {message: "Plugins must have both a start and stop function.", stack: ""}, this.prefix); addon.instance = thePlugin; addon.name = thePlugin.getName ? thePlugin.getName() : addon.name; - addon.author = thePlugin.getAuthor ? thePlugin.getAuthor() : addon.author || "No author"; - addon.description = thePlugin.getDescription ? thePlugin.getDescription() : addon.description || "No description"; - addon.version = thePlugin.getVersion ? thePlugin.getVersion() : addon.version || "No version"; + addon.author = thePlugin.getAuthor ? thePlugin.getAuthor() : addon.author; + addon.description = thePlugin.getDescription ? thePlugin.getDescription() : addon.description; + addon.version = thePlugin.getVersion ? thePlugin.getVersion() : addon.version; + if (!addon.name || !addon.author || !addon.description || !addon.version) return new AddonError(addon.name || addon.filename, addon.filename, "Plugin is missing name, author, description, or version", {message: "Plugin must provide name, author, description, and version.", stack: ""}, this.prefix); try { if (typeof(addon.instance.load) == "function") addon.instance.load(); }