mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 11:08:31 +00:00
Fix race condition where not all logs would be added to the viewer.
This commit is contained in:
@@ -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,27 +346,29 @@ 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
|
||||
this.progressCard.setVisibility(View.GONE);
|
||||
ThreadUtil.runOnMain(() -> {
|
||||
this.progressCard.setVisibility(View.GONE);
|
||||
});
|
||||
});
|
||||
disposables.add(disposable);
|
||||
}
|
||||
|
||||
private void presentLines(@NonNull List<String> lines) {
|
||||
warningBanner.setVisibility(View.VISIBLE);
|
||||
submitButton.setVisibility(View.VISIBLE);
|
||||
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
StringBuilder lineBuilder = new StringBuilder();
|
||||
|
||||
for (String line : lines) {
|
||||
lineBuilder.append(line).append("\n");
|
||||
}
|
||||
|
||||
DebugLogsViewer.appendLines(logWebView, lineBuilder.toString());
|
||||
private void appendLines(@NonNull List<String> lines) {
|
||||
ThreadUtil.runOnMain(() -> {
|
||||
warningBanner.setVisibility(View.VISIBLE);
|
||||
submitButton.setVisibility(View.VISIBLE);
|
||||
});
|
||||
|
||||
StringBuilder lineBuilder = new StringBuilder();
|
||||
|
||||
for (String line : lines) {
|
||||
lineBuilder.append(line).append("\n");
|
||||
}
|
||||
|
||||
DebugLogsViewer.appendLines(logWebView, lineBuilder.toString());
|
||||
}
|
||||
|
||||
private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user