refactor: rename assets api

This commit is contained in:
amsyarasyiq 2024-07-09 15:53:34 +08:00
parent 64473cdadf
commit aaecce6cd4
20 changed files with 111 additions and 97 deletions

View file

@ -1,5 +1,5 @@
import { Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after } from "@lib/api/patcher";
import { useProxy } from "@lib/api/storage";
@ -77,7 +77,7 @@ function useInstaller(thread: any, firstMessage = null, actionSheet = false): [t
try {
await postMap[postType].installOrRemove(url);
} catch (e: any) {
showToast(e.message, requireAssetIndex("Small"));
showToast(e.message, findAssetId("Small"));
} finally {
setIsInstalling(false);
}
@ -119,7 +119,7 @@ const installButtonPatch = () => after("MostCommonForumPostReaction", forumReact
variant={installed ? "secondary" : "primary"}
text={installed ? Strings.UNINSTALL : Strings.INSTALL}
onPress={installOrRemove}
icon={requireAssetIndex(installed ? "ic_message_delete" : "DownloadIcon")}
icon={findAssetId(installed ? "ic_message_delete" : "DownloadIcon")}
style={{ marginLeft: 8 }}
/>
</ErrorBoundary>

View file

@ -1,5 +1,5 @@
import { formatString, Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after, instead } from "@lib/api/patcher";
import { installPlugin } from "@lib/managers/plugins";
@ -30,10 +30,10 @@ function typeFromUrl(url: string) {
function installWithToast(type: "plugin" | "theme", url: string) {
(type === "plugin" ? installPlugin : installTheme)(url)
.then(() => {
showToast(Strings.SUCCESSFULLY_INSTALLED, requireAssetIndex("Check"));
showToast(Strings.SUCCESSFULLY_INSTALLED, findAssetId("Check"));
})
.catch((e: Error) => {
showToast(e.message, requireAssetIndex("Small"));
showToast(e.message, findAssetId("Small"));
});
}

View file

@ -163,9 +163,9 @@ export const initVendettaObject = (): any => {
assets: {
all: assets.assetsMap,
find: (filter: (a: any) => void) => assets.findAsset(filter),
getAssetByName: (name: string) => assets.requireAssetByName(name),
getAssetByID: (id: number) => assets.requireAssetByIndex(id),
getAssetIDByName: (name: string) => assets.requireAssetIndex(name)
getAssetByName: (name: string) => assets.findAsset(name),
getAssetByID: (id: number) => assets.findAsset(id),
getAssetIDByName: (name: string) => assets.findAssetId(name)
},
semanticColors: color.semanticColors,
rawColors: color.rawColors

View file

@ -1,4 +1,4 @@
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { lazyDestructure } from "@lib/utils/lazy";
import { Card, FormRadio, FormSwitch, IconButton, LegacyFormRow, Stack, Text } from "@metro/common/components";
import { findByProps } from "@metro/utils";
@ -108,17 +108,17 @@ export default function AddonCard(props: CardProps) {
key: "CardOverflow",
header: {
title: props.overflowTitle,
icon: props.headerIcon && <LegacyFormRow.Icon style={{ marginRight: 8 }} source={requireAssetIndex(props.headerIcon)} />,
icon: props.headerIcon && <LegacyFormRow.Icon style={{ marginRight: 8 }} source={findAssetId(props.headerIcon)} />,
onClose: () => hideActionSheet(),
},
options: props.overflowActions?.map(i => ({
...i,
icon: requireAssetIndex(i.icon)
icon: findAssetId(i.icon)
})),
})}
size="sm"
variant="secondary"
icon={requireAssetIndex("CircleInformationIcon-primary")}
icon={findAssetId("CircleInformationIcon-primary")}
/>}
{props.actions?.map(({ icon, onPress, disabled }) => (
<IconButton
@ -126,7 +126,7 @@ export default function AddonCard(props: CardProps) {
disabled={disabled}
size="sm"
variant="secondary"
icon={requireAssetIndex(icon)}
icon={findAssetId(icon)}
/>
))}
</View>

View file

@ -1,6 +1,6 @@
import { Strings } from "@core/i18n";
import { CardWrapper } from "@core/ui/components/AddonCard";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { settings } from "@lib/settings";
import { HTTP_REGEX_MULTI } from "@lib/utils/constants";
@ -76,7 +76,7 @@ export default function AddonPage<T extends object>({ card: CardComponent, ...pr
)}
/>
<FloatingActionButton
icon={requireAssetIndex("PlusLargeIcon")}
icon={findAssetId("PlusLargeIcon")}
onPress={props.onFABPress ?? (() => {
// from ./InstallButton.tsx
clipboard.getString().then(content =>

View file

@ -1,5 +1,5 @@
import { Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { HTTP_REGEX_MULTI } from "@lib/utils/constants";
import { clipboard } from "@metro/common";
import { showInputAlert } from "@ui/alerts";
@ -35,7 +35,7 @@ export default function InstallButton({ alertTitle, installFunction: fetchFuncti
})
)
}>
<Image style={styles.icon} source={requireAssetIndex("ic_add_24px")} />
<Image style={styles.icon} source={findAssetId("ic_add_24px")} />
</TouchableOpacity>
);
}

View file

@ -1,6 +1,6 @@
import PyoncordIcon from "@assets/icons/pyoncord.png";
import { Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { isFontSupported, isThemeSupported } from "@lib/api/native/loader";
import { useProxy } from "@lib/api/storage";
import { settings } from "@lib/settings";
@ -25,27 +25,27 @@ export default function initSettings() {
{
key: "BUNNY_PLUGINS",
title: () => Strings.PLUGINS,
icon: requireAssetIndex("ActivitiesIcon"),
icon: findAssetId("ActivitiesIcon"),
render: () => import("@core/ui/settings/pages/Plugins")
},
{
key: "BUNNY_THEMES",
title: () => Strings.THEMES,
icon: requireAssetIndex("PaintPaletteIcon"),
icon: findAssetId("PaintPaletteIcon"),
render: () => import("@core/ui/settings/pages/Themes"),
usePredicate: () => isThemeSupported()
},
{
key: "BUNNY_FONTS",
title: () => Strings.FONTS,
icon: requireAssetIndex("ic_add_text"),
icon: findAssetId("ic_add_text"),
render: () => import("@core/ui/settings/pages/Fonts"),
usePredicate: () => isFontSupported()
},
{
key: "BUNNY_DEVELOPER",
title: () => Strings.DEVELOPER,
icon: requireAssetIndex("WrenchIcon"),
icon: findAssetId("WrenchIcon"),
render: () => import("@core/ui/settings/pages/Developer"),
usePredicate: () => useProxy(settings).developerSettings ?? false
}

View file

@ -1,7 +1,7 @@
import { Strings } from "@core/i18n";
import { CheckState, useFileExists } from "@core/ui/settings/hooks/useFS";
import AssetBrowser from "@core/ui/settings/pages/Developer/AssetBrowser";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded, isVendettaLoader } from "@lib/api/native/loader";
import { useProxy } from "@lib/api/storage";
import { connectToDebugger } from "@lib/debug";
@ -52,13 +52,13 @@ export default function Developer() {
<TableRowGroup title={Strings.DEBUG}>
<TableRow
label={Strings.CONNECT_TO_DEBUG_WEBSOCKET}
icon={<TableRow.Icon source={requireAssetIndex("copy")} />}
icon={<TableRow.Icon source={findAssetId("copy")} />}
onPress={() => connectToDebugger(settings.debuggerUrl)}
/>
{isReactDevToolsPreloaded() && <>
<TableRow
label={Strings.CONNECT_TO_REACT_DEVTOOLS}
icon={<TableRow.Icon source={requireAssetIndex("ic_badge_staff")} />}
icon={<TableRow.Icon source={findAssetId("ic_badge_staff")} />}
onPress={() => window[getReactDevToolsProp() || "__vendetta_rdc"]?.connectToDevTools({
host: settings.debuggerUrl.split(":")?.[0],
resolveRNStyle: StyleSheet.flatten,
@ -71,7 +71,7 @@ export default function Developer() {
<TableSwitchRow
label={Strings.LOAD_FROM_CUSTOM_URL}
subLabel={Strings.LOAD_FROM_CUSTOM_URL_DEC}
icon={<TableRow.Icon source={requireAssetIndex("copy")} />}
icon={<TableRow.Icon source={findAssetId("copy")} />}
value={loaderConfig.customLoadUrl.enabled}
onValueChange={(v: boolean) => {
loaderConfig.customLoadUrl.enabled = v;
@ -87,7 +87,7 @@ export default function Developer() {
{isReactDevToolsPreloaded() && isVendettaLoader() && <TableSwitchRow
label={Strings.LOAD_REACT_DEVTOOLS}
subLabel={`${Strings.VERSION}: ${getReactDevToolsVersion()}`}
icon={<TableRow.Icon source={requireAssetIndex("ic_badge_staff")} />}
icon={<TableRow.Icon source={findAssetId("ic_badge_staff")} />}
value={loaderConfig.loadReactDevTools}
onValueChange={(v: boolean) => {
loaderConfig.loadReactDevTools = v;
@ -99,7 +99,7 @@ export default function Developer() {
<TableRow
arrow
label={Strings.ASSET_BROWSER}
icon={<TableRow.Icon source={requireAssetIndex("ic_image")} />}
icon={<TableRow.Icon source={findAssetId("ic_image")} />}
trailing={TableRow.Arrow}
onPress={() => navigation.push("VendettaCustomPage", {
title: Strings.ASSET_BROWSER,
@ -109,12 +109,12 @@ export default function Developer() {
<TableRow
arrow
label={Strings.ERROR_BOUNDARY_TOOLS_LABEL}
icon={<TableRow.Icon source={requireAssetIndex("ic_warning_24px")} />}
icon={<TableRow.Icon source={findAssetId("ic_warning_24px")} />}
onPress={() => showSimpleActionSheet({
key: "ErrorBoundaryTools",
header: {
title: "Which ErrorBoundary do you want to trip?",
icon: <TableRow.Icon style={{ marginRight: 8 }} source={requireAssetIndex("ic_warning_24px")} />,
icon: <TableRow.Icon style={{ marginRight: 8 }} source={findAssetId("ic_warning_24px")} />,
onClose: () => hideActionSheet(),
},
options: [
@ -128,7 +128,7 @@ export default function Developer() {
<TableRow
label={Strings.INSTALL_REACT_DEVTOOLS}
subLabel={Strings.RESTART_REQUIRED_TO_TAKE_EFFECT}
icon={<TableRow.Icon source={requireAssetIndex("DownloadIcon")} />}
icon={<TableRow.Icon source={findAssetId("DownloadIcon")} />}
trailing={
<Button
size="sm"
@ -143,7 +143,7 @@ export default function Developer() {
fs.removeFile("preloads/reactDevtools.js");
}
}}
icon={requireAssetIndex(rdtFileExists === CheckState.TRUE ? "ic_message_delete" : "DownloadIcon")}
icon={findAssetId(rdtFileExists === CheckState.TRUE ? "ic_message_delete" : "DownloadIcon")}
style={{ marginLeft: 8 }}
/>
}
@ -151,7 +151,7 @@ export default function Developer() {
<TableSwitchRow
label={Strings.ENABLE_EVAL_COMMAND}
subLabel={Strings.ENABLE_EVAL_COMMAND_DESC}
icon={<TableRow.Icon source={requireAssetIndex("PencilIcon")} />}
icon={<TableRow.Icon source={findAssetId("PencilIcon")} />}
value={settings.enableEvalCommand}
onValueChange={(v: boolean) => {
settings.enableEvalCommand = v;

View file

@ -1,6 +1,6 @@
import { Strings } from "@core/i18n";
import { CardWrapper } from "@core/ui/components/AddonCard";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { BundleUpdaterManager } from "@lib/api/native/modules";
import { useProxy } from "@lib/api/storage";
import { FontDefinition, fonts, selectFont } from "@lib/managers/fonts";
@ -89,7 +89,7 @@ export default function FontCard({ item: font }: CardWrapper<FontDefinition>) {
size="sm"
variant="secondary"
disabled={selected}
icon={requireAssetIndex("PencilIcon")}
icon={findAssetId("PencilIcon")}
/>
<Button
size="sm"

View file

@ -1,5 +1,5 @@
import { formatString, Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { createProxy, useProxy } from "@lib/api/storage";
import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/managers/fonts";
import { getCurrentTheme } from "@lib/managers/themes";
@ -196,7 +196,7 @@ function NewEntryRow({ fontEntry }: { fontEntry: Record<string, string>; }) {
size="md"
label={nameSet ? nameRef.current : void 0}
placeholder={nameSet ? "https://path.to/the/file.ttf" : "PostScript name (e.g. ggsans-Bold)"}
leadingIcon={() => nameSet ? null : <TableRow.Icon source={requireAssetIndex("PlusSmallIcon")} />}
leadingIcon={() => nameSet ? null : <TableRow.Icon source={findAssetId("PlusSmallIcon")} />}
leadingText={nameSet ? nameRef.current : ""}
onChange={(text: string) => (nameSet ? urlRef : nameRef).current = text}
errorMessage={error}
@ -210,7 +210,7 @@ function NewEntryRow({ fontEntry }: { fontEntry: Record<string, string>; }) {
nameRef.current = "";
setNameSet(false);
}}
icon={requireAssetIndex("TrashIcon")}
icon={findAssetId("TrashIcon")}
/>}
<IconButton
size="md"
@ -234,7 +234,7 @@ function NewEntryRow({ fontEntry }: { fontEntry: Record<string, string>; }) {
}
}
}}
icon={requireAssetIndex(nameSet ? "PlusSmallIcon" : "ArrowLargeRightIcon")}
icon={findAssetId(nameSet ? "PlusSmallIcon" : "ArrowLargeRightIcon")}
/>
</View>;
}
@ -262,20 +262,20 @@ export default function FontEditor(props: {
{getCurrentTheme()?.data?.fonts && <TableRow
label={Strings.LABEL_EXTRACT_FONTS_FROM_THEME}
subLabel={Strings.DESC_EXTRACT_FONTS_FROM_THEME}
icon={<TableRow.Icon source={requireAssetIndex("HammerIcon")} />}
icon={<TableRow.Icon source={findAssetId("HammerIcon")} />}
onPress={() => promptActionSheet(RevengeFontsExtractor, fontEntries, { setName })}
/>}
<TableRow
label={"Import font entries from a link"}
subLabel={"Directly import from a link with a pre-configured JSON file"}
icon={<TableRow.Icon source={requireAssetIndex("LinkIcon")} />}
icon={<TableRow.Icon source={findAssetId("LinkIcon")} />}
onPress={() => promptActionSheet(JsonFontImporter, fontEntries, { setName, setSource })}
/>
</TableRowGroup>
: <TableRowGroup title="Actions">
<TableRow
label={"Refetch fonts from source"}
icon={<TableRow.Icon source={requireAssetIndex("RetryIcon")} />}
icon={<TableRow.Icon source={findAssetId("RetryIcon")} />}
onPress={async () => {
const ftCopy = { ...fonts[props.name!] };
await removeFont(props.name!);
@ -285,7 +285,7 @@ export default function FontEditor(props: {
/>
<TableRow
label={"Delete font pack"}
icon={<TableRow.Icon source={requireAssetIndex("TrashIcon")} />}
icon={<TableRow.Icon source={findAssetId("TrashIcon")} />}
onPress={() => removeFont(props.name!).then(() => navigation.goBack())}
/>
</TableRowGroup>}
@ -305,7 +305,7 @@ export default function FontEditor(props: {
<IconButton
size="sm"
variant="secondary"
icon={requireAssetIndex("PencilIcon")}
icon={findAssetId("PencilIcon")}
onPress={() => promptActionSheet(EntryEditorActionSheet, fontEntries, {
name,
fontEntries,
@ -314,7 +314,7 @@ export default function FontEditor(props: {
<IconButton
size="sm"
variant="secondary"
icon={requireAssetIndex("TrashIcon")}
icon={findAssetId("TrashIcon")}
onPress={() => delete fontEntries[name]}
/>
</Stack>}
@ -353,7 +353,7 @@ export default function FontEditor(props: {
navigation.goBack();
}
}}
icon={requireAssetIndex(props.name ? "toast_image_saved" : "DownloadIcon")}
icon={findAssetId(props.name ? "toast_image_saved" : "DownloadIcon")}
style={{ marginLeft: 8 }}
/>
</View>

View file

@ -1,4 +1,4 @@
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { clipboard } from "@metro/common";
import { LegacyFormText, TableRow } from "@metro/common/components";
import { showToast } from "@ui/toasts";
@ -13,7 +13,7 @@ export default function Version({ label, version, icon }: VersionProps) {
return (
<TableRow
label={label}
icon={<TableRow.Icon source={requireAssetIndex(icon)} />}
icon={<TableRow.Icon source={findAssetId(icon)} />}
trailing={<LegacyFormText>{version}</LegacyFormText>}
onPress={() => {
clipboard.setString(`${label} - ${version}`);

View file

@ -1,7 +1,7 @@
import { Strings } from "@core/i18n";
import { PyoncordIcon } from "@core/ui/settings";
import About from "@core/ui/settings/pages/General/About";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { getDebugInfo, toggleSafeMode } from "@lib/debug";
import { settings } from "@lib/settings";
@ -27,13 +27,13 @@ export default function General() {
/>
<TableRow
label={"Discord"}
icon={<TableRow.Icon source={requireAssetIndex("Discord")} />}
icon={<TableRow.Icon source={findAssetId("Discord")} />}
trailing={<TableRow.TrailingText text={`${debugInfo.discord.version} (${debugInfo.discord.build})`} />}
/>
<TableRow
arrow
label={Strings.ABOUT}
icon={<TableRow.Icon source={requireAssetIndex("CircleInformationIcon-primary")} />}
icon={<TableRow.Icon source={findAssetId("CircleInformationIcon-primary")} />}
trailing={TableRow.Arrow}
onPress={() => navigation.push("VendettaCustomPage", {
title: Strings.ABOUT,
@ -44,13 +44,13 @@ export default function General() {
<TableRowGroup title={Strings.LINKS}>
<TableRow
label={Strings.DISCORD_SERVER}
icon={<TableRow.Icon source={requireAssetIndex("Discord")} />}
icon={<TableRow.Icon source={findAssetId("Discord")} />}
trailing={TableRow.Arrow}
onPress={() => url.openDeeplink(DISCORD_SERVER)}
/>
<TableRow
label={Strings.GITHUB}
icon={<TableRow.Icon source={requireAssetIndex("img_account_sync_github_white")} />}
icon={<TableRow.Icon source={findAssetId("img_account_sync_github_white")} />}
trailing={TableRow.Arrow}
onPress={() => url.openURL(GITHUB)}
/>
@ -58,18 +58,18 @@ export default function General() {
<TableRowGroup title={Strings.ACTIONS}>
<TableRow
label={Strings.RELOAD_DISCORD}
icon={<TableRow.Icon source={requireAssetIndex("ic_message_retry")} />}
icon={<TableRow.Icon source={findAssetId("ic_message_retry")} />}
onPress={() => NativeModules.BundleUpdaterManager.reload()}
/>
<TableRow
label={settings.safeMode?.enabled ? Strings.RELOAD_IN_NORMAL_MODE : Strings.RELOAD_IN_SAFE_MODE}
subLabel={settings.safeMode?.enabled ? Strings.RELOAD_IN_NORMAL_MODE_DESC : Strings.RELOAD_IN_SAFE_MODE_DESC}
icon={<TableRow.Icon source={requireAssetIndex("ic_privacy_24px")} />}
icon={<TableRow.Icon source={findAssetId("ic_privacy_24px")} />}
onPress={toggleSafeMode}
/>
<TableSwitchRow
label={Strings.DEVELOPER_SETTINGS}
icon={<TableRow.Icon source={requireAssetIndex("ic_progress_wrench_24px")} />}
icon={<TableRow.Icon source={findAssetId("ic_progress_wrench_24px")} />}
value={settings.developerSettings}
onValueChange={(v: boolean) => {
settings.developerSettings = v;
@ -80,7 +80,7 @@ export default function General() {
<TableSwitchRow
label={Strings.SETTINGS_ACTIVATE_DISCORD_EXPERIMENTS}
subLabel={Strings.SETTINGS_ACTIVATE_DISCORD_EXPERIMENTS_DESC}
icon={<TableRow.Icon source={requireAssetIndex("ic_progress_wrench_24px")} />}
icon={<TableRow.Icon source={findAssetId("ic_progress_wrench_24px")} />}
value={settings.enableDiscordDeveloperSettings}
onValueChange={(v: boolean) => {
settings.enableDiscordDeveloperSettings = v;

View file

@ -1,5 +1,5 @@
import { CardWrapper } from "@core/ui/components/AddonCard";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { BunnyPlugin, getSettingsComponent, startPlugin, stopPlugin } from "@lib/managers/plugins";
import { showSheet } from "@lib/ui/sheets";
@ -37,7 +37,7 @@ function Title() {
const plugin = usePlugin();
const iconName = plugin.manifest.vendetta?.icon;
const icon = iconName && requireAssetIndex(iconName);
const icon = iconName && findAssetId(iconName);
const textElement = (
<Text
@ -76,7 +76,7 @@ function Status() {
<View style={styles.smallIcon}>
<Image
tintColor={INTERACTIVE_NORMAL}
source={requireAssetIndex("WarningIcon")}
source={findAssetId("WarningIcon")}
/>
</View>
<Text variant="text-sm/semibold">
@ -93,7 +93,7 @@ const Actions = memo(() => {
<IconButton
size="sm"
variant="secondary"
icon={requireAssetIndex("WrenchIcon")}
icon={findAssetId("WrenchIcon")}
disabled={!getSettingsComponent(plugin.id)}
onPress={() => navigation.push("VendettaCustomPage", {
title: plugin.manifest.name,
@ -103,7 +103,7 @@ const Actions = memo(() => {
<IconButton
size="sm"
variant="secondary"
icon={requireAssetIndex("CircleInformationIcon-primary")}
icon={findAssetId("CircleInformationIcon-primary")}
onPress={() => void showSheet(
"PluginInfoActionSheet",
import("./sheets/PluginInfoActionSheet"),

View file

@ -1,5 +1,5 @@
import { formatString, Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { purgeStorage, useProxy } from "@lib/api/storage";
import { BunnyPlugin, fetchAndStorePlugin, getSettingsComponent, removePlugin, startPlugin, stopPlugin } from "@lib/managers/plugins";
import { showConfirmationAlert } from "@lib/ui/alerts";
@ -31,7 +31,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
size="md"
text="Configure"
variant="secondary"
icon={requireAssetIndex("WrenchIcon")}
icon={findAssetId("WrenchIcon")}
onPress={() => {
hideSheet("PluginInfoActionSheet");
navigation.push("VendettaCustomPage", {
@ -45,15 +45,15 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
<ActionSheetRow.Group>
<ActionSheetRow
label={Strings.REFETCH}
icon={<TableRow.Icon source={requireAssetIndex("RetryIcon")} />}
icon={<TableRow.Icon source={findAssetId("RetryIcon")} />}
onPress={async () => {
if (plugin.enabled) stopPlugin(plugin.id, false);
try {
await fetchAndStorePlugin(plugin.id);
showToast(Strings.PLUGIN_REFETCH_SUCCESSFUL, requireAssetIndex("toast_image_saved"));
showToast(Strings.PLUGIN_REFETCH_SUCCESSFUL, findAssetId("toast_image_saved"));
} catch {
showToast(Strings.PLUGIN_REFETCH_FAILED, requireAssetIndex("Small"));
showToast(Strings.PLUGIN_REFETCH_FAILED, findAssetId("Small"));
}
if (plugin.enabled) await startPlugin(plugin.id);
@ -62,7 +62,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
/>
<ActionSheetRow
label={Strings.COPY_URL}
icon={<TableRow.Icon source={requireAssetIndex("copy")} />}
icon={<TableRow.Icon source={findAssetId("copy")} />}
onPress={() => {
clipboard.setString(plugin.id);
showToast.showCopyToClipboard();
@ -70,18 +70,18 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
/>
<ActionSheetRow
label={plugin.update ? Strings.DISABLE_UPDATES : Strings.ENABLE_UPDATES}
icon={<TableRow.Icon source={requireAssetIndex("ic_download_24px")} />}
icon={<TableRow.Icon source={findAssetId("ic_download_24px")} />}
onPress={() => {
plugin.update = !plugin.update;
showToast(formatString("TOASTS_PLUGIN_UPDATE", {
update: plugin.update,
name: plugin.manifest.name
}), requireAssetIndex("toast_image_saved"));
}), findAssetId("toast_image_saved"));
}}
/>
<ActionSheetRow
label={Strings.CLEAR_DATA}
icon={<TableRow.Icon source={requireAssetIndex("ic_duplicate")} />}
icon={<TableRow.Icon source={findAssetId("ic_duplicate")} />}
onPress={() => showConfirmationAlert({
title: Strings.HOLD_UP,
content: formatString("ARE_YOU_SURE_TO_CLEAR_DATA", { name: plugin.manifest.name }),
@ -93,9 +93,9 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
try {
await fetchAndStorePlugin(plugin.id);
showToast(Strings.PLUGIN_REFETCH_SUCCESSFUL, requireAssetIndex("toast_image_saved"));
showToast(Strings.PLUGIN_REFETCH_SUCCESSFUL, findAssetId("toast_image_saved"));
} catch {
showToast(Strings.PLUGIN_REFETCH_FAILED, requireAssetIndex("Small"));
showToast(Strings.PLUGIN_REFETCH_FAILED, findAssetId("Small"));
}
let message: any[];
@ -108,7 +108,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
showToast(
formatString(message[0], { name: plugin.manifest.name }),
requireAssetIndex(message[1])
findAssetId(message[1])
);
if (plugin.enabled) await startPlugin(plugin.id);
@ -118,7 +118,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
/>
<ActionSheetRow
label={Strings.DELETE}
icon={<TableRow.Icon source={requireAssetIndex("ic_message_delete")} />}
icon={<TableRow.Icon source={findAssetId("ic_message_delete")} />}
onPress={() => showConfirmationAlert({
title: Strings.HOLD_UP,
content: formatString("ARE_YOU_SURE_TO_DELETE_PLUGIN", { name: plugin.manifest.name }),
@ -129,7 +129,7 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
try {
removePlugin(plugin.id);
} catch (e) {
showToast(String(e), requireAssetIndex("Small"));
showToast(String(e), findAssetId("Small"));
}
hideSheet("PluginInfoActionSheet");
}

View file

@ -1,6 +1,6 @@
import { formatString, Strings } from "@core/i18n";
import AddonCard, { CardWrapper } from "@core/ui/components/AddonCard";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { useProxy } from "@lib/api/storage";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/managers/themes";
import { settings } from "@lib/settings";
@ -46,9 +46,9 @@ export default function ThemeCard({ item: theme, index }: CardWrapper<Theme>) {
label: Strings.REFETCH,
onPress: () => {
fetchTheme(theme.id, theme.selected).then(() => {
showToast(Strings.THEME_REFETCH_SUCCESSFUL, requireAssetIndex("toast_image_saved"));
showToast(Strings.THEME_REFETCH_SUCCESSFUL, findAssetId("toast_image_saved"));
}).catch(() => {
showToast(Strings.THEME_REFETCH_FAILED, requireAssetIndex("Small"));
showToast(Strings.THEME_REFETCH_FAILED, findAssetId("Small"));
});
},
},
@ -75,7 +75,7 @@ export default function ThemeCard({ item: theme, index }: CardWrapper<Theme>) {
setRemoved(true);
if (wasSelected) selectAndApply(false, theme);
}).catch((e: Error) => {
showToast(e.message, requireAssetIndex("Small"));
showToast(e.message, findAssetId("Small"));
});
}
})

View file

@ -26,8 +26,6 @@ export const assetsMap: Record<string, Asset> = new Proxy<any>({}, {
assetDefinition.moduleId ??= id;
// ??= is intended, we only assign to the first asset registered
// Though, VD seems to assign the last registered, but doing that breaks HideGiftButton so idk
// https://github.com/vendetta-mod/Vendetta/blob/rewrite/src/ui/assets.ts
cache[p] ??= assetDefinition;
}
@ -73,7 +71,23 @@ export function patchAssets(module: AssetModule) {
return unpatch;
}
export const findAsset = (filter: (a: any) => void): Asset | null | undefined => Object.values(assetsMap).find(filter);
export const requireAssetByName = (name: string): Asset => assetsMap[name];
export const requireAssetByIndex = (id: number): Asset => assetsModule.getAssetByID(id);
export const requireAssetIndex = (name: string) => assetsMap[name]?.index;
/**
* Returns the first asset registry by its registry id (number), name (string) or given filter (function)
*/
export function findAsset(id: number): Asset | undefined;
export function findAsset(name: string): Asset | undefined;
export function findAsset(filter: (a: Asset) => boolean): Asset | undefined;
export function findAsset(param: number | string | ((a: any) => void)) {
if (typeof param === "number") return assetsModule.getAssetByID(param);
if (typeof param === "string") return assetsMap[param];
return Object.values(assetsMap).find(param);
}
/**
* Returns the first asset ID in the registry with the given name
*/
export function findAssetId(name: string) {
return assetsMap[name]?.index;
}

View file

@ -1,4 +1,4 @@
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { getLoaderName, getLoaderVersion, isThemeSupported } from "@lib/api/native/loader";
import { BundleUpdaterManager, ClientInfoManager, DeviceManager } from "@lib/api/native/modules";
import { after } from "@lib/api/patcher";
@ -48,13 +48,13 @@ export function connectToDebugger(url: string) {
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) socket.close();
if (!url) {
showToast("Invalid debugger URL!", requireAssetIndex("Small"));
showToast("Invalid debugger URL!", findAssetId("Small"));
return;
}
socket = new WebSocket(`ws://${url}`);
socket.addEventListener("open", () => showToast("Connected to debugger.", requireAssetIndex("Check")));
socket.addEventListener("open", () => showToast("Connected to debugger.", findAssetId("Check")));
socket.addEventListener("message", (message: any) => {
try {
(0, eval)(message.data);
@ -65,7 +65,7 @@ export function connectToDebugger(url: string) {
socket.addEventListener("error", (err: any) => {
console.log(`Debugger error: ${err.message}`);
showToast("An error occurred with the debugger connection!", requireAssetIndex("Small"));
showToast("An error occurred with the debugger connection!", findAssetId("Small"));
});
}

View file

@ -1,5 +1,5 @@
import { Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { TextInput } from "@metro/common/components";
import ErrorBoundary from "@ui/components/ErrorBoundary";
import { Image, View } from "react-native";
@ -11,7 +11,7 @@ export interface SearchProps {
}
function SearchIcon() {
return <Image style={{ width: 16, height: 16 }} source={requireAssetIndex("search")} />;
return <Image style={{ width: 16, height: 16 }} source={findAssetId("search")} />;
}
export default ({ onChangeText, placeholder, style }: SearchProps) => {

View file

@ -1,4 +1,4 @@
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { LegacyFormRow, TableRow } from "@metro/common/components";
import { LayoutAnimation, View } from "react-native";
@ -17,7 +17,7 @@ export default function Summary({ label, icon, noPadding = false, noAnimation =
<>
<TableRow
label={label}
icon={icon && <TableRow.Icon source={requireAssetIndex(icon)} />}
icon={icon && <TableRow.Icon source={findAssetId(icon)} />}
trailing={<LegacyFormRow.Arrow style={{ transform: [{ rotate: `${hidden ? 180 : 90}deg` }] }} />}
onPress={() => {
setHidden(!hidden);

View file

@ -1,5 +1,5 @@
import { Strings } from "@core/i18n";
import { requireAssetIndex } from "@lib/api/assets";
import { findAssetId } from "@lib/api/assets";
import { lazyDestructure } from "@lib/utils/lazy";
import { toasts } from "@metro/common";
import { findByProps } from "@metro/utils";
@ -19,6 +19,6 @@ export const showToast = (content: string, asset?: number) => toasts.open({
showToast.showCopyToClipboard = (message = Strings.COPIED_TO_CLIPBOARD) => {
// On Android, only show toast for 12 and lower
if (Platform.OS !== "android" || Platform.Version <= 32) {
showToast(message, requireAssetIndex("toast_copy_link"));
showToast(message, findAssetId("toast_copy_link"));
}
};