Ensure uploaded logs match debug log viewer.

This commit is contained in:
Greyson Parrelli
2025-08-13 21:20:44 -04:00
parent fc1cd6d262
commit a34ccd8ce7
6 changed files with 132 additions and 21 deletions

View File

@@ -13,6 +13,7 @@ android {
dependencies {
implementation(project(":core-util"))
implementation(project(":core-util-jvm"))
implementation(libs.kotlin.reflect)
implementation(libs.jackson.module.kotlin)

View File

@@ -220,4 +220,13 @@ function applyFilter() {
editor.setValue(filtered, -1);
}
function readLines(offset, limit) {
const lines = logLines.split("\n")
if (offset >= lines.length) {
return "<<END OF INPUT>>";
}
return lines.slice(offset, offset + limit).join("\n")
}
main();

View File

@@ -11,8 +11,10 @@ import android.webkit.ValueCallback
import android.webkit.WebView
import android.webkit.WebViewClient
import kotlinx.coroutines.Runnable
import org.json.JSONArray
import org.json.JSONObject
import org.signal.core.util.ThreadUtil
import java.util.concurrent.CountDownLatch
import java.util.function.Consumer
object DebugLogsViewer {
@@ -47,6 +49,27 @@ object DebugLogsViewer {
ThreadUtil.runOnMain { webview.evaluateJavascript("editor.insert($escaped); logLines+=$escaped;", null) }
}
@JvmStatic
fun readLogs(webview: WebView): LogReader {
var position = 0
return LogReader { size ->
val latch = CountDownLatch(1)
var result: String? = null
ThreadUtil.runOnMain {
webview.evaluateJavascript("readLines($position, $size)") { value ->
// Annoying, string returns from javascript land are always encoded as JSON strings (wrapped in quotes, various strings escaped, etc)
val parsed = JSONArray("[$value]").getString(0)
result = parsed.takeUnless { it == "<<END OF INPUT>>" }
position += size
latch.countDown()
}
}
latch.await()
result
}
}
@JvmStatic
fun scrollToTop(webview: WebView) {
webview.evaluateJavascript("editor.scrollToRow(0);", null)
@@ -107,4 +130,9 @@ object DebugLogsViewer {
fun onSearchClose(webview: WebView) {
webview.evaluateJavascript("onSearchClose();", null)
}
fun interface LogReader {
/** Returns the next bit of log, containing at most [size] lines (but may be less), or null if there are no logs remaining. */
fun nextChunk(size: Int): String?
}
}