Add more sanity checks
This commit is contained in:
parent
04eb399ea2
commit
2341448de2
|
@ -9,7 +9,6 @@ import Events from "./emitter";
|
||||||
import Toasts from "../ui/toasts";
|
import Toasts from "../ui/toasts";
|
||||||
import Modals from "../ui/modals";
|
import Modals from "../ui/modals";
|
||||||
import SettingsRenderer from "../ui/settings";
|
import SettingsRenderer from "../ui/settings";
|
||||||
import Utilities from "./utilities";
|
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
|
@ -91,18 +90,18 @@ export default new class PluginManager extends AddonManager {
|
||||||
const isValid = typeof(addon.exports) === "function";
|
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);
|
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 PluginClass = addon.exports;
|
||||||
const meta = Object.assign({}, addon);
|
const meta = Object.assign({}, addon);
|
||||||
delete meta.exports;
|
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);
|
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.instance = thePlugin;
|
||||||
addon.name = thePlugin.getName ? thePlugin.getName() : addon.name;
|
addon.name = thePlugin.getName ? thePlugin.getName() : addon.name;
|
||||||
addon.author = thePlugin.getAuthor ? thePlugin.getAuthor() : addon.author || "No author";
|
addon.author = thePlugin.getAuthor ? thePlugin.getAuthor() : addon.author;
|
||||||
addon.description = thePlugin.getDescription ? thePlugin.getDescription() : addon.description || "No description";
|
addon.description = thePlugin.getDescription ? thePlugin.getDescription() : addon.description;
|
||||||
addon.version = thePlugin.getVersion ? thePlugin.getVersion() : addon.version || "No version";
|
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 {
|
try {
|
||||||
if (typeof(addon.instance.load) == "function") addon.instance.load();
|
if (typeof(addon.instance.load) == "function") addon.instance.load();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue