diff --git a/src/core/plugins/quickInstall/forumPost.tsx b/src/core/plugins/quickInstall/forumPost.tsx
index 27789c5..b9606c2 100644
--- a/src/core/plugins/quickInstall/forumPost.tsx
+++ b/src/core/plugins/quickInstall/forumPost.tsx
@@ -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 }}
/>
diff --git a/src/core/plugins/quickInstall/url.tsx b/src/core/plugins/quickInstall/url.tsx
index 1b33938..8344feb 100644
--- a/src/core/plugins/quickInstall/url.tsx
+++ b/src/core/plugins/quickInstall/url.tsx
@@ -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"));
});
}
diff --git a/src/core/polyfills/vendettaObject.tsx b/src/core/polyfills/vendettaObject.tsx
index 30d5cc7..30c9c9b 100644
--- a/src/core/polyfills/vendettaObject.tsx
+++ b/src/core/polyfills/vendettaObject.tsx
@@ -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
diff --git a/src/core/ui/components/AddonCard.tsx b/src/core/ui/components/AddonCard.tsx
index 47839d4..927334a 100644
--- a/src/core/ui/components/AddonCard.tsx
+++ b/src/core/ui/components/AddonCard.tsx
@@ -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 && ,
+ icon: 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 }) => (
))}
diff --git a/src/core/ui/components/AddonPage.tsx b/src/core/ui/components/AddonPage.tsx
index a132fa0..b4201d3 100644
--- a/src/core/ui/components/AddonPage.tsx
+++ b/src/core/ui/components/AddonPage.tsx
@@ -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({ card: CardComponent, ...pr
)}
/>
{
// from ./InstallButton.tsx
clipboard.getString().then(content =>
diff --git a/src/core/ui/components/InstallButton.tsx b/src/core/ui/components/InstallButton.tsx
index 525bf17..a810bd1 100644
--- a/src/core/ui/components/InstallButton.tsx
+++ b/src/core/ui/components/InstallButton.tsx
@@ -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
})
)
}>
-
+
);
}
diff --git a/src/core/ui/settings/index.ts b/src/core/ui/settings/index.ts
index 7006434..7433740 100644
--- a/src/core/ui/settings/index.ts
+++ b/src/core/ui/settings/index.ts
@@ -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
}
diff --git a/src/core/ui/settings/pages/Developer/index.tsx b/src/core/ui/settings/pages/Developer/index.tsx
index 85a52b0..c340bf2 100644
--- a/src/core/ui/settings/pages/Developer/index.tsx
+++ b/src/core/ui/settings/pages/Developer/index.tsx
@@ -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() {
}
+ icon={}
onPress={() => connectToDebugger(settings.debuggerUrl)}
/>
{isReactDevToolsPreloaded() && <>
}
+ icon={}
onPress={() => window[getReactDevToolsProp() || "__vendetta_rdc"]?.connectToDevTools({
host: settings.debuggerUrl.split(":")?.[0],
resolveRNStyle: StyleSheet.flatten,
@@ -71,7 +71,7 @@ export default function Developer() {
}
+ icon={}
value={loaderConfig.customLoadUrl.enabled}
onValueChange={(v: boolean) => {
loaderConfig.customLoadUrl.enabled = v;
@@ -87,7 +87,7 @@ export default function Developer() {
{isReactDevToolsPreloaded() && isVendettaLoader() && }
+ icon={}
value={loaderConfig.loadReactDevTools}
onValueChange={(v: boolean) => {
loaderConfig.loadReactDevTools = v;
@@ -99,7 +99,7 @@ export default function Developer() {
}
+ icon={}
trailing={TableRow.Arrow}
onPress={() => navigation.push("VendettaCustomPage", {
title: Strings.ASSET_BROWSER,
@@ -109,12 +109,12 @@ export default function Developer() {
}
+ icon={}
onPress={() => showSimpleActionSheet({
key: "ErrorBoundaryTools",
header: {
title: "Which ErrorBoundary do you want to trip?",
- icon: ,
+ icon: ,
onClose: () => hideActionSheet(),
},
options: [
@@ -128,7 +128,7 @@ export default function Developer() {
}
+ icon={}
trailing={
}
@@ -151,7 +151,7 @@ export default function Developer() {
}
+ icon={}
value={settings.enableEvalCommand}
onValueChange={(v: boolean) => {
settings.enableEvalCommand = v;
diff --git a/src/core/ui/settings/pages/Fonts/FontCard.tsx b/src/core/ui/settings/pages/Fonts/FontCard.tsx
index bc5a4d9..cf3d7b6 100644
--- a/src/core/ui/settings/pages/Fonts/FontCard.tsx
+++ b/src/core/ui/settings/pages/Fonts/FontCard.tsx
@@ -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) {
size="sm"
variant="secondary"
disabled={selected}
- icon={requireAssetIndex("PencilIcon")}
+ icon={findAssetId("PencilIcon")}
/>
:
}
+ icon={}
onPress={async () => {
const ftCopy = { ...fonts[props.name!] };
await removeFont(props.name!);
@@ -285,7 +285,7 @@ export default function FontEditor(props: {
/>
}
+ icon={}
onPress={() => removeFont(props.name!).then(() => navigation.goBack())}
/>
}
@@ -305,7 +305,7 @@ export default function FontEditor(props: {
promptActionSheet(EntryEditorActionSheet, fontEntries, {
name,
fontEntries,
@@ -314,7 +314,7 @@ export default function FontEditor(props: {
delete fontEntries[name]}
/>
}
@@ -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 }}
/>
diff --git a/src/core/ui/settings/pages/General/Version.tsx b/src/core/ui/settings/pages/General/Version.tsx
index 10e87bb..070a90f 100644
--- a/src/core/ui/settings/pages/General/Version.tsx
+++ b/src/core/ui/settings/pages/General/Version.tsx
@@ -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 (
}
+ icon={}
trailing={{version}}
onPress={() => {
clipboard.setString(`${label} - ${version}`);
diff --git a/src/core/ui/settings/pages/General/index.tsx b/src/core/ui/settings/pages/General/index.tsx
index 86cbaef..ef80c84 100644
--- a/src/core/ui/settings/pages/General/index.tsx
+++ b/src/core/ui/settings/pages/General/index.tsx
@@ -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() {
/>
}
+ icon={}
trailing={}
/>
}
+ icon={}
trailing={TableRow.Arrow}
onPress={() => navigation.push("VendettaCustomPage", {
title: Strings.ABOUT,
@@ -44,13 +44,13 @@ export default function General() {
}
+ icon={}
trailing={TableRow.Arrow}
onPress={() => url.openDeeplink(DISCORD_SERVER)}
/>
}
+ icon={}
trailing={TableRow.Arrow}
onPress={() => url.openURL(GITHUB)}
/>
@@ -58,18 +58,18 @@ export default function General() {
}
+ icon={}
onPress={() => NativeModules.BundleUpdaterManager.reload()}
/>
}
+ icon={}
onPress={toggleSafeMode}
/>
}
+ icon={}
value={settings.developerSettings}
onValueChange={(v: boolean) => {
settings.developerSettings = v;
@@ -80,7 +80,7 @@ export default function General() {
}
+ icon={}
value={settings.enableDiscordDeveloperSettings}
onValueChange={(v: boolean) => {
settings.enableDiscordDeveloperSettings = v;
diff --git a/src/core/ui/settings/pages/Plugins/PluginCard.tsx b/src/core/ui/settings/pages/Plugins/PluginCard.tsx
index 7d18b7c..31a93f7 100644
--- a/src/core/ui/settings/pages/Plugins/PluginCard.tsx
+++ b/src/core/ui/settings/pages/Plugins/PluginCard.tsx
@@ -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 = (
@@ -93,7 +93,7 @@ const Actions = memo(() => {
navigation.push("VendettaCustomPage", {
title: plugin.manifest.name,
@@ -103,7 +103,7 @@ const Actions = memo(() => {
void showSheet(
"PluginInfoActionSheet",
import("./sheets/PluginInfoActionSheet"),
diff --git a/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx b/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx
index cbc12ea..de3ebe1 100644
--- a/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx
+++ b/src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.tsx
@@ -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)
}
+ icon={}
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)
/>
}
+ icon={}
onPress={() => {
clipboard.setString(plugin.id);
showToast.showCopyToClipboard();
@@ -70,18 +70,18 @@ export default function PluginInfoActionSheet({ plugin, navigation }: InfoProps)
/>
}
+ icon={}
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"));
}}
/>
}
+ icon={}
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)
/>
}
+ icon={}
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");
}
diff --git a/src/core/ui/settings/pages/Themes/ThemeCard.tsx b/src/core/ui/settings/pages/Themes/ThemeCard.tsx
index 80afe9d..c60243a 100644
--- a/src/core/ui/settings/pages/Themes/ThemeCard.tsx
+++ b/src/core/ui/settings/pages/Themes/ThemeCard.tsx
@@ -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) {
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) {
setRemoved(true);
if (wasSelected) selectAndApply(false, theme);
}).catch((e: Error) => {
- showToast(e.message, requireAssetIndex("Small"));
+ showToast(e.message, findAssetId("Small"));
});
}
})
diff --git a/src/lib/api/assets.ts b/src/lib/api/assets.ts
index e835cab..91831ca 100644
--- a/src/lib/api/assets.ts
+++ b/src/lib/api/assets.ts
@@ -26,8 +26,6 @@ export const assetsMap: Record = new Proxy({}, {
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;
+}
+
diff --git a/src/lib/debug.ts b/src/lib/debug.ts
index 9273cab..37606de 100644
--- a/src/lib/debug.ts
+++ b/src/lib/debug.ts
@@ -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"));
});
}
diff --git a/src/lib/ui/components/Search.tsx b/src/lib/ui/components/Search.tsx
index 5f3b75d..85047f9 100644
--- a/src/lib/ui/components/Search.tsx
+++ b/src/lib/ui/components/Search.tsx
@@ -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 ;
+ return ;
}
export default ({ onChangeText, placeholder, style }: SearchProps) => {
diff --git a/src/lib/ui/components/Summary.tsx b/src/lib/ui/components/Summary.tsx
index 9112022..fb99eac 100644
--- a/src/lib/ui/components/Summary.tsx
+++ b/src/lib/ui/components/Summary.tsx
@@ -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 =
<>
}
+ icon={icon && }
trailing={}
onPress={() => {
setHidden(!hidden);
diff --git a/src/lib/ui/toasts.ts b/src/lib/ui/toasts.ts
index 6d99dd0..a0abb90 100644
--- a/src/lib/ui/toasts.ts
+++ b/src/lib/ui/toasts.ts
@@ -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"));
}
};