Skip to content

Commit f07f35c

Browse files
committed
Add cache control to WebUIConfigDexFile
Introduced a 'cache' property to WebUIConfigDexFile to allow toggling of interface caching. Updated logic to check the cache only if caching is enabled. Also reformatted DexSourceType enum and createDexLoader function for improved readability.
1 parent 931f97e commit f07f35c

File tree

1 file changed

+14
-5
lines changed
  • webui/src/main/kotlin/com/dergoogler/mmrl/webui/model

1 file changed

+14
-5
lines changed

webui/src/main/kotlin/com/dergoogler/mmrl/webui/model/Config.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ data class WebUIConfigRequire(
9191

9292
@JsonClass(generateAdapter = false)
9393
enum class DexSourceType {
94-
@Json(name = "dex") DEX,
95-
@Json(name = "apk") APK
94+
@Json(name = "dex")
95+
DEX,
96+
@Json(name = "apk")
97+
APK
9698
}
9799

98100
private val interfaceCache = ConcurrentHashMap<String, JavaScriptInterface<out WXInterface>>()
@@ -102,6 +104,7 @@ data class WebUIConfigDexFile(
102104
val type: DexSourceType = DexSourceType.DEX,
103105
val path: String? = null,
104106
val className: String? = null,
107+
val cache: Boolean = true,
105108
) {
106109
private companion object {
107110
const val TAG = "WebUIConfigDexFile"
@@ -124,8 +127,10 @@ data class WebUIConfigDexFile(
124127
val currentClassName = className ?: return null
125128
val currentPath = path ?: return null
126129

127-
// 1. Check cache first for immediate retrieval.
128-
interfaceCache[currentClassName]?.let { return it }
130+
if (cache) {
131+
// 1. Check cache first for immediate retrieval.
132+
interfaceCache[currentClassName]?.let { return it }
133+
}
129134

130135
return try {
131136
// 2. Create the appropriate class loader.
@@ -161,7 +166,11 @@ data class WebUIConfigDexFile(
161166
/**
162167
* Creates a ClassLoader for a standalone .dex file.
163168
*/
164-
private fun createDexLoader(context: Context, modId: ModId, dexPath: String): BaseDexClassLoader? {
169+
private fun createDexLoader(
170+
context: Context,
171+
modId: ModId,
172+
dexPath: String,
173+
): BaseDexClassLoader? {
165174
val file = SuFile(modId.webrootDir, dexPath)
166175

167176
if (!file.isFile || file.extension != "dex") {

0 commit comments

Comments
 (0)