[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;
|
let pluginJs: string;
|
||||||
|
|
||||||
|
// TODO: Remove duplicate error if possible
|
||||||
try {
|
try {
|
||||||
pluginJs = await (await fetch(new URL("plugin.js", url), { cache: "no-store" })).text()
|
pluginJs = await (await fetch(new URL("plugin.js", url), { cache: "no-store" })).text()
|
||||||
} catch {
|
} 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] = {
|
plugins[id] = {
|
||||||
id: id,
|
id: id,
|
||||||
manifest: pluginManifest,
|
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) {
|
export function evalPlugin(plugin: Plugin) {
|
||||||
// TODO: Refactor to not depend on own window object
|
// TODO: Refactor to not depend on own window object
|
||||||
const vendettaForPlugins = Object.assign({}, window.vendetta);
|
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);
|
const raw = (0, eval)(pluginString)(vendettaForPlugins);
|
||||||
return typeof ret == "function" ? ret() : ret;
|
const ret = typeof raw == "function" ? raw() : raw;
|
||||||
|
return ret.default || ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startPlugin(id: string) {
|
export function startPlugin(id: string) {
|
||||||
|
|
|
@ -36,7 +36,6 @@ export default function PluginCard({ plugin }: PluginCardProps) {
|
||||||
<FormSwitch
|
<FormSwitch
|
||||||
value={plugin.enabled}
|
value={plugin.enabled}
|
||||||
onValueChange={(v: boolean) => {
|
onValueChange={(v: boolean) => {
|
||||||
alert(v);
|
|
||||||
if (v) startPlugin(plugin.id); else stopPlugin(plugin.id);
|
if (v) startPlugin(plugin.id); else stopPlugin(plugin.id);
|
||||||
setEnabled(v);
|
setEnabled(v);
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue