commit c29d142f9180f91c2dbde73b517b15eff4720aeb
parent fafb88d9ce9fa111584565a317b3b19691488bc1
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Thu, 28 Aug 2025 15:39:23 +0200

fix(core): font crash

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>

Diffstat:
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/ui/UserInterface.kt | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/UserInterface.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/UserInterface.kt @@ -20,7 +20,7 @@ class UserInterface( val actionSheetBackground get() = if (context.androidContext.isDarkTheme()) 0xff1e1e1e.toInt() else 0xffffffff.toInt() val avenirNextFontId = 500 - val avenirNextTypeface get() = fontMap[avenirNextFontId] ?: fontMap.entries.sortedBy { it.key }.firstOrNull()?.value ?: Typeface.DEFAULT + val avenirNextTypeface get() = fontMap[avenirNextFontId] ?: fontMap.entries.minByOrNull { it.key }?.value ?: Typeface.DEFAULT fun dpToPx(dp: Int): Int { return (dp * context.resources.displayMetrics.density).toInt() @@ -63,21 +63,21 @@ class UserInterface( it.type == TypedValue.TYPE_STRING && it.string?.endsWith(".ttf") == true } ?: return@hook + unhook() + var offset = typedValue.resourceId.shr(8).shl(8) while (true) { - var font = try { - context.resources.getFont(++offset) + try { + if (context.resources.getResourceTypeName(++offset) != "font") break + val font = runCatching { context.resources.getFont(offset) }.getOrNull() ?: break + fontMap[font.weight] = font } catch (_: Throwable) { break } - - fontMap[font.weight] = font } - - unhook() - }.let { - { it.forEach { it.unhook() } } + }.let { unhooks -> + { unhooks.forEach { it.unhook() } } } } } \ No newline at end of file