Compare commits

..

3 Commits

Author SHA1 Message Date
tom5079
dfb60461e4 Merge remote-tracking branch 'origin/master' 2022-01-05 20:20:08 +09:00
tom5079
bd6bc418e6 5.2.8-BETA01 potential fix for loading not finishing 2022-01-05 20:19:00 +09:00
tom5079
a284143ce1 Update README.md 2022-01-04 23:18:16 +09:00
6 changed files with 31 additions and 31 deletions

View File

@@ -7,11 +7,11 @@
<deviceKey> <deviceKey>
<Key> <Key>
<type value="VIRTUAL_DEVICE_PATH" /> <type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_2_API_31.avd" /> <value value="$USER_HOME$/.android/avd/Pixel_2_API_30.avd" />
</Key> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</targetSelectedWithDropDown> </targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-01-04T14:06:06.261345Z" /> <timeTargetWasSelectedWithDropDown value="2022-01-04T14:31:24.587053Z" />
</component> </component>
</project> </project>

View File

@@ -2,7 +2,7 @@
*Pupil, Hitomi.la viewer for Android* *Pupil, Hitomi.la viewer for Android*
![](https://img.shields.io/github/downloads/tom5079/Pupil/total) ![](https://img.shields.io/github/downloads/tom5079/Pupil/total)
[![](https://img.shields.io/github/downloads/tom5079/Pupil/5.2.6/Pupil-v5.2.6.apk?color=%234fc3f7&label=DOWNLOAD%20APP&style=for-the-badge)](https://github.com/tom5079/Pupil/releases/download/5.2.6/Pupil-v5.2.6.apk) [![](https://img.shields.io/github/downloads/tom5079/Pupil/5.2.7/Pupil-v5.2.7.apk?color=%234fc3f7&label=DOWNLOAD%20APP&style=for-the-badge)](https://github.com/tom5079/Pupil/releases/download/5.2.7/Pupil-v5.2.7.apk)
[![](https://discordapp.com/api/guilds/610452916612104194/embed.png?style=banner2)](https://discord.gg/Stj4b5v) [![](https://discordapp.com/api/guilds/610452916612104194/embed.png?style=banner2)](https://discord.gg/Stj4b5v)
# Features # Features

View File

@@ -38,7 +38,7 @@ android {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 31 targetSdkVersion 31
versionCode 69 versionCode 69
versionName "5.2.6" versionName "5.2.8-BETA01"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }

View File

@@ -12,7 +12,7 @@
"filters": [], "filters": [],
"attributes": [], "attributes": [],
"versionCode": 69, "versionCode": 69,
"versionName": "5.2.6", "versionName": "5.2.8-BETA01",
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }
], ],

View File

@@ -166,7 +166,7 @@ class Pupil : Application() {
instance = this instance = this
isDebugBuild = applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 isDebugBuild = applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
WebView.setWebContentsDebuggingEnabled(true) if (isDebugBuild) WebView.setWebContentsDebuggingEnabled(true)
webView = WebView(this).apply { webView = WebView(this).apply {
with (settings) { with (settings) {
@@ -257,11 +257,10 @@ class Pupil : Application() {
try { try {
Preferences.get<String>("download_folder").also { Preferences.get<String>("download_folder").also {
if (it.startsWith("content") && Build.VERSION.SDK_INT > 19) contentResolver.takePersistableUriPermission(
contentResolver.takePersistableUriPermission( Uri.parse(it),
Uri.parse(it), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION )
)
if (!FileX(this, it).canWrite()) if (!FileX(this, it).canWrite())
throw Exception() throw Exception()

View File

@@ -20,13 +20,10 @@ import android.webkit.WebView
import android.widget.Toast import android.widget.Toast
import com.google.common.collect.ConcurrentHashMultiset import com.google.common.collect.ConcurrentHashMultiset
import com.google.firebase.crashlytics.FirebaseCrashlytics import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.transformWhile import kotlinx.coroutines.flow.transformWhile
import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield
import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
@@ -43,16 +40,18 @@ const val protocol = "https:"
val evaluations = Collections.newSetFromMap<String>(ConcurrentHashMap()) val evaluations = Collections.newSetFromMap<String>(ConcurrentHashMap())
suspend fun WebView.evaluate(script: String): String = withContext(Dispatchers.Main) { 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 -> suspendCoroutine { continuation ->
evaluateJavascript(script) { evaluateJavascript(script) {
evaluations.remove(uid) evaluations.remove(uid)
continuation.resume(it) continuation.resume(it)
}
} }
} }
@@ -61,20 +60,22 @@ suspend fun WebView.evaluate(script: String): String = withContext(Dispatchers.M
@OptIn(ExperimentalCoroutinesApi::class) @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) { 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<Pair<String, String?>> = 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<Pair<String, String?>> = webViewFlow.transformWhile { (currentUid, result) -> webViewFlow.transformWhile { (currentUid, result) ->
if (currentUid == uid) { if (currentUid == uid) {
evaluations.remove(uid) evaluations.remove(uid)
emit(currentUid to result) emit(currentUid to result)
}
currentUid != uid
} }
currentUid != uid
} }
flow.first().second flow.first().second