diff --git a/app/src/main/java/ani/dantotsu/others/webview/CloudFlare.kt b/app/src/main/java/ani/dantotsu/others/webview/CloudFlare.kt index 11fd7cdb..c7866978 100644 --- a/app/src/main/java/ani/dantotsu/others/webview/CloudFlare.kt +++ b/app/src/main/java/ani/dantotsu/others/webview/CloudFlare.kt @@ -11,7 +11,7 @@ class CloudFlare(override val location: FileUrl) : WebViewBottomDialog() { override var title = "Cloudflare Bypass" override val webViewClient = object : WebViewClient() { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { - val cookie = cookies.getCookie(url.toString()) + val cookie = cookies?.getCookie(url.toString()) if (cookie?.contains(cfTag) == true) { val clearance = cookie.substringAfter("$cfTag=").substringBefore(";") privateCallback.invoke(mapOf(cfTag to clearance)) diff --git a/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt b/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt index 22f11f3f..73ae553a 100644 --- a/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt +++ b/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt @@ -34,8 +34,8 @@ class CookieCatcher : AppCompatActivity() { val webView = findViewById(R.id.discordWebview) - val cookies: CookieManager = Injekt.get().cookieJar.manager - cookies.setAcceptThirdPartyCookies(webView, true) + val cookies: CookieManager? = Injekt.get().cookieJar.manager + cookies?.setAcceptThirdPartyCookies(webView, true) webView.apply { settings.javaScriptEnabled = true diff --git a/app/src/main/java/ani/dantotsu/others/webview/WebViewBottomDialog.kt b/app/src/main/java/ani/dantotsu/others/webview/WebViewBottomDialog.kt index 489c68fc..219c5ff0 100644 --- a/app/src/main/java/ani/dantotsu/others/webview/WebViewBottomDialog.kt +++ b/app/src/main/java/ani/dantotsu/others/webview/WebViewBottomDialog.kt @@ -33,7 +33,7 @@ abstract class WebViewBottomDialog : BottomSheetDialogFragment() { dismiss() } - val cookies: CookieManager = Injekt.get().cookieJar.manager + val cookies: CookieManager? = Injekt.get().cookieJar.manager //CookieManager.getInstance() override fun onCreateView( @@ -52,7 +52,7 @@ abstract class WebViewBottomDialog : BottomSheetDialogFragment() { javaScriptEnabled = true userAgentString = defaultHeaders["User-Agent"] } - cookies.setAcceptThirdPartyCookies(binding.webView, true) + cookies?.setAcceptThirdPartyCookies(binding.webView, true) binding.webView.webViewClient = webViewClient binding.webView.loadUrl(location.url, location.headers) this.dismiss() diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt b/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt index 055bab09..2b57445f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/AndroidCookieJar.kt @@ -1,18 +1,24 @@ package eu.kanade.tachiyomi.network import android.webkit.CookieManager +import ani.dantotsu.snackString import okhttp3.Cookie import okhttp3.CookieJar import okhttp3.HttpUrl class AndroidCookieJar : CookieJar { - val manager: CookieManager = CookieManager.getInstance() + val manager: CookieManager? = try { + CookieManager.getInstance() + } catch (e: Exception) { + snackString("Webview is outdated, please update your webview") + null + } override fun saveFromResponse(url: HttpUrl, cookies: List) { val urlString = url.toString() - cookies.forEach { manager.setCookie(urlString, it.toString()) } + cookies.forEach { manager?.setCookie(urlString, it.toString()) } } override fun loadForRequest(url: HttpUrl): List { @@ -20,9 +26,9 @@ class AndroidCookieJar : CookieJar { } fun get(url: HttpUrl): List { - val cookies = manager.getCookie(url.toString()) + val cookies = manager?.getCookie(url.toString()) - return if (cookies != null && cookies.isNotEmpty()) { + return if (!cookies.isNullOrEmpty()) { cookies.split(";").mapNotNull { Cookie.parse(url, it) } } else { emptyList() @@ -31,7 +37,7 @@ class AndroidCookieJar : CookieJar { fun remove(url: HttpUrl, cookieNames: List? = null, maxAge: Int = -1): Int { val urlString = url.toString() - val cookies = manager.getCookie(urlString) ?: return 0 + val cookies = manager?.getCookie(urlString) ?: return 0 fun List.filterNames(): List { return if (cookieNames != null) { @@ -49,6 +55,6 @@ class AndroidCookieJar : CookieJar { } fun removeAll() { - manager.removeAllCookies {} + manager?.removeAllCookies {} } }