mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 01:39:18 +01:00
Force close app if Webview isn't available
This commit is contained in:
parent
abbb329ba6
commit
dff239141d
@ -32,6 +32,8 @@ import eu.kanade.tachiyomi.ui.source.SourceController
|
|||||||
import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController
|
import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchInUI
|
import eu.kanade.tachiyomi.util.lang.launchInUI
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
|
import eu.kanade.tachiyomi.util.system.WebviewUtil
|
||||||
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -64,6 +66,12 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||||||
|
|
||||||
binding = MainActivityBinding.inflate(layoutInflater)
|
binding = MainActivityBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
|
// Enforce Webview availability
|
||||||
|
if (!WebviewUtil.supportsWebview(this)) {
|
||||||
|
toast(R.string.information_webview_required, Toast.LENGTH_LONG)
|
||||||
|
finishAndRemoveTask()
|
||||||
|
}
|
||||||
|
|
||||||
// Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079
|
// Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079
|
||||||
if (!isTaskRoot) {
|
if (!isTaskRoot) {
|
||||||
finish()
|
finish()
|
||||||
|
@ -1,15 +1,23 @@
|
|||||||
package eu.kanade.tachiyomi.util.system
|
package eu.kanade.tachiyomi.util.system
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
|
||||||
private val WEBVIEW_UA_VERSION_REGEX by lazy {
|
object WebviewUtil {
|
||||||
Regex(""".*Chrome/(\d+)\..*""")
|
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 {
|
fun WebView.isOutdated(): Boolean {
|
||||||
return getWebviewMajorVersion(this) < MINIMUM_WEBVIEW_VERSION
|
return getWebviewMajorVersion(this) < WebviewUtil.MINIMUM_WEBVIEW_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on https://stackoverflow.com/a/29218966
|
// 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
|
// Next call to getUserAgentString() will get us the default
|
||||||
webview.settings.userAgentString = null
|
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) {
|
val webViewVersion: Int = if (uaRegexMatch != null && uaRegexMatch.groupValues.size > 1) {
|
||||||
uaRegexMatch.groupValues[1].toInt()
|
uaRegexMatch.groupValues[1].toInt()
|
||||||
} else {
|
} else {
|
||||||
|
@ -593,6 +593,7 @@
|
|||||||
<string name="information_empty_library">Your library is empty, add series to your library from the sources.</string>
|
<string name="information_empty_library">Your library is empty, add series to your library from the sources.</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_cloudflare_bypass_failure">Failed to bypass Cloudflare</string>
|
<string name="information_cloudflare_bypass_failure">Failed to bypass Cloudflare</string>
|
||||||
|
<string name="information_webview_required">Webview is required for Tachiyomi</string>
|
||||||
<string name="information_webview_outdated">Please update the WebView app for better compatibility</string>
|
<string name="information_webview_outdated">Please update the WebView app for better compatibility</string>
|
||||||
|
|
||||||
<!-- Download Notification -->
|
<!-- Download Notification -->
|
||||||
|
Loading…
Reference in New Issue
Block a user