Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from gedoor:master #203

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/src/main/assets/web/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<meta charset="UTF-8" />
<link rel="icon" href="./favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<script type="module" crossorigin src="./assets/index-CbAkEkfY.js"></script>
<link rel="modulepreload" crossorigin href="./assets/vendor-s-nmC2k_.js">
<link rel="stylesheet" crossorigin href="./assets/vendor-CLJ3E4SE.css">
<script type="module" crossorigin src="./assets/index-DlKwQuXM.js"></script>
<link rel="modulepreload" crossorigin href="./assets/vendor-Ch2U0QGt.js">
<link rel="stylesheet" crossorigin href="./assets/vendor-BIr1CDSx.css">
<link rel="stylesheet" crossorigin href="./assets/index-Qnqkzihq.css">
</head>

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/io/legado/app/help/http/CookieManager.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.legado.app.help.http

import android.webkit.CookieManager
import io.legado.app.constant.AppLog
import io.legado.app.data.appDb
import io.legado.app.help.CacheManager
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.splitNotBlank
import okhttp3.Cookie
import okhttp3.Headers
import okhttp3.HttpUrl
Expand Down Expand Up @@ -139,6 +141,14 @@ object CookieManager {
}
}

fun applyToWebView(url: String) {
val cookies = CookieStore.getCookie(url).splitNotBlank(";")
val cookieManager = CookieManager.getInstance()
cookies.forEach {
cookieManager.setCookie(url, it)
}
}

fun List<Cookie>.getString() = buildString {
[email protected] { index, cookie ->
if (index > 0) append("; ")
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import io.legado.app.utils.toggleNavigationBar
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
import java.net.URLDecoder
import io.legado.app.help.http.CookieManager as AppCookieManager

class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {

Expand Down Expand Up @@ -171,8 +172,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
userAgentString = it
}
}
val cookieManager = CookieManager.getInstance()
cookieManager.setCookie(url, CookieStore.getCookie(url))
AppCookieManager.applyToWebView(url)
binding.webView.addJavascriptInterface(this, "app")
binding.webView.setOnLongClickListener {
val hitTestResult = binding.webView.hitTestResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import io.legado.app.constant.AppLog
import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.ActivityRssReadBinding
import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.CookieManager
import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor
Expand Down Expand Up @@ -306,6 +307,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
}
viewModel.urlLiveData.observe(this) {
upJavaScriptEnable()
CookieManager.applyToWebView(it.url)
binding.webView.settings.userAgentString = it.getUserAgent()
binding.webView.loadUrl(it.url, it.headerMap)
}
Expand Down
Loading