diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 784f98ae..b4f545e3 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -7,11 +7,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 5ec63a1c..3f2ac10c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -38,7 +38,7 @@ android {
minSdkVersion 16
targetSdkVersion 31
versionCode 69
- versionName "5.2.6"
+ versionName "5.2.8-BETA01"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
index 0645f022..966545ef 100644
--- a/app/release/output-metadata.json
+++ b/app/release/output-metadata.json
@@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 69,
- "versionName": "5.2.6",
+ "versionName": "5.2.8-BETA01",
"outputFile": "app-release.apk"
}
],
diff --git a/app/src/main/java/xyz/quaver/pupil/Pupil.kt b/app/src/main/java/xyz/quaver/pupil/Pupil.kt
index a74a850d..66762a51 100644
--- a/app/src/main/java/xyz/quaver/pupil/Pupil.kt
+++ b/app/src/main/java/xyz/quaver/pupil/Pupil.kt
@@ -166,7 +166,7 @@ class Pupil : Application() {
instance = this
isDebugBuild = applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
- WebView.setWebContentsDebuggingEnabled(true)
+ if (isDebugBuild) WebView.setWebContentsDebuggingEnabled(true)
webView = WebView(this).apply {
with (settings) {
@@ -257,11 +257,10 @@ class Pupil : Application() {
try {
Preferences.get("download_folder").also {
- if (it.startsWith("content") && Build.VERSION.SDK_INT > 19)
- contentResolver.takePersistableUriPermission(
- Uri.parse(it),
- Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
- )
+ contentResolver.takePersistableUriPermission(
+ Uri.parse(it),
+ Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
+ )
if (!FileX(this, it).canWrite())
throw Exception()
diff --git a/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt b/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt
index 661ab11b..0c53f4e7 100644
--- a/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt
+++ b/app/src/main/java/xyz/quaver/pupil/hitomi/common.kt
@@ -20,13 +20,10 @@ import android.webkit.WebView
import android.widget.Toast
import com.google.common.collect.ConcurrentHashMultiset
import com.google.firebase.crashlytics.FirebaseCrashlytics
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.transformWhile
-import kotlinx.coroutines.withContext
-import kotlinx.coroutines.yield
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
@@ -43,16 +40,18 @@ const val protocol = "https:"
val evaluations = Collections.newSetFromMap(ConcurrentHashMap())
suspend fun WebView.evaluate(script: String): String = withContext(Dispatchers.Main) {
- while (webViewFailed || !webViewReady) yield()
+ val result: String = withTimeout(10000) {
+ while (webViewFailed || !webViewReady) yield()
- val uid = UUID.randomUUID().toString()
+ val uid = UUID.randomUUID().toString()
- evaluations.add(uid)
+ evaluations.add(uid)
- val result: String = suspendCoroutine { continuation ->
- evaluateJavascript(script) {
- evaluations.remove(uid)
- continuation.resume(it)
+ suspendCoroutine { continuation ->
+ evaluateJavascript(script) {
+ evaluations.remove(uid)
+ continuation.resume(it)
+ }
}
}
@@ -61,20 +60,22 @@ suspend fun WebView.evaluate(script: String): String = withContext(Dispatchers.M
@OptIn(ExperimentalCoroutinesApi::class)
suspend fun WebView.evaluatePromise(script: String, then: String = ".then(result => Callback.onResult(%uid, JSON.stringify(result))).catch(err => Callback.onError(%uid, JSON.stringify(error)))"): String? = withContext(Dispatchers.Main) {
- while (webViewFailed || !webViewReady) yield()
+ val flow: Flow> = withTimeout(10000) {
+ while (webViewFailed || !webViewReady) yield()
- val uid = UUID.randomUUID().toString()
+ val uid = UUID.randomUUID().toString()
- evaluations.add(uid)
+ evaluations.add(uid)
- evaluateJavascript((script+then).replace("%uid", "'$uid'"), null)
+ evaluateJavascript((script+then).replace("%uid", "'$uid'"), null)
- val flow: Flow> = webViewFlow.transformWhile { (currentUid, result) ->
- if (currentUid == uid) {
- evaluations.remove(uid)
- emit(currentUid to result)
+ webViewFlow.transformWhile { (currentUid, result) ->
+ if (currentUid == uid) {
+ evaluations.remove(uid)
+ emit(currentUid to result)
+ }
+ currentUid != uid
}
- currentUid != uid
}
flow.first().second