This commit is contained in:
Horis
2024-07-07 14:41:46 +08:00
parent 7d01189288
commit 3bafe5051e
@@ -18,6 +18,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.runOnUI import io.legado.app.utils.runOnUI
import kotlinx.coroutines.Runnable import kotlinx.coroutines.Runnable
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withTimeout
import org.apache.commons.text.StringEscapeUtils import org.apache.commons.text.StringEscapeUtils
import splitties.init.appCtx import splitties.init.appCtx
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
@@ -42,28 +43,30 @@ class BackstageWebView(
private var callback: Callback? = null private var callback: Callback? = null
private var mWebView: WebView? = null private var mWebView: WebView? = null
suspend fun getStrResponse(): StrResponse = suspendCancellableCoroutine { block -> suspend fun getStrResponse(): StrResponse = withTimeout(60000L) {
block.invokeOnCancellation { suspendCancellableCoroutine { block ->
runOnUI { block.invokeOnCancellation {
destroy() runOnUI {
} destroy()
} }
callback = object : Callback() {
override fun onResult(response: StrResponse) {
if (!block.isCompleted)
block.resume(response)
} }
callback = object : Callback() {
override fun onResult(response: StrResponse) {
if (!block.isCompleted)
block.resume(response)
}
override fun onError(error: Throwable) { override fun onError(error: Throwable) {
if (!block.isCompleted) if (!block.isCompleted)
block.resumeWithException(error) block.resumeWithException(error)
}
} }
} runOnUI {
runOnUI { try {
try { load()
load() } catch (error: Throwable) {
} catch (error: Throwable) { block.resumeWithException(error)
block.resumeWithException(error) }
} }
} }
} }