[Plugins] Move to support polymanifest
This commit is contained in:
parent
57df878f65
commit
62933bc5ba
3 changed files with 19 additions and 7 deletions
15
src/def.d.ts
vendored
15
src/def.d.ts
vendored
|
@ -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 {
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
|
|
|
@ -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) {
|
|||
<RN.View style={styles.card}>
|
||||
<FormRow
|
||||
style={styles.header}
|
||||
label={`${plugin.manifest.name} by ${plugin.manifest.author}`}
|
||||
leading={<FormRow.Icon source={getAssetIDByName(plugin.manifest.icon || "ic_application_command_24px")} />}
|
||||
label={`${plugin.manifest.name} by ${plugin.manifest.authors.map(i => i.name).join(", ")}`}
|
||||
leading={<FormRow.Icon source={getAssetIDByName(plugin.manifest.vendetta.icon || "ic_application_command_24px")} />}
|
||||
trailing={
|
||||
<FormSwitch
|
||||
value={plugin.enabled}
|
||||
|
|
Loading…
Reference in a new issue