From 3bafe5051eeb629c0500d5ab5363b34f1eff3a27 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:41:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/http/BackstageWebView.kt | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt b/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt index 16b89cd63..492714204 100644 --- a/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt @@ -18,6 +18,7 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.utils.runOnUI import kotlinx.coroutines.Runnable import kotlinx.coroutines.suspendCancellableCoroutine +import kotlinx.coroutines.withTimeout import org.apache.commons.text.StringEscapeUtils import splitties.init.appCtx import java.lang.ref.WeakReference @@ -42,28 +43,30 @@ class BackstageWebView( private var callback: Callback? = null private var mWebView: WebView? = null - suspend fun getStrResponse(): StrResponse = suspendCancellableCoroutine { block -> - block.invokeOnCancellation { - runOnUI { - destroy() - } - } - callback = object : Callback() { - override fun onResult(response: StrResponse) { - if (!block.isCompleted) - block.resume(response) + suspend fun getStrResponse(): StrResponse = withTimeout(60000L) { + suspendCancellableCoroutine { block -> + block.invokeOnCancellation { + runOnUI { + destroy() + } } + callback = object : Callback() { + override fun onResult(response: StrResponse) { + if (!block.isCompleted) + block.resume(response) + } - override fun onError(error: Throwable) { - if (!block.isCompleted) - block.resumeWithException(error) + override fun onError(error: Throwable) { + if (!block.isCompleted) + block.resumeWithException(error) + } } - } - runOnUI { - try { - load() - } catch (error: Throwable) { - block.resumeWithException(error) + runOnUI { + try { + load() + } catch (error: Throwable) { + block.resumeWithException(error) + } } } }