From 93d81ea038ca3decc15b97d582c09eb8e4303c31 Mon Sep 17 00:00:00 2001 From: Sofie <117321707+Sofie99@users.noreply.github.com> Date: Tue, 20 Feb 2024 03:18:36 +0700 Subject: [PATCH] WebViewResolver: added timeout (#941) --- .../cloudstream3/network/WebViewResolver.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt index 2c11bcdd..90872d94 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt @@ -31,6 +31,7 @@ import java.net.URI * @param useOkhttp will try to use the okhttp client as much as possible, but this might cause some requests to fail. Disable for cloudflare. * @param script pass custom js to execute * @param scriptCallback will be called with the result from custom js + * @param timeout close webview after timeout * */ class WebViewResolver( val interceptUrl: Regex, @@ -38,18 +39,29 @@ class WebViewResolver( val userAgent: String? = USER_AGENT, val useOkhttp: Boolean = true, val script: String? = null, - val scriptCallback: ((String) -> Unit)? = null + val scriptCallback: ((String) -> Unit)? = null, + val timeout: Long = DEFAULT_TIMEOUT ) : Interceptor { + constructor( + interceptUrl: Regex, + additionalUrls: List = emptyList(), + userAgent: String? = USER_AGENT, + useOkhttp: Boolean = true, + script: String? = null, + scriptCallback: ((String) -> Unit)? = null, + ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, script, scriptCallback, DEFAULT_TIMEOUT) + constructor( interceptUrl: Regex, additionalUrls: List = emptyList(), userAgent: String? = USER_AGENT, useOkhttp: Boolean = true - ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, null, null) + ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, null, null, DEFAULT_TIMEOUT) companion object { + private const val DEFAULT_TIMEOUT = 60_000L var webViewUserAgent: String? = null @JvmName("getWebViewUserAgent1") @@ -262,7 +274,7 @@ class WebViewResolver( var loop = 0 // Timeouts after this amount, 60s - val totalTime = 60000L + val totalTime = timeout val delayTime = 100L