From cec69827642f6535c1f6eb3ba1d2f68c6d59b6fe Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 2 Nov 2019 23:21:15 +0800 Subject: [PATCH] up --- .../io/legado/app/help/http/HttpHelper.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 61ea749fd..44bb29346 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/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) + } + } \ No newline at end of file