From 57df83636222ca7b1e2fb335718751e04f2ed27c Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Thu, 8 Sep 2022 23:20:10 +0800 Subject: [PATCH] Mangabz: fix stubbed CookieManager (#13398) --- .../mangabz/mangabz/src/CookieInterceptor.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/multisrc/overrides/mangabz/mangabz/src/CookieInterceptor.kt b/multisrc/overrides/mangabz/mangabz/src/CookieInterceptor.kt index ab65d5fc3..183232fab 100644 --- a/multisrc/overrides/mangabz/mangabz/src/CookieInterceptor.kt +++ b/multisrc/overrides/mangabz/mangabz/src/CookieInterceptor.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.extension.zh.mangabz +import android.util.Log import android.webkit.CookieManager import okhttp3.Interceptor import okhttp3.Response @@ -13,7 +14,7 @@ class CookieInterceptor( init { val url = "https://$domain/" val cookie = "$key=$value; Domain=$domain; Path=/" - CookieManager.getInstance().setCookie(url, cookie) + setCookie(url, cookie) } override fun intercept(chain: Interceptor.Chain): Response { @@ -24,7 +25,7 @@ class CookieInterceptor( val cookieList = request.header("Cookie")?.split("; ") ?: emptyList() if (cookie in cookieList) return chain.proceed(request) - CookieManager.getInstance().setCookie("https://$domain/", "$cookie; Domain=$domain; Path=/") + setCookie("https://$domain/", "$cookie; Domain=$domain; Path=/") val prefix = "$key=" val newCookie = buildList(cookieList.size + 1) { cookieList.filterNotTo(this) { it.startsWith(prefix) } @@ -33,4 +34,13 @@ class CookieInterceptor( val newRequest = request.newBuilder().header("Cookie", newCookie).build() return chain.proceed(newRequest) } + + private fun setCookie(url: String, value: String) { + try { + CookieManager.getInstance().setCookie(url, value) + } catch (e: Exception) { + // Probably running on Tachidesk + Log.e("Mangabz", "failed to set cookie", e) + } + } }