Crashfix + version bump

This commit is contained in:
Blatzar 2022-10-23 18:59:01 +02:00
parent 570fdb5af4
commit 034bad289f
2 changed files with 27 additions and 14 deletions

View file

@ -35,8 +35,8 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 51 versionCode 52
versionName "3.1.5" versionName "3.1.6"
resValue "string", "app_version", resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}" "${defaultConfig.versionName}${versionNameSuffix ?: ""}"

View file

@ -7,7 +7,9 @@ import com.lagradost.cloudstream3.AcraApplication
import com.lagradost.cloudstream3.AcraApplication.Companion.context import com.lagradost.cloudstream3.AcraApplication.Companion.context
import com.lagradost.cloudstream3.USER_AGENT import com.lagradost.cloudstream3.USER_AGENT
import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.debugException
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.Coroutines.mainWork import com.lagradost.cloudstream3.utils.Coroutines.mainWork
import com.lagradost.cloudstream3.utils.Coroutines.threadSafeListOf import com.lagradost.cloudstream3.utils.Coroutines.threadSafeListOf
@ -65,9 +67,15 @@ class WebViewResolver(
method: String = "GET", method: String = "GET",
requestCallBack: (Request) -> Boolean = { false }, requestCallBack: (Request) -> Boolean = { false },
): Pair<Request?, List<Request>> { ): Pair<Request?, List<Request>> {
return resolveUsingWebView( return try {
requestCreator(method, url, referer = referer), requestCallBack resolveUsingWebView(
) requestCreator(method, url, referer = referer), requestCallBack
)
} catch (e: java.lang.IllegalArgumentException) {
logError(e)
debugException { "ILLEGAL URL IN resolveUsingWebView!" }
return null to emptyList()
}
} }
/** /**
@ -129,7 +137,7 @@ class WebViewResolver(
println("Loading WebView URL: $webViewUrl") println("Loading WebView URL: $webViewUrl")
if (interceptUrl.containsMatchIn(webViewUrl)) { if (interceptUrl.containsMatchIn(webViewUrl)) {
fixedRequest = request.toRequest().also { fixedRequest = request.toRequest()?.also {
requestCallBack(it) requestCallBack(it)
} }
println("Web-view request finished: $webViewUrl") println("Web-view request finished: $webViewUrl")
@ -138,9 +146,9 @@ class WebViewResolver(
} }
if (additionalUrls.any { it.containsMatchIn(webViewUrl) }) { if (additionalUrls.any { it.containsMatchIn(webViewUrl) }) {
extraRequestList.add(request.toRequest().also { request.toRequest()?.also {
if (requestCallBack(it)) destroyWebView() if (requestCallBack(it)) destroyWebView()
}) }?.let(extraRequestList::add)
} }
// Suppress image requests as we don't display them anywhere // Suppress image requests as we don't display them anywhere
@ -251,14 +259,19 @@ class WebViewResolver(
} }
fun WebResourceRequest.toRequest(): Request { fun WebResourceRequest.toRequest(): Request? {
val webViewUrl = this.url.toString() val webViewUrl = this.url.toString()
return requestCreator( // If invalid url then it can crash with
this.method, // java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but was 'data'
webViewUrl, // At Request.Builder().url(addParamsToUrl(url, params))
this.requestHeaders, return normalSafeApiCall {
) requestCreator(
this.method,
webViewUrl,
this.requestHeaders,
)
}
} }
fun Response.toWebResourceResponse(): WebResourceResponse { fun Response.toWebResourceResponse(): WebResourceResponse {