feat: implemet basic plugin info

This commit is contained in:
amsyarasyiq 2024-07-30 21:04:41 +08:00
parent 5fe3025339
commit a198b71074
8 changed files with 55 additions and 18 deletions

View file

@ -7,7 +7,7 @@ interface CorePlugin {
// Called from @lib/plugins
export const getCorePlugins = (): Record<string, CorePlugin> => ({
"bunny.quickinstall": require("./vd-quick-install")
"bunny.quickinstall": require("./quickinstall")
});
/**

View file

@ -4,7 +4,8 @@ import PluginCard from "@core/ui/settings/pages/Plugins/PluginCard";
import { VdPluginManager, VendettaPlugin } from "@core/vendetta/plugins";
import { settings } from "@lib/api/settings";
import { useProxy } from "@lib/api/storage";
import { registeredPlugins } from "@lib/plugins";
import { useProxy as useProxyNew } from "@lib/api/storage/new";
import { getId, getPluginSettingsComponent, isPluginEnabled, pluginSettings, registeredPlugins, startPlugin, stopPlugin } from "@lib/plugins";
import { BunnyPluginManifest } from "@lib/plugins/types";
import { Author } from "@lib/utils/types";
import { SegmentedControl, SegmentedControlPages, useSegmentedControlState } from "@metro/common/components";
@ -52,25 +53,28 @@ function resolveFromVdPlugin(vdPlugin: VendettaPlugin): PluginManifest {
}
function resolveFromBunnyPlugin(manifest: BunnyPluginManifest): PluginManifest {
return {
id: manifest.id,
name: manifest.name,
description: manifest.description,
authors: manifest.authors,
isEnabled() {
return false;
return isPluginEnabled(getId(manifest));
},
usePluginState() {
useProxyNew(pluginSettings);
},
toggle(start: boolean) {
start
? startPlugin(getId(manifest))
: stopPlugin(getId(manifest));
},
resolveSheetComponent() {
return import("./sheets/PluginInfoActionSheet");
},
getPluginSettingsComponent() {
return null;
return getPluginSettingsComponent(getId(manifest));
},
};
}

View file

@ -1,3 +1,35 @@
export default function PluginInfoActionSheet() {
return <></>;
import { findAssetId } from "@lib/api/assets";
import { hideSheet } from "@lib/ui/sheets";
import { ActionSheet, Button, Text } from "@metro/common/components";
import { ScrollView, View } from "react-native";
import { PluginInfoActionSheetProps } from "./common";
export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfoActionSheetProps) {
plugin.usePluginState();
return <ActionSheet>
<ScrollView>
<View style={{ flexDirection: "row", alignItems: "center", paddingVertical: 24 }}>
<Text variant="heading-xl/semibold">
{plugin.name}
</Text>
<View style={{ marginLeft: "auto" }}>
{plugin.getPluginSettingsComponent() && <Button
size="md"
text="Configure"
variant="secondary"
icon={findAssetId("WrenchIcon")}
onPress={() => {
hideSheet("PluginInfoActionSheet");
navigation.push("VendettaCustomPage", {
title: plugin.name,
render: plugin.getPluginSettingsComponent(),
});
}}
/>}
</View>
</View>
</ScrollView>
</ActionSheet>;
}

View file

@ -10,14 +10,9 @@ import { hideSheet } from "@ui/sheets";
import { showToast } from "@ui/toasts";
import { ScrollView, View } from "react-native";
import { PluginManifest } from "..";
import { PluginInfoActionSheetProps } from "./common";
interface InfoProps {
plugin: PluginManifest;
navigation: any;
}
export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps) {
export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfoActionSheetProps) {
plugin.usePluginState();
const vdPlugin = VdPluginManager.plugins[plugin.id];

View file

@ -0,0 +1,6 @@
import { PluginManifest } from "..";
export interface PluginInfoActionSheetProps {
plugin: PluginManifest;
navigation: any;
}

View file

@ -94,7 +94,7 @@ export function createProxy(target: any = {}): { proxy: any; emitter: Emitter; }
};
}
export function useProxy<T>(storage: T & { [key in typeof storageInitErrorSymbol | typeof emitterSymbol]: any; }) {
export function useProxy<T>(storage: T & { [key: string | symbol]: any; }) {
if (storage[storageInitErrorSymbol]) throw new Error(
"An error occured while initializing the storage",
{ cause: storage[storageInitErrorSymbol] }

View file

@ -56,7 +56,7 @@ export function getId<T extends t.BunnyPluginManifest>(manifest: T): string {
return id;
}
export function getPluginSettingsComponent(id: string): (() => React.Component<any>) | null {
export function getPluginSettingsComponent(id: string): React.ComponentType<any> | null {
const instance = pluginInstances.get(id);
if (!instance) return null;

View file

@ -37,7 +37,7 @@ export interface BunnyPluginManifestInternal extends BunnyPluginManifest {
export interface PluginInstance {
start?(): void;
stop?(): void;
SettingsComponent?(): React.Component<any>;
SettingsComponent?(): JSX.Element;
}
export interface PluginInstanceInternal extends PluginInstance {