This commit is contained in:
kunfei 2023-02-21 22:08:35 +08:00
parent 555e15d534
commit 76fa03e518
2 changed files with 24 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import io.legado.app.data.entities.Cookie
import io.legado.app.help.CacheManager
import io.legado.app.help.http.api.CookieManager
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.removeCookie
object CookieStore : CookieManager {
@ -61,7 +62,7 @@ object CookieStore : CookieManager {
val domain = NetworkUtils.getSubDomain(url)
appDb.cookieDao.delete(domain)
CacheManager.deleteMemory("${domain}_cookie")
android.webkit.CookieManager.getInstance().removeAllCookies(null)
android.webkit.CookieManager.getInstance().removeCookie(domain)
}
override fun cookieToMap(cookie: String): MutableMap<String, String> {

View File

@ -0,0 +1,22 @@
package io.legado.app.utils
import android.webkit.CookieManager
@Suppress("unused")
fun CookieManager.removeCookie(domain: String) {
val cm = CookieManager.getInstance()
val urls = arrayOf(
"http://$domain",
"https://$domain"
)
urls.forEach { url ->
val cookieGlob = cm.getCookie(url)
cookieGlob.split(";").forEach {
val cookieName = it.substringBefore("=")
if (cookieName.isEmpty()) {
cm.setCookie(url, "$cookieName=; Expires=Wed, 31 Dec 2000 23:59:59 GMT")
}
}
}
}