[Plugins] Move to support polymanifest

This commit is contained in:
Beef 2023-01-04 22:39:28 +00:00
parent 57df878f65
commit 62933bc5ba
3 changed files with 19 additions and 7 deletions

15
src/def.d.ts vendored
View file

@ -37,11 +37,22 @@ interface Assets {
[id: string]: Asset; [id: string]: Asset;
} }
interface PluginAuthor {
name: string;
id: string;
}
// See https://github.com/vendetta-mod/polymanifest
interface PluginManifest { interface PluginManifest {
name: string; name: string;
description: string; description: string;
icon?: string; authors: PluginAuthor[];
author: string; main: string;
hash: string;
// Vendor-specific field, contains our own data
vendetta: {
icon: string;
};
} }
interface Plugin { interface Plugin {

View file

@ -27,7 +27,8 @@ export async function fetchPlugin(url: string) {
// TODO: Remove duplicate error if possible // TODO: Remove duplicate error if possible
try { try {
pluginJs = await (await fetch(new URL("plugin.js", url), { cache: "no-store" })).text() // by polymanifest spec, plugins should always specify their main file, but just in case
pluginJs = await (await fetch(new URL(pluginManifest.main || "index.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}`);
} }

View file

@ -1,8 +1,8 @@
import { ReactNative as RN, stylesheet } from "@metro/common"; import { ReactNative as RN, stylesheet } from "@metro/common";
import { Forms } from "@ui/components"; import { Forms } from "@ui/components";
import { Plugin } from "@types"; import { Plugin } from "@types";
import { getAssetIDByName } from "@/ui/assets"; import { getAssetIDByName } from "@ui/assets";
import { startPlugin, stopPlugin } from "@/lib/plugins"; import { startPlugin, stopPlugin } from "@lib/plugins";
const { FormRow, FormSwitch } = Forms; const { FormRow, FormSwitch } = Forms;
@ -30,8 +30,8 @@ export default function PluginCard({ plugin }: PluginCardProps) {
<RN.View style={styles.card}> <RN.View style={styles.card}>
<FormRow <FormRow
style={styles.header} style={styles.header}
label={`${plugin.manifest.name} by ${plugin.manifest.author}`} label={`${plugin.manifest.name} by ${plugin.manifest.authors.map(i => i.name).join(", ")}`}
leading={<FormRow.Icon source={getAssetIDByName(plugin.manifest.icon || "ic_application_command_24px")} />} leading={<FormRow.Icon source={getAssetIDByName(plugin.manifest.vendetta.icon || "ic_application_command_24px")} />}
trailing={ trailing={
<FormSwitch <FormSwitch
value={plugin.enabled} value={plugin.enabled}