From a6cbb632f39f5e5d986fd704a39653137a85d8d8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 15 Jan 2021 23:15:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/web/SourceDebugWebSocket.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt index 97a4ad0f1..747a741f5 100644 --- a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt +++ b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt @@ -1,6 +1,7 @@ package io.legado.app.web +import android.os.Looper import fi.iki.elonen.NanoHTTPD import fi.iki.elonen.NanoWSD import io.legado.app.App @@ -71,7 +72,19 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : } override fun printLog(state: Int, msg: String) { - launch(IO) { + if (Looper.getMainLooper() == Looper.myLooper()) { + launch(IO) { + runCatching { + send(msg) + if (state == -1 || state == 1000) { + Debug.cancelDebug(true) + close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) + } + }.onFailure { + it.printStackTrace() + } + } + } else { runCatching { send(msg) if (state == -1 || state == 1000) {