优化web调试

pull/801/head
gedoor 4 years ago
parent a76d64f040
commit b159fb479f
  1. 20
      app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt

@ -22,12 +22,12 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
override fun onOpen() {
launch(IO) {
do {
delay(30000)
runCatching {
kotlin.runCatching {
while (isOpen) {
ping("ping".toByteArray())
delay(30000)
}
}
} while (isOpen)
}
}
@ -42,6 +42,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
override fun onMessage(message: NanoWSD.WebSocketFrame) {
if (!message.textPayload.isJson()) return
launch(IO) {
kotlin.runCatching {
val debugBean = GSON.fromJsonObject<Map<String, String>>(message.textPayload)
if (debugBean != null) {
@ -50,15 +51,16 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
if (tag.isNullOrBlank() || key.isNullOrBlank()) {
send(App.INSTANCE.getString(R.string.cannot_empty))
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false)
return
return@launch
}
App.db.bookSourceDao.getBookSource(tag)?.let {
Debug.callback = this
Debug.callback = this@SourceDebugWebSocket
Debug.startDebug(this, WebBook(it), key)
}
}
}
}
}
override fun onPong(pong: NanoWSD.WebSocketFrame) {
@ -69,12 +71,16 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
}
override fun printLog(state: Int, msg: String) {
kotlin.runCatching {
launch(IO) {
runCatching {
send(msg)
if (state == -1 || state == 1000) {
Debug.cancelDebug(true)
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false)
}
}.onFailure {
it.printStackTrace()
}
}
}

Loading…
Cancel
Save