mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 22:41:48 +01:00
Show message if WebView version is too low
This commit is contained in:
parent
72ef5d8f8d
commit
f515674dff
@ -8,6 +8,7 @@ import android.os.Looper
|
|||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
||||||
|
import eu.kanade.tachiyomi.util.system.checkVersion
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
@ -78,12 +79,15 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
|||||||
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
|
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
|
||||||
|
|
||||||
handler.post {
|
handler.post {
|
||||||
val view = WebView(context)
|
val webview = WebView(context)
|
||||||
webView = view
|
webView = webview
|
||||||
view.settings.javaScriptEnabled = true
|
|
||||||
view.settings.userAgentString = request.header("User-Agent")
|
|
||||||
view.webViewClient = object : WebViewClientCompat() {
|
|
||||||
|
|
||||||
|
webview.checkVersion()
|
||||||
|
|
||||||
|
webview.settings.javaScriptEnabled = true
|
||||||
|
webview.settings.userAgentString = request.header("User-Agent")
|
||||||
|
|
||||||
|
webview.webViewClient = object : WebViewClientCompat() {
|
||||||
override fun onPageFinished(view: WebView, url: String) {
|
override fun onPageFinished(view: WebView, url: String) {
|
||||||
fun isCloudFlareBypassed(): Boolean {
|
fun isCloudFlareBypassed(): Boolean {
|
||||||
return networkHelper.cookieManager.get(origRequestUrl.toHttpUrl())
|
return networkHelper.cookieManager.get(origRequestUrl.toHttpUrl())
|
||||||
@ -122,6 +126,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webView?.loadUrl(origRequestUrl, headers)
|
webView?.loadUrl(origRequestUrl, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.webview
|
package eu.kanade.tachiyomi.ui.webview
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
@ -14,10 +15,7 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
import eu.kanade.tachiyomi.util.system.*
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
|
||||||
import eu.kanade.tachiyomi.util.view.invisible
|
import eu.kanade.tachiyomi.util.view.invisible
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
import eu.kanade.tachiyomi.util.view.visible
|
||||||
import kotlinx.android.synthetic.main.webview_activity.*
|
import kotlinx.android.synthetic.main.webview_activity.*
|
||||||
@ -29,6 +27,7 @@ class WebViewActivity : BaseActivity() {
|
|||||||
|
|
||||||
private var bundle: Bundle? = null
|
private var bundle: Bundle? = null
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.webview_activity)
|
setContentView(R.layout.webview_activity)
|
||||||
@ -54,6 +53,11 @@ class WebViewActivity : BaseActivity() {
|
|||||||
val url = intent.extras!!.getString(URL_KEY) ?: return
|
val url = intent.extras!!.getString(URL_KEY) ?: return
|
||||||
val headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
|
val headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
|
||||||
|
|
||||||
|
webview.checkVersion()
|
||||||
|
|
||||||
|
webview.settings.javaScriptEnabled = true
|
||||||
|
webview.settings.userAgentString = source.headers["User-Agent"]
|
||||||
|
|
||||||
webview.webChromeClient = object : WebChromeClient() {
|
webview.webChromeClient = object : WebChromeClient() {
|
||||||
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
||||||
progress_bar.visible()
|
progress_bar.visible()
|
||||||
@ -91,8 +95,7 @@ class WebViewActivity : BaseActivity() {
|
|||||||
nested_view.scrollTo(0, 0)
|
nested_view.scrollTo(0, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
webview.settings.javaScriptEnabled = true
|
|
||||||
webview.settings.userAgentString = source.headers["User-Agent"]
|
|
||||||
webview.loadUrl(url, headers)
|
webview.loadUrl(url, headers)
|
||||||
} else {
|
} else {
|
||||||
webview.restoreState(bundle)
|
webview.restoreState(bundle)
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package eu.kanade.tachiyomi.util.system
|
||||||
|
|
||||||
|
import android.webkit.WebView
|
||||||
|
import android.widget.Toast
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
|
||||||
|
private val WEBVIEW_UA_VERSION_REGEX by lazy {
|
||||||
|
Regex(""".*Chrome/(\d+)\..*""")
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val MINIMUM_WEBVIEW_VERSION = 78
|
||||||
|
|
||||||
|
fun WebView.checkVersion() {
|
||||||
|
if (getWebviewMajorVersion(this) < MINIMUM_WEBVIEW_VERSION) {
|
||||||
|
this.context.toast(R.string.information_webview_outdated, Toast.LENGTH_LONG)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Based on https://stackoverflow.com/a/29218966
|
||||||
|
private fun getWebviewMajorVersion(webview: WebView): Int {
|
||||||
|
val originalUA: String = webview.settings.userAgentString
|
||||||
|
|
||||||
|
// Next call to getUserAgentString() will get us the default
|
||||||
|
webview.settings.userAgentString = null
|
||||||
|
|
||||||
|
val uaRegexMatch = WEBVIEW_UA_VERSION_REGEX.matchEntire(webview.settings.userAgentString)
|
||||||
|
val webViewVersion: Int = if (uaRegexMatch != null && uaRegexMatch.groupValues.size > 1) {
|
||||||
|
uaRegexMatch.groupValues[1].toInt()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revert to original UA string
|
||||||
|
webview.settings.userAgentString = originalUA
|
||||||
|
|
||||||
|
return webViewVersion
|
||||||
|
}
|
@ -522,6 +522,7 @@
|
|||||||
<string name="information_no_recent_manga">No recently read manga</string>
|
<string name="information_no_recent_manga">No recently read manga</string>
|
||||||
<string name="information_empty_library">Your library is empty, add series to your library from the catalogues.</string>
|
<string name="information_empty_library">Your library is empty, add series to your library from the catalogues.</string>
|
||||||
<string name="information_empty_category">You have no categories. Hit the plus button to create one for organizing your library.</string>
|
<string name="information_empty_category">You have no categories. Hit the plus button to create one for organizing your library.</string>
|
||||||
|
<string name="information_webview_outdated">Please update the WebView app for better compatibility</string>
|
||||||
|
|
||||||
<!-- Download Notification -->
|
<!-- Download Notification -->
|
||||||
<string name="download_notifier_downloader_title">Downloader</string>
|
<string name="download_notifier_downloader_title">Downloader</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user