Fix settings profile cookie
This commit is contained in:
1 parent
b944d073de
commit
26f05a0800
2 files changed
+16
-7
No files matched your search
@@ -47,6 +47,7 @@ object EhCookieStore : CookieJar, CookiesStorage {
|
||||
const val KEY_IPB_MEMBER_ID = "ipb_member_id"
|
||||
const val KEY_IPB_PASS_HASH = "ipb_pass_hash"
|
||||
const val KEY_IGNEOUS = "igneous"
|
||||
const val KEY_SETTINGS_PROFILE = "sp"
|
||||
private const val KEY_CONTENT_WARNING = "nw"
|
||||
private const val CONTENT_WARNING_NOT_SHOW = "1"
|
||||
private val sTipsCookie: Cookie = Cookie.Builder()
|
||||
@@ -86,6 +87,16 @@ object EhCookieStore : CookieJar, CookiesStorage {
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun deleteCookie(url: HttpUrl, name: String) {
|
||||
val deletedCookie = Cookie.Builder()
|
||||
.name(name)
|
||||
.value("deleted")
|
||||
.domain(url.host)
|
||||
.expiresAt(0)
|
||||
.build()
|
||||
addCookie(deletedCookie)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun addCookie(cookie: Cookie) {
|
||||
// For cookie database
|
||||
|
||||
@@ -35,6 +35,7 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.hippo.ehviewer.EhApplication.Companion.ehCookieStore
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.EhCookieStore.KEY_SETTINGS_PROFILE
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.databinding.ActivityWebviewBinding
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene
|
||||
@@ -134,16 +135,13 @@ class UConfigFragment : BaseFragment() {
|
||||
val cookiesString = cookieManager.getCookie(url)
|
||||
if (!cookiesString.isNullOrEmpty()) {
|
||||
val store = ehCookieStore
|
||||
val eUrl = EhUrl.HOST_E.toHttpUrl()
|
||||
val exUrl = EhUrl.HOST_EX.toHttpUrl()
|
||||
val hostUrl = EhUrl.host.toHttpUrl()
|
||||
|
||||
lifecycleScope.launchIO {
|
||||
// The cookies saved in the uconfig page should be shared between e and ex
|
||||
store.deleteCookie(hostUrl, KEY_SETTINGS_PROFILE)
|
||||
// The cookies saved in the uconfig page should not be shared between e and ex
|
||||
for (header in cookiesString.split(";".toRegex()).dropLastWhile { it.isEmpty() }) {
|
||||
Cookie.parse(eUrl, header)?.let {
|
||||
store.addCookie(longLive(it))
|
||||
}
|
||||
Cookie.parse(exUrl, header)?.let {
|
||||
Cookie.parse(hostUrl, header)?.let {
|
||||
store.addCookie(longLive(it))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user