feat: add official plugin repo
This commit is contained in:
parent
61286d8980
commit
60a95aba10
5 changed files with 28 additions and 12 deletions
|
|
@ -24,6 +24,7 @@ interface AddonPageProps<T extends object> {
|
|||
card: ComponentType<CardWrapper<T>>;
|
||||
searchKeywords: SearchKeywords;
|
||||
onFabPress?: () => void;
|
||||
ListHeaderComponent?: ComponentType<any>;
|
||||
ListFooterComponent?: ComponentType<any>;
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +46,7 @@ export default function AddonPage<T extends object>({ card: CardComponent, ...pr
|
|||
|
||||
const headerElement = (
|
||||
<View style={{ paddingBottom: 8 }}>
|
||||
{props.ListHeaderComponent && <props.ListHeaderComponent />}
|
||||
{settings.safeMode?.enabled && <View style={{ marginBottom: 10 }}>
|
||||
<HelpMessage messageType={0}>{props.safeModeMessage}</HelpMessage>
|
||||
{props.safeModeExtras}
|
||||
|
|
|
|||
|
|
@ -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<T>(iterableOrArrayLike: AsyncIterable<T>): 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 }) {
|
|||
</Stack>;
|
||||
}
|
||||
|
||||
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) => (
|
||||
<View style={{ paddingVertical: 6, paddingHorizontal: 8 }}>
|
||||
<PluginCard id={manifest.id} manifest={manifest} />
|
||||
<PluginCard repoUrl={OFFICIAL_PLUGINS_REPO_URL} id={manifest.id} manifest={manifest} />
|
||||
</View>
|
||||
)}
|
||||
/>;
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
<PluginPage
|
||||
useItems={() => (useNewProxy(pluginSettings), [...registeredPlugins.values()].filter(p => isPluginInstalled(p.id)))}
|
||||
resolveItem={unifyBunnyPlugin}
|
||||
ListHeaderComponent={() => (
|
||||
<View style={{ marginBottom: 10 }}>
|
||||
<HelpMessage messageType={0}>
|
||||
Bunny plugin system is in no way ready, try not getting yourself burnt ⚠️
|
||||
</HelpMessage>
|
||||
</View>
|
||||
)}
|
||||
ListFooterComponent={() => (
|
||||
<View style={{ alignItems: "center", justifyContent: "center", paddingTop: 16, gap: 12 }}>
|
||||
<Text variant="heading-lg/bold">{"Looking for more?"}</Text>
|
||||
|
|
|
|||
|
|
@ -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<unknown>[];
|
||||
|
|
@ -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);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue