perf: lazy extension VM init, incremental startup maintenance, and UI optimizations

- Defer extension VM initialization until first use with lockReadyVM() pattern to eliminate TOCTOU races and reduce startup overhead
- Add validateExtensionLoad() to catch JS errors at install time without keeping VM alive
- Teardown VM on extension disable to free resources; re-init lazily on re-enable
- Replace full orphan cleanup with incremental cursor-based pagination across launches
- Batch DB writes (upsertBatch, replaceAll) with transactions for atomicity
- Parse JSON natively on Kotlin side to avoid double-serialization over MethodChannel
- Add identity-based memoization caches for unified items and path match keys in queue tab
- Use ValueListenableBuilder for targeted embedded cover refreshes instead of full setState
- Extract shared widgets (_buildAlbumGridItemCore, _buildFilterButton, _navigateWithUnfocus)
- Use libraryCollectionsProvider selector and MediaQuery.paddingOf for fewer rebuilds
- Simplify supporter chip tiers and localize remaining hardcoded strings
This commit is contained in:
zarzet
2026-03-25 19:55:02 +07:00
parent da9d64ccfd
commit 03fd734048
18 changed files with 1279 additions and 1133 deletions
@@ -27,6 +27,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONArray
import org.json.JSONObject
import org.json.JSONTokener
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
@@ -413,6 +414,38 @@ class MainActivity: FlutterFragmentActivity() {
}
}
private fun parseJsonValue(value: Any?): Any? {
return when (value) {
null, JSONObject.NULL -> null
is JSONObject -> {
val map = LinkedHashMap<String, Any?>()
val keys = value.keys()
while (keys.hasNext()) {
val key = keys.next()
map[key] = parseJsonValue(value.opt(key))
}
map
}
is JSONArray -> {
val list = ArrayList<Any?>()
for (i in 0 until value.length()) {
list.add(parseJsonValue(value.opt(i)))
}
list
}
is Number, is Boolean, is String -> value
else -> value.toString()
}
}
private fun parseJsonPayload(payload: String): Any {
return try {
parseJsonValue(JSONTokener(payload).nextValue()) ?: payload
} catch (_: Exception) {
payload
}
}
private fun startDownloadProgressStream(sink: EventChannel.EventSink) {
stopDownloadProgressStream()
downloadProgressEventSink = sink
@@ -425,7 +458,7 @@ class MainActivity: FlutterFragmentActivity() {
}
if (payload != lastDownloadProgressPayload) {
lastDownloadProgressPayload = payload
sink.success(payload)
sink.success(parseJsonPayload(payload))
}
} catch (e: Exception) {
android.util.Log.w(
@@ -457,7 +490,7 @@ class MainActivity: FlutterFragmentActivity() {
}
if (payload != lastLibraryScanProgressPayload) {
lastLibraryScanProgressPayload = payload
sink.success(payload)
sink.success(parseJsonPayload(payload))
}
} catch (e: Exception) {
android.util.Log.w(
@@ -2000,13 +2033,13 @@ class MainActivity: FlutterFragmentActivity() {
val response = withContext(Dispatchers.IO) {
Gobackend.getDownloadProgress()
}
result.success(response)
result.success(parseJsonPayload(response))
}
"getAllDownloadProgress" -> {
val response = withContext(Dispatchers.IO) {
Gobackend.getAllDownloadProgress()
}
result.success(response)
result.success(parseJsonPayload(response))
}
"initItemProgress" -> {
val itemId = call.argument<String>("item_id") ?: ""
@@ -3298,7 +3331,7 @@ class MainActivity: FlutterFragmentActivity() {
Gobackend.getLibraryScanProgressJSON()
}
}
result.success(response)
result.success(parseJsonPayload(response))
}
"cancelLibraryScan" -> {
withContext(Dispatchers.IO) {