commit d09d4ee96eb567107bb577019c8b50116f4a41f3
parent 006f9f84e39bc8c9d39b011505c41de62402e0c2
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Tue, 11 Jun 2024 22:14:26 +0200

fix(core): accessibility strings

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

Diffstat:
Mapp/proguard-rules.pro | 1+
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt | 19+++++++++----------
2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro @@ -7,6 +7,7 @@ -keep class org.mozilla.javascript.** { *; } -keep class androidx.compose.material.icons.** { *; } -keep class androidx.compose.material3.R$* { *; } +-keep class androidx.compose.ui.R$* { *; } -keep class androidx.navigation.** { *; } -keep class me.rhunk.snapenhance.** { *; } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt @@ -29,6 +29,7 @@ import me.rhunk.snapenhance.core.util.hook.HookAdapter import me.rhunk.snapenhance.core.util.hook.HookStage import me.rhunk.snapenhance.core.util.hook.hook import me.rhunk.snapenhance.core.util.hook.hookConstructor +import kotlin.reflect.KClass import kotlin.system.exitProcess import kotlin.system.measureTimeMillis @@ -95,6 +96,7 @@ class SnapEnhance { }.onFailure { appContext.log.error("Failed to init LSPatchUpdater", it) } + jetpackComposeResourceHook() runCatching { measureTimeMillis { init(this) @@ -116,7 +118,6 @@ class SnapEnhance { if (isMainActivityNotNull || !appContext.mappings.isMappingsLoaded) return@hookMainActivity appContext.isMainActivityPaused = false onActivityCreate() - jetpackComposeResourceHook() appContext.actionManager.onNewIntent(intent) } @@ -320,16 +321,14 @@ class SnapEnhance { } private fun jetpackComposeResourceHook() { - val material3RString = try { - Class.forName("androidx.compose.material3.R\$string") - } catch (e: ClassNotFoundException) { - return + fun strings(vararg classes: KClass<*>): Map<Int, String> { + return classes.fold(mapOf()) { map, clazz -> + map + clazz.java.fields.filter { + java.lang.reflect.Modifier.isStatic(it.modifiers) && it.type == Int::class.javaPrimitiveType + }.associate { it.getInt(null) to it.name } + } } - - val stringResources = material3RString.fields.filter { - java.lang.reflect.Modifier.isStatic(it.modifiers) && it.type == Int::class.javaPrimitiveType - }.associate { it.getInt(null) to it.name } - + val stringResources = strings(androidx.compose.material3.R.string::class, androidx.compose.ui.R.string::class) Resources::class.java.getMethod("getString", Int::class.javaPrimitiveType).hook(HookStage.BEFORE) { param -> val key = param.arg<Int>(0) val name = stringResources[key]?.replaceFirst("m3c_", "") ?: return@hook