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