Ask user to update WebView when es2020 is not supported
This commit is contained in:
8
.idea/deploymentTargetDropDown.xml
generated
8
.idea/deploymentTargetDropDown.xml
generated
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<targetSelectedWithDropDown>
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
@@ -11,7 +11,7 @@
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2022-01-22T00:36:10.057058Z" />
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2022-01-24T19:20:51.436372Z" />
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -3,6 +3,7 @@
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="../../../../layout/custom_preview.xml" value="0.2564814814814815" />
|
||||
<entry key="app/src/main/res/layout/reader_activity.xml" value="0.14351851851851852" />
|
||||
</map>
|
||||
</option>
|
||||
|
||||
@@ -38,7 +38,7 @@ android {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 31
|
||||
versionCode 69
|
||||
versionName "5.2.19"
|
||||
versionName "5.2.20"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
}
|
||||
@@ -91,6 +91,7 @@ dependencies {
|
||||
implementation "androidx.gridlayout:gridlayout:1.0.0"
|
||||
implementation "androidx.biometric:biometric:1.1.0"
|
||||
implementation "androidx.work:work-runtime-ktx:2.7.1"
|
||||
implementation 'androidx.webkit:webkit:1.4.0'
|
||||
|
||||
implementation "com.daimajia.swipelayout:library:1.2.0@aar"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 69,
|
||||
"versionName": "5.2.19",
|
||||
"versionName": "5.2.20",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -29,10 +29,10 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.webkit.*
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.webkit.WebViewCompat
|
||||
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
|
||||
import com.github.piasy.biv.BigImageViewer
|
||||
import com.github.piasy.biv.loader.fresco.FrescoImageLoader
|
||||
@@ -43,6 +43,8 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.*
|
||||
import xyz.quaver.io.FileX
|
||||
import xyz.quaver.pupil.hitomi.evaluationContext
|
||||
@@ -83,6 +85,7 @@ val _webViewFlow = MutableSharedFlow<Pair<String, String?>>()
|
||||
val webViewFlow = _webViewFlow.asSharedFlow()
|
||||
var webViewReady = false
|
||||
var webViewFailed = false
|
||||
var oldWebView = false
|
||||
private var reloadJob: Job? = null
|
||||
|
||||
fun reloadWebView() {
|
||||
@@ -91,6 +94,7 @@ fun reloadWebView() {
|
||||
reloadJob = CoroutineScope(Dispatchers.IO).launch {
|
||||
webViewReady = false
|
||||
webViewFailed = false
|
||||
oldWebView = false
|
||||
|
||||
evaluationContext.cancelChildren(CancellationException("reload"))
|
||||
|
||||
@@ -156,7 +160,21 @@ fun initWebView(context: Context) {
|
||||
|
||||
webViewClient = object: WebViewClient() {
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
webViewReady = true
|
||||
webView.evaluateJavascript(
|
||||
"""
|
||||
try {
|
||||
new Function('(x => x?.y ?? z)');
|
||||
true;
|
||||
} catch (err) {
|
||||
false;
|
||||
}
|
||||
""".trimIndent()
|
||||
) {
|
||||
val es2020: Boolean = Json.decodeFromString(it)
|
||||
|
||||
webViewReady = es2020
|
||||
oldWebView = !es2020
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReceivedError(
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package xyz.quaver.pupil.hitomi
|
||||
|
||||
import android.util.Log
|
||||
import android.webkit.WebView
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -25,10 +26,7 @@ import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import xyz.quaver.pupil.webView
|
||||
import xyz.quaver.pupil.webViewFailed
|
||||
import xyz.quaver.pupil.webViewFlow
|
||||
import xyz.quaver.pupil.webViewReady
|
||||
import xyz.quaver.pupil.*
|
||||
import java.util.*
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
@@ -55,9 +53,11 @@ suspend inline fun <reified T> WebView.evaluate(script: String): T = coroutineSc
|
||||
|
||||
while (result == null) {
|
||||
try {
|
||||
result = withContext(evaluationContext) {
|
||||
while (webViewFailed || !webViewReady) yield()
|
||||
while (!oldWebView && !(webViewReady && !webViewFailed)) yield()
|
||||
|
||||
result = if (oldWebView)
|
||||
"null"
|
||||
else withContext(evaluationContext) {
|
||||
suspendCoroutine { continuation ->
|
||||
evaluateJavascript(script) {
|
||||
continuation.resume(it)
|
||||
@@ -82,9 +82,11 @@ suspend inline fun <reified T> WebView.evaluatePromise(
|
||||
|
||||
while (result == null) {
|
||||
try {
|
||||
result = withContext(evaluationContext) {
|
||||
while (webViewFailed || !webViewReady) yield()
|
||||
while (!oldWebView && !(webViewReady && !webViewFailed)) yield()
|
||||
|
||||
result = if (oldWebView)
|
||||
"null"
|
||||
else withContext(evaluationContext) {
|
||||
val uid = UUID.randomUUID().toString()
|
||||
|
||||
val flow: Flow<Pair<String, String?>> = webViewFlow.transformWhile { (currentUid, result) ->
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package xyz.quaver.pupil.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -37,6 +38,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.webkit.WebViewCompat
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
@@ -105,6 +107,8 @@ class MainActivity :
|
||||
|
||||
private lateinit var binding: MainActivityBinding
|
||||
|
||||
private var oldWebViewJob: Job? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = MainActivityBinding.inflate(layoutInflater)
|
||||
@@ -125,9 +129,40 @@ class MainActivity :
|
||||
if (Preferences["download_folder", ""].isEmpty())
|
||||
DownloadLocationDialogFragment().show(supportFragmentManager, "Download Location Dialog")
|
||||
|
||||
oldWebViewJob = CoroutineScope(Dispatchers.Unconfined).launch {
|
||||
do {
|
||||
delay(1000)
|
||||
if (oldWebView) {
|
||||
AlertDialog.Builder(this@MainActivity)
|
||||
.setTitle(android.R.string.dialog_alert_title)
|
||||
.setMessage(R.string.old_webview)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
WebViewCompat.getCurrentWebViewPackage(this@MainActivity)?.packageName?.let { packageName ->
|
||||
try {
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("market://details?id=$packageName")
|
||||
)
|
||||
)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://play.google.com/store/apps/details?id=$packageName")
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.show()
|
||||
break
|
||||
}
|
||||
} while (isActive)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
|
||||
!Preferences["download_folder_ignore_warning", false] &&
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Preferences["download_folder_ignore_warning", false] &&
|
||||
ContextCompat.getExternalFilesDirs(this, null).filterNotNull().map { Uri.fromFile(it).toString() }
|
||||
.contains(Preferences["download_folder", ""])
|
||||
) {
|
||||
@@ -169,6 +204,8 @@ class MainActivity :
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
|
||||
oldWebViewJob?.cancel()
|
||||
|
||||
(binding.contents.recyclerview.adapter as? GalleryBlockAdapter)?.updateAll = false
|
||||
}
|
||||
|
||||
|
||||
@@ -157,4 +157,5 @@
|
||||
<string name="settings_max_concurrent_download">並列ダウンロード</string>
|
||||
<string name="unaccessible_download_folder">アンドロイド11以上では外部からのアプリ内部空間接近が不可能です。ダウンロードフォルダを変更しますか?</string>
|
||||
<string name="settings_networking">ネットワーク</string>
|
||||
<string name="old_webview">WebViewのアップデートが必要です</string>
|
||||
</resources>
|
||||
@@ -157,4 +157,5 @@
|
||||
<string name="settings_max_concurrent_download">병렬 다운로드</string>
|
||||
<string name="unaccessible_download_folder">안드로이드 11 이상에서는 외부에서 현재 다운로드 폴더에 접근할 수 없습니다. 변경하시겠습니까?</string>
|
||||
<string name="settings_networking">네트워크</string>
|
||||
<string name="old_webview">WebView 업데이트가 필요합니다</string>
|
||||
</resources>
|
||||
@@ -51,6 +51,8 @@
|
||||
|
||||
<string name="unaccessible_download_folder">From Android 11 and above, current Download folder cannot be accessed by outside apps. Would you like to change the download folder?</string>
|
||||
|
||||
<string name="old_webview">You are using an old version of WebView. Please update it on PlayStore</string>
|
||||
|
||||
<string name="main_drawer_home">Home</string>
|
||||
<string name="main_drawer_history">History</string>
|
||||
<string name="main_drawer_downloads">Downloads</string>
|
||||
|
||||
Reference in New Issue
Block a user