From 62933bc5bac320b360f690d320123789e96b58e7 Mon Sep 17 00:00:00 2001 From: Beef Date: Wed, 4 Jan 2023 22:39:28 +0000 Subject: [PATCH] [Plugins] Move to support polymanifest --- src/def.d.ts | 15 +++++++++++++-- src/lib/plugins.ts | 3 ++- src/ui/settings/components/PluginCard.tsx | 8 ++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/def.d.ts b/src/def.d.ts index c25d151..eff8a91 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -37,11 +37,22 @@ interface Assets { [id: string]: Asset; } +interface PluginAuthor { + name: string; + id: string; +} + +// See https://github.com/vendetta-mod/polymanifest interface PluginManifest { name: string; description: string; - icon?: string; - author: string; + authors: PluginAuthor[]; + main: string; + hash: string; + // Vendor-specific field, contains our own data + vendetta: { + icon: string; + }; } interface Plugin { diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index 0a4c6d6..ac534f8 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -27,7 +27,8 @@ export async function fetchPlugin(url: string) { // TODO: Remove duplicate error if possible 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 { throw new Error(`Failed to fetch JS for ${url}`); } diff --git a/src/ui/settings/components/PluginCard.tsx b/src/ui/settings/components/PluginCard.tsx index 1adb8ed..79f0e8a 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/ui/settings/components/PluginCard.tsx @@ -1,8 +1,8 @@ import { ReactNative as RN, stylesheet } from "@metro/common"; import { Forms } from "@ui/components"; import { Plugin } from "@types"; -import { getAssetIDByName } from "@/ui/assets"; -import { startPlugin, stopPlugin } from "@/lib/plugins"; +import { getAssetIDByName } from "@ui/assets"; +import { startPlugin, stopPlugin } from "@lib/plugins"; const { FormRow, FormSwitch } = Forms; @@ -30,8 +30,8 @@ export default function PluginCard({ plugin }: PluginCardProps) { } + label={`${plugin.manifest.name} by ${plugin.manifest.authors.map(i => i.name).join(", ")}`} + leading={} trailing={