From b37ff5bce8b43da655d5ac027084c74fbb25d4bc Mon Sep 17 00:00:00 2001 From: pylixonly <82711525+pylixonly@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:16:47 +0800 Subject: [PATCH] refactor(plugins): update dist fetch directory --- .../ui/settings/pages/PluginBrowser/index.tsx | 8 ++++---- .../ui/settings/pages/Plugins/models/bunny.ts | 16 ++++++++-------- .../Plugins/sheets/PluginInfoActionSheet.tsx | 4 ++-- src/lib/addons/plugins/index.ts | 11 ----------- src/lib/addons/plugins/types.ts | 10 +++------- src/lib/addons/types.ts | 16 +++++++++------- src/lib/api/native/loader.ts | 4 ++-- src/lib/ui/styles.ts | 4 ++-- 8 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/core/ui/settings/pages/PluginBrowser/index.tsx b/src/core/ui/settings/pages/PluginBrowser/index.tsx index c1665de..c8a6a65 100644 --- a/src/core/ui/settings/pages/PluginBrowser/index.tsx +++ b/src/core/ui/settings/pages/PluginBrowser/index.tsx @@ -19,7 +19,7 @@ async function arrayFromAsync(iterableOrArrayLike: AsyncIterable): Promise } async function fetchManifest(repoURL: string, id: string) { - const url = new URL(`plugins/${id}/manifest.json`, repoURL); + const url = new URL(`builds/${id}/manifest.json`, repoURL); const data = await safeFetch(url).then(d => d.json()); queryClient.setQueryData(["plugin-manifest-dist", { id }], data); @@ -93,10 +93,10 @@ function PluginCard(props: { repoUrl: string, id: string, manifest: BunnyPluginM - {plugin.name} + {plugin.display.name} - by {plugin.authors.map(a => typeof a === "string" ? a : a.name).join(", ")} + by {plugin.display.authors?.map(a => typeof a === "string" ? a : a.name).join(", ") ?? "Unknown"} @@ -104,7 +104,7 @@ function PluginCard(props: { repoUrl: string, id: string, manifest: BunnyPluginM - {plugin.description} + {plugin.display.description} } diff --git a/src/core/ui/settings/pages/Plugins/models/bunny.ts b/src/core/ui/settings/pages/Plugins/models/bunny.ts index 5b5c583..1f7f203 100644 --- a/src/core/ui/settings/pages/Plugins/models/bunny.ts +++ b/src/core/ui/settings/pages/Plugins/models/bunny.ts @@ -1,4 +1,4 @@ -import { disablePlugin, enablePlugin, getId, getPluginSettingsComponent, isPluginEnabled, pluginSettings } from "@lib/addons/plugins"; +import { disablePlugin, enablePlugin, getPluginSettingsComponent, isPluginEnabled, pluginSettings } from "@lib/addons/plugins"; import { BunnyPluginManifest } from "@lib/addons/plugins/types"; import { useObservable } from "@lib/api/storage"; @@ -7,24 +7,24 @@ import { UnifiedPluginModel } from ".."; export default function unifyBunnyPlugin(manifest: BunnyPluginManifest): UnifiedPluginModel { return { id: manifest.id, - name: manifest.name, - description: manifest.description, - authors: manifest.authors, - isEnabled: () => isPluginEnabled(getId(manifest)), + name: manifest.display.name, + description: manifest.display.description, + authors: manifest.display.authors, + isEnabled: () => isPluginEnabled(manifest.id), isInstalled: () => manifest.id in pluginSettings, usePluginState() { useObservable([pluginSettings]); }, toggle(start: boolean) { start - ? enablePlugin(getId(manifest), true) - : disablePlugin(getId(manifest)); + ? enablePlugin(manifest.id, true) + : disablePlugin(manifest.id); }, resolveSheetComponent() { return import("../sheets/PluginInfoActionSheet"); }, getPluginSettingsComponent() { - return getPluginSettingsComponent(getId(manifest)); + return getPluginSettingsComponent(manifest.id); }, }; } diff --git a/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx b/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx index 7bc5eae..2a60a02 100644 --- a/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx +++ b/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx @@ -36,9 +36,9 @@ export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfo - + {/* Oops, you shouldn't see this! - + */} ; diff --git a/src/lib/addons/plugins/index.ts b/src/lib/addons/plugins/index.ts index 8d0b421..ca56d43 100644 --- a/src/lib/addons/plugins/index.ts +++ b/src/lib/addons/plugins/index.ts @@ -25,8 +25,6 @@ export const apiObjects = new Map("plugins/repositories.json"); export const pluginSettings = createStorage("plugins/settings.json"); -const manifestToId = new WeakMap(); - const _fetch = (repoUrl: string, path: string) => safeFetch(new URL(path, repoUrl), { cache: "no-store" }); const fetchJS = (repoUrl: string, path: string) => _fetch(repoUrl, path).then(r => r.text()); const fetchJSON = (repoUrl: string, path: string) => _fetch(repoUrl, path).then(r => r.json()); @@ -55,12 +53,6 @@ export function isCorePlugin(id: string) { return corePluginInstances.has(id); } -export function getId(manifest: T): string { - const id = manifestToId.get(manifest); - assert(id, manifest?.name ?? "unknown", "getting ID from an unregistered/invalid manifest"); - return id; -} - export function getPluginSettingsComponent(id: string): React.ComponentType | null { const instance = pluginInstances.get(id); if (!instance) return null; @@ -126,7 +118,6 @@ export async function refreshPlugin(id: string, repoUrl?: string) { registeredPlugins.delete(id); registeredPlugins.set(id, manifest); - manifestToId.set(manifest, id); await startPlugin(id); } @@ -186,7 +177,6 @@ export async function updateRepository(repoUrl: string) { } registeredPlugins.set(id, manifest); - manifestToId.set(manifest, id); } return updated; @@ -382,7 +372,6 @@ export async function updatePlugins() { }; registeredPlugins.set(id, instance.manifest); - manifestToId.set(instance.manifest, id); corePluginInstances.set(id, instance); } diff --git a/src/lib/addons/plugins/types.ts b/src/lib/addons/plugins/types.ts index fb7027a..833bf3f 100644 --- a/src/lib/addons/plugins/types.ts +++ b/src/lib/addons/plugins/types.ts @@ -1,5 +1,5 @@ import { createStorage } from "@core/vendetta/storage"; -import { Author } from "@lib/addons/types"; +import { BunnyManifest } from "@lib/addons/types"; import { Logger } from "@lib/utils/logger"; export interface PluginRepo { @@ -21,12 +21,8 @@ export interface PluginSettingsStorage { }; } -export interface BunnyPluginManifest { - readonly id: string; - readonly name: string; - readonly description: string; - readonly version: string; - readonly authors: Author[]; +export interface BunnyPluginManifest extends BunnyManifest { + readonly main: string; } export interface BunnyPluginManifestInternal extends BunnyPluginManifest { diff --git a/src/lib/addons/types.ts b/src/lib/addons/types.ts index 8ebc62f..d38615f 100644 --- a/src/lib/addons/types.ts +++ b/src/lib/addons/types.ts @@ -1,13 +1,15 @@ export type Author = { name: string, id?: `${bigint}`; }; export interface BunnyManifest { - id: string; - display: { - name: string; - description?: string; - authors?: Author[]; + readonly id: string; + readonly version: string; + readonly type: string; + readonly display: { + readonly name: string; + readonly description?: string; + readonly authors?: Author[]; }; - extras?: { - [key: string]: any; + readonly extras?: { + readonly [key: string]: any; }; } diff --git a/src/lib/api/native/loader.ts b/src/lib/api/native/loader.ts index fa63b80..63701b5 100644 --- a/src/lib/api/native/loader.ts +++ b/src/lib/api/native/loader.ts @@ -1,4 +1,4 @@ -import { Theme } from "@lib/addons/themes"; +import { VdThemeInfo } from "@lib/addons/themes"; // @ts-ignore const pyonLoaderIdentity = globalThis.__PYON_LOADER__; @@ -124,7 +124,7 @@ export function isThemeSupported() { return false; } -export function getStoredTheme(): Theme | null { +export function getStoredTheme(): VdThemeInfo | null { if (isPyonLoader()) { return pyonLoaderIdentity.storedTheme; } else if (isVendettaLoader()) { diff --git a/src/lib/ui/styles.ts b/src/lib/ui/styles.ts index 2c5d7de..c840d75 100644 --- a/src/lib/ui/styles.ts +++ b/src/lib/ui/styles.ts @@ -1,7 +1,7 @@ import { lazyDestructure, proxyLazy } from "@lib/utils/lazy"; import { findByProps, findByPropsLazy } from "@metro/wrappers"; import { isSemanticColor, resolveSemanticColor } from "@ui/color"; -import { DiscordTextStyles } from "@ui/types"; +import { TextStyles } from "@ui/types"; import { ImageStyle, StyleSheet, TextStyle, ViewStyle } from "react-native"; type NamedStyles = { [P in keyof T]: ViewStyle | TextStyle | ImageStyle }; @@ -10,7 +10,7 @@ const Styles = findByPropsLazy("createStyles"); export const { ThemeContext } = lazyDestructure(() => findByProps("ThemeContext"), { hint: "object" }); export const { TextStyleSheet } = lazyDestructure(() => findByProps("TextStyleSheet")) as unknown as { - TextStyleSheet: Record; + TextStyleSheet: Record; }; /**