From 60a95aba108859e0239c970ce585c5f47b3268df Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Thu, 15 Aug 2024 01:58:23 +0800 Subject: [PATCH] feat: add official plugin repo --- src/core/ui/components/AddonPage.tsx | 2 ++ .../ui/settings/pages/PluginBrowser/index.tsx | 19 ++++++++++--------- src/core/ui/settings/pages/Plugins/index.tsx | 9 ++++++++- src/lib/plugins/index.ts | 8 ++++++-- src/lib/utils/constants.ts | 2 ++ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/core/ui/components/AddonPage.tsx b/src/core/ui/components/AddonPage.tsx index 4879369..f5d2a0f 100644 --- a/src/core/ui/components/AddonPage.tsx +++ b/src/core/ui/components/AddonPage.tsx @@ -24,6 +24,7 @@ interface AddonPageProps { card: ComponentType>; searchKeywords: SearchKeywords; onFabPress?: () => void; + ListHeaderComponent?: ComponentType; ListFooterComponent?: ComponentType; } @@ -45,6 +46,7 @@ export default function AddonPage({ card: CardComponent, ...pr const headerElement = ( + {props.ListHeaderComponent && } {settings.safeMode?.enabled && {props.safeModeMessage} {props.safeModeExtras} diff --git a/src/core/ui/settings/pages/PluginBrowser/index.tsx b/src/core/ui/settings/pages/PluginBrowser/index.tsx index 4dd5a86..0b4c127 100644 --- a/src/core/ui/settings/pages/PluginBrowser/index.tsx +++ b/src/core/ui/settings/pages/PluginBrowser/index.tsx @@ -3,6 +3,7 @@ import { installPlugin, isPluginInstalled, uninstallPlugin } from "@lib/plugins" import { BunnyPluginManifest } from "@lib/plugins/types"; import { showToast } from "@lib/ui/toasts"; import { safeFetch } from "@lib/utils"; +import { OFFICIAL_PLUGINS_REPO_URL } from "@lib/utils/constants"; import { Button, Card, FlashList, IconButton, Stack, Text } from "@metro/common/components"; import { QueryClient, QueryClientProvider, useMutation, useQuery } from "@tanstack/react-query"; import { chunk } from "es-toolkit"; @@ -17,8 +18,8 @@ async function arrayFromAsync(iterableOrArrayLike: AsyncIterable): Promise return arr; } -async function fetchManifest(id: string) { - const url = `https://bn-plugins.github.io/dist/plugins/${id}/manifest.json`; +async function fetchManifest(repoURL: string, id: string) { + const url = new URL(`plugins/${id}/manifest.json`, repoURL); const data = await safeFetch(url).then(d => d.json()); queryClient.setQueryData(["plugin-manifest-dist", { id }], data); @@ -26,12 +27,12 @@ async function fetchManifest(id: string) { return data as BunnyPluginManifest; } -async function* getManifests() { - const rawResponse = await safeFetch("https://bn-plugins.github.io/dist/repo.json"); +async function* getManifests(repoUrl: string) { + const rawResponse = await safeFetch(repoUrl); const pluginIds = Object.keys(await rawResponse.json()); for (const idChunks of chunk(pluginIds, 5)) { - const manifests = idChunks.map(fetchManifest); + const manifests = idChunks.map(id => fetchManifest(OFFICIAL_PLUGINS_REPO_URL, id)); for (const manifest of manifests) { yield await manifest; } @@ -74,10 +75,10 @@ function TrailingButtons(props: { id: string }) { ; } -function PluginCard(props: { id: string, manifest: BunnyPluginManifest; }) { +function PluginCard(props: { repoUrl: string, id: string, manifest: BunnyPluginManifest; }) { const { isPending, error, data: plugin } = useQuery({ queryKey: ["plugin-manifest-dist", { id: props.id }], - queryFn: () => fetchManifest(props.id) + queryFn: () => fetchManifest(props.repoUrl, props.id) }); return ( @@ -113,7 +114,7 @@ function PluginCard(props: { id: string, manifest: BunnyPluginManifest; }) { function BrowserPage() { const { data, error, isPending, refetch } = useQuery({ queryKey: ["plugins-repo-fetch"], - queryFn: () => arrayFromAsync(getManifests()) + queryFn: () => arrayFromAsync(getManifests(OFFICIAL_PLUGINS_REPO_URL)) }); if (error) { @@ -148,7 +149,7 @@ function BrowserPage() { contentContainerStyle={{ paddingBottom: 90, paddingHorizontal: 5 }} renderItem={({ item: manifest }: any) => ( - + )} />; diff --git a/src/core/ui/settings/pages/Plugins/index.tsx b/src/core/ui/settings/pages/Plugins/index.tsx index 1790e65..fc25f81 100644 --- a/src/core/ui/settings/pages/Plugins/index.tsx +++ b/src/core/ui/settings/pages/Plugins/index.tsx @@ -9,7 +9,7 @@ import { useProxy as useNewProxy } from "@lib/api/storage/new"; import { isPluginInstalled, pluginSettings, registeredPlugins } from "@lib/plugins"; import { Author } from "@lib/utils/types"; import { NavigationNative } from "@metro/common"; -import { Button, SegmentedControl, SegmentedControlPages, Text, useSegmentedControlState } from "@metro/common/components"; +import { Button, HelpMessage, SegmentedControl, SegmentedControlPages, Text, useSegmentedControlState } from "@metro/common/components"; import { ComponentProps } from "react"; import { useWindowDimensions, View } from "react-native"; @@ -87,6 +87,13 @@ export default function Plugins() { (useNewProxy(pluginSettings), [...registeredPlugins.values()].filter(p => isPluginInstalled(p.id)))} resolveItem={unifyBunnyPlugin} + ListHeaderComponent={() => ( + + + Bunny plugin system is in no way ready, try not getting yourself burnt ⚠️ + + + )} ListFooterComponent={() => ( {"Looking for more?"} diff --git a/src/lib/plugins/index.ts b/src/lib/plugins/index.ts index 70072eb..cd325fd 100644 --- a/src/lib/plugins/index.ts +++ b/src/lib/plugins/index.ts @@ -2,6 +2,7 @@ import { getCorePlugins } from "@core/plugins"; import { readFile, removeFile, writeFile } from "@lib/api/native/fs"; import { awaitStorage, createStorage, getPreloadedStorage, preloadStorageIfExists, updateStorageAsync } from "@lib/api/storage/new"; import { safeFetch } from "@lib/utils"; +import { OFFICIAL_PLUGINS_REPO_URL } from "@lib/utils/constants"; import { semver } from "@metro/common"; import { createBunnyPluginAPI } from "./api"; @@ -191,7 +192,7 @@ export async function updateRepository(repoUrl: string) { * Deletes a repository from registrations and uninstalls ALL plugins under this repository */ export async function deleteRepository(repoUrl: string) { - // Once when we have our "official repository", make sure to make it non-deleteable + assert(repoUrl !== OFFICIAL_PLUGINS_REPO_URL, repoUrl, "delete the official repository"); assert(pluginRepositories[repoUrl], repoUrl, "delete a non-registered repository"); const promQueues = [] as Promise[]; @@ -366,8 +367,11 @@ export async function checkAndRegisterUpdates() { corePluginInstances.set(id, instance); } + await updateRepository(OFFICIAL_PLUGINS_REPO_URL); await Promise.allSettled(Object.keys(pluginRepositories).map(async repo => { - await updateRepository(repo); + if (repo !== OFFICIAL_PLUGINS_REPO_URL) { + await updateRepository(repo); + } })); } diff --git a/src/lib/utils/constants.ts b/src/lib/utils/constants.ts index dc5430e..1885fdf 100644 --- a/src/lib/utils/constants.ts +++ b/src/lib/utils/constants.ts @@ -6,6 +6,8 @@ export const VD_PROXY_PREFIX = "https://vd-plugins.github.io/proxy"; export const BUNNY_PROXY_PREFIX = "https://bn-plugins.github.io/vd-proxy"; export const OLD_BUNNY_PROXY_PREFIX = "https://bunny-mod.github.io/plugins-proxy"; +export const OFFICIAL_PLUGINS_REPO_URL = "https://bn-plugins.github.io/dist/repo.json"; + // These are still Vendetta's export const DISCORD_SERVER_ID = "1015931589865246730"; export const PLUGINS_CHANNEL_ID = "1091880384561684561";