pull/1352/head
gedoor 3 years ago
parent 995c9098db
commit 5db9d95b92
  1. 17
      app/src/main/java/io/legado/app/help/http/BackstageWebView.kt

@ -14,10 +14,11 @@ import kotlinx.coroutines.*
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
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.resume import kotlin.coroutines.resume
/**
* 后台webView
*/
class BackstageWebView( class BackstageWebView(
private val url: String? = null, private val url: String? = null,
private val html: String? = null, private val html: String? = null,
@ -26,17 +27,13 @@ class BackstageWebView(
private val headerMap: Map<String, String>? = null, private val headerMap: Map<String, String>? = null,
private val sourceRegex: String? = null, private val sourceRegex: String? = null,
private val javaScript: String? = null, private val javaScript: String? = null,
) : CoroutineScope { ) {
private lateinit var job: Job private lateinit var job: Job
private val mHandler = Handler(Looper.getMainLooper()) private val mHandler = Handler(Looper.getMainLooper())
private var callback: Callback? = null private var callback: Callback? = null
private var mWebView: WebView? = null private var mWebView: WebView? = null
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job
suspend fun getStrResponse(): StrResponse = suspendCancellableCoroutine { block -> suspend fun getStrResponse(): StrResponse = suspendCancellableCoroutine { block ->
job = Job()
block.invokeOnCancellation { block.invokeOnCancellation {
destroy() destroy()
} }
@ -95,10 +92,8 @@ class BackstageWebView(
} }
private fun destroy() { private fun destroy() {
launch { mWebView?.destroy()
mWebView?.destroy() mWebView = null
mWebView = null
}
job.cancel() job.cancel()
} }

Loading…
Cancel
Save