mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
9f5a22f01b
commit
e008156a18
@ -74,7 +74,7 @@ object CookieStore : CookieManagerInterface {
|
||||
appDb.cookieDao.delete(domain)
|
||||
CacheManager.deleteMemory("${domain}_cookie")
|
||||
CacheManager.deleteMemory("${domain}_session_cookie")
|
||||
android.webkit.CookieManager.getInstance().removeCookie(domain)
|
||||
android.webkit.CookieManager.getInstance().removeCookie(url)
|
||||
}
|
||||
|
||||
override fun cookieToMap(cookie: String): MutableMap<String, String> {
|
||||
|
@ -6,17 +6,17 @@ import android.webkit.CookieManager
|
||||
|
||||
|
||||
@Suppress("unused")
|
||||
fun CookieManager.removeCookie(domain: String) {
|
||||
fun CookieManager.removeCookie(url: String) {
|
||||
val cm = CookieManager.getInstance()
|
||||
val urls = arrayOf(
|
||||
"http://$domain",
|
||||
"https://$domain"
|
||||
val domains = arrayOf(
|
||||
NetworkUtils.getDomain(url),
|
||||
NetworkUtils.getSubDomain(url)
|
||||
)
|
||||
urls.forEach { url ->
|
||||
val cookieGlob: String? = cm.getCookie(url)
|
||||
domains.forEach { dm ->
|
||||
val cookieGlob: String? = cm.getCookie(dm)
|
||||
cookieGlob?.splitNotBlank(";")?.forEach {
|
||||
val cookieName = it.substringBefore("=")
|
||||
cm.setCookie(url, "$cookieName=; Expires=Wed, 31 Dec 2000 23:59:59 GMT")
|
||||
cm.setCookie(dm, "$cookieName=; Expires=Wed, 31 Dec 2000 23:59:59 GMT")
|
||||
}
|
||||
}
|
||||
}
|
@ -179,6 +179,13 @@ object NetworkUtils {
|
||||
}.getOrDefault(baseUrl)
|
||||
}
|
||||
|
||||
fun getDomain(url: String): String {
|
||||
val baseUrl = getBaseUrl(url) ?: return url
|
||||
return kotlin.runCatching {
|
||||
URL(baseUrl).host
|
||||
}.getOrDefault(baseUrl)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local Ip address.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user