mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 04:28:55 +01:00
Force close app if Webview isn't available
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
package eu.kanade.tachiyomi.util.system
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.webkit.WebView
|
||||
|
||||
private val WEBVIEW_UA_VERSION_REGEX by lazy {
|
||||
Regex(""".*Chrome/(\d+)\..*""")
|
||||
object WebviewUtil {
|
||||
val WEBVIEW_UA_VERSION_REGEX by lazy {
|
||||
Regex(""".*Chrome/(\d+)\..*""")
|
||||
}
|
||||
|
||||
const val MINIMUM_WEBVIEW_VERSION = 79
|
||||
|
||||
fun supportsWebview(context: Context): Boolean {
|
||||
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW)
|
||||
}
|
||||
}
|
||||
|
||||
private const val MINIMUM_WEBVIEW_VERSION = 79
|
||||
|
||||
fun WebView.isOutdated(): Boolean {
|
||||
return getWebviewMajorVersion(this) < MINIMUM_WEBVIEW_VERSION
|
||||
return getWebviewMajorVersion(this) < WebviewUtil.MINIMUM_WEBVIEW_VERSION
|
||||
}
|
||||
|
||||
// Based on https://stackoverflow.com/a/29218966
|
||||
@@ -19,7 +27,7 @@ private fun getWebviewMajorVersion(webview: WebView): Int {
|
||||
// Next call to getUserAgentString() will get us the default
|
||||
webview.settings.userAgentString = null
|
||||
|
||||
val uaRegexMatch = WEBVIEW_UA_VERSION_REGEX.matchEntire(webview.settings.userAgentString)
|
||||
val uaRegexMatch = WebviewUtil.WEBVIEW_UA_VERSION_REGEX.matchEntire(webview.settings.userAgentString)
|
||||
val webViewVersion: Int = if (uaRegexMatch != null && uaRegexMatch.groupValues.size > 1) {
|
||||
uaRegexMatch.groupValues[1].toInt()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user