pull/45/head
kunfei 5 years ago
parent 4e25c675a4
commit cec6982764
  1. 22
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt

@ -94,4 +94,26 @@ object HttpHelper {
}
ajaxWebView.ajax(params)
}
@ExperimentalCoroutinesApi
suspend fun sniff(params: AjaxWebView.AjaxParams): String =
suspendCancellableCoroutine { block ->
val ajaxWebView = AjaxWebView()
ajaxWebView.callback = object : AjaxWebView.Callback() {
override fun onResult(result: String) {
block.resume(result) {
ajaxWebView.destroyWebView()
}
}
override fun onError(error: Throwable) {
block.resume(error.localizedMessage) {
ajaxWebView.destroyWebView()
}
}
}
ajaxWebView.sniff(params)
}
}
Loading…
Cancel
Save