Skip to content

Commit

Permalink
refactor(plugins): update dist fetch directory
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Oct 23, 2024
1 parent 131c119 commit b37ff5b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/core/ui/settings/pages/PluginBrowser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function arrayFromAsync<T>(iterableOrArrayLike: AsyncIterable<T>): 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);
Expand Down Expand Up @@ -93,18 +93,18 @@ function PluginCard(props: { repoUrl: string, id: string, manifest: BunnyPluginM
<View style={{ flexDirection: "row", justifyContent: "space-between", alignItems: "center" }}>
<View style={{ flexShrink: 1 }}>
<Text numberOfLines={1} variant="heading-lg/semibold">
{plugin.name}
{plugin.display.name}
</Text>
<Text variant="text-md/semibold" color="text-muted">
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"}
</Text>
</View>
<View>
<TrailingButtons id={props.id} />
</View>
</View>
<Text variant="text-md/medium">
{plugin.description}
{plugin.display.description}
</Text>
</Stack>}
</Card>
Expand Down
16 changes: 8 additions & 8 deletions src/core/ui/settings/pages/Plugins/models/bunny.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfo
</View>
</View>
<View style={{ flexDirection: "row", justifyContent: "center", alignContent: "center" }}>
<Text variant="text-lg/medium">
{/* <Text variant="text-lg/medium">
Oops, you shouldn't see this!
</Text>
</Text> */}
</View>
</ScrollView>
</ActionSheet>;
Expand Down
11 changes: 0 additions & 11 deletions src/lib/addons/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const apiObjects = new Map<string, ReturnType<typeof createBunnyPluginAPI
export const pluginRepositories = createStorage<t.PluginRepoStorage>("plugins/repositories.json");
export const pluginSettings = createStorage<t.PluginSettingsStorage>("plugins/settings.json");

const manifestToId = new WeakMap<t.BunnyPluginManifest, string>();

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());
Expand Down Expand Up @@ -55,12 +53,6 @@ export function isCorePlugin(id: string) {
return corePluginInstances.has(id);
}

export function getId<T extends t.BunnyPluginManifest>(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<any> | null {
const instance = pluginInstances.get(id);
if (!instance) return null;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -186,7 +177,6 @@ export async function updateRepository(repoUrl: string) {
}

registeredPlugins.set(id, manifest);
manifestToId.set(manifest, id);
}

return updated;
Expand Down Expand Up @@ -382,7 +372,6 @@ export async function updatePlugins() {
};

registeredPlugins.set(id, instance.manifest);
manifestToId.set(instance.manifest, id);
corePluginInstances.set(id, instance);
}

Expand Down
10 changes: 3 additions & 7 deletions src/lib/addons/plugins/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions src/lib/addons/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}
4 changes: 2 additions & 2 deletions src/lib/api/native/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Theme } from "@lib/addons/themes";
import { VdThemeInfo } from "@lib/addons/themes";

// @ts-ignore
const pyonLoaderIdentity = globalThis.__PYON_LOADER__;
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ui/styles.ts
Original file line number Diff line number Diff line change
@@ -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<T> = { [P in keyof T]: ViewStyle | TextStyle | ImageStyle };
Expand All @@ -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<DiscordTextStyles, TextStyle>;
TextStyleSheet: Record<TextStyles, TextStyle>;
};

/**
Expand Down

0 comments on commit b37ff5b

Please sign in to comment.