From 57df878f65c7977f415f48a8c0348d45770d4efe Mon Sep 17 00:00:00 2001 From: Beef Date: Wed, 4 Jan 2023 08:01:56 +0000 Subject: [PATCH] [Plugins] Minor but necessary fixes --- src/lib/plugins.ts | 15 ++++++++------- src/ui/settings/components/PluginCard.tsx | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index 6ab18c7..0a4c6d6 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -25,12 +25,15 @@ export async function fetchPlugin(url: string) { let pluginJs: string; + // TODO: Remove duplicate error if possible try { pluginJs = await (await fetch(new URL("plugin.js", url), { cache: "no-store" })).text() } catch { - throw new Error(`Failed to fetch JS for ${url}`) + throw new Error(`Failed to fetch JS for ${url}`); } + if (pluginJs.length === 0) throw new Error(`Failed to fetch JS for ${url}`); + plugins[id] = { id: id, manifest: pluginManifest, @@ -39,16 +42,14 @@ export async function fetchPlugin(url: string) { }; } -// Bundlers don't like eval -const theSystemHasBeenDestroyed = eval; - export function evalPlugin(plugin: Plugin) { // TODO: Refactor to not depend on own window object const vendettaForPlugins = Object.assign({}, window.vendetta); - const pluginString = `(vendetta)=>{return ${plugin.js}}\n//# sourceURL=${plugin.id}`; + const pluginString = `vendetta=>{return ${plugin.js}}\n//# sourceURL=${plugin.id}`; - const ret = theSystemHasBeenDestroyed(pluginString)(vendettaForPlugins); - return typeof ret == "function" ? ret() : ret; + const raw = (0, eval)(pluginString)(vendettaForPlugins); + const ret = typeof raw == "function" ? raw() : raw; + return ret.default || ret; } export function startPlugin(id: string) { diff --git a/src/ui/settings/components/PluginCard.tsx b/src/ui/settings/components/PluginCard.tsx index 9a03468..1adb8ed 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/ui/settings/components/PluginCard.tsx @@ -36,7 +36,6 @@ export default function PluginCard({ plugin }: PluginCardProps) { { - alert(v); if (v) startPlugin(plugin.id); else stopPlugin(plugin.id); setEnabled(v); }}