[Plugins] Minor but necessary fixes
This commit is contained in:
parent
5c4026685e
commit
57df878f65
2 changed files with 8 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -36,7 +36,6 @@ export default function PluginCard({ plugin }: PluginCardProps) {
|
|||
<FormSwitch
|
||||
value={plugin.enabled}
|
||||
onValueChange={(v: boolean) => {
|
||||
alert(v);
|
||||
if (v) startPlugin(plugin.id); else stopPlugin(plugin.id);
|
||||
setEnabled(v);
|
||||
}}
|
||||
|
|
Loading…
Reference in a new issue