优化调试

pull/811/head
gedoor 4 years ago
parent 6c965d1ebe
commit a6cbb632f3
  1. 15
      app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt

@ -1,6 +1,7 @@
package io.legado.app.web package io.legado.app.web
import android.os.Looper
import fi.iki.elonen.NanoHTTPD import fi.iki.elonen.NanoHTTPD
import fi.iki.elonen.NanoWSD import fi.iki.elonen.NanoWSD
import io.legado.app.App import io.legado.app.App
@ -71,7 +72,19 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
} }
override fun printLog(state: Int, msg: String) { 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 { runCatching {
send(msg) send(msg)
if (state == -1 || state == 1000) { if (state == -1 || state == 1000) {

Loading…
Cancel
Save