Fix race condition where not all logs would be added to the viewer.

This commit is contained in:
Greyson Parrelli
2025-08-13 21:43:01 -04:00
parent a34ccd8ce7
commit 33f7fdedfa
3 changed files with 29 additions and 18 deletions

View File

@@ -27,7 +27,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.ThreadUtil;
import org.signal.debuglogsviewer.DebugLogsViewer;
import org.thoughtcrime.securesms.BaseActivity;
import org.thoughtcrime.securesms.R;
@@ -44,9 +44,9 @@ import org.thoughtcrime.securesms.util.views.CircularProgressMaterialButton;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
public class SubmitDebugLogActivity extends BaseActivity {
@@ -346,19 +346,22 @@ public class SubmitDebugLogActivity extends BaseActivity {
private void subscribeToLogLines() {
Disposable disposable = viewModel.getLogLinesObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::presentLines, throwable -> {
.observeOn(Schedulers.io())
.subscribe(this::appendLines, throwable -> {
// Handle error
ThreadUtil.runOnMain(() -> {
this.progressCard.setVisibility(View.GONE);
});
});
disposables.add(disposable);
}
private void presentLines(@NonNull List<String> lines) {
private void appendLines(@NonNull List<String> lines) {
ThreadUtil.runOnMain(() -> {
warningBanner.setVisibility(View.VISIBLE);
submitButton.setVisibility(View.VISIBLE);
});
SignalExecutors.BOUNDED.execute(() -> {
StringBuilder lineBuilder = new StringBuilder();
for (String line : lines) {
@@ -366,7 +369,6 @@ public class SubmitDebugLogActivity extends BaseActivity {
}
DebugLogsViewer.appendLines(logWebView, lineBuilder.toString());
});
}
private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) {

View File

@@ -220,6 +220,11 @@ function applyFilter() {
editor.setValue(filtered, -1);
}
function appendLines(lines) {
editor.session.insert({ row: editor.session.getLength(), column: 0}, lines);
logLines += lines;
}
function readLines(offset, limit) {
const lines = logLines.split("\n")
if (offset >= lines.length) {

View File

@@ -46,7 +46,11 @@ object DebugLogsViewer {
fun appendLines(webview: WebView, lines: String) {
// Set the debug log lines
val escaped = JSONObject.quote(lines)
ThreadUtil.runOnMain { webview.evaluateJavascript("editor.insert($escaped); logLines+=$escaped;", null) }
val latch = CountDownLatch(1)
ThreadUtil.runOnMain {
webview.evaluateJavascript("appendLines($escaped)") { latch.countDown() }
}
latch.await()
}
@JvmStatic