Improved search speed

This commit is contained in:
tom5079
2022-01-09 00:34:29 +09:00
parent 0fd2cf4fd7
commit 0902fdf981
9 changed files with 76 additions and 43 deletions

View File

@@ -77,8 +77,6 @@ suspend fun WebView.evaluatePromise(
val uid = UUID.randomUUID().toString()
evaluateJavascript((script + then).replace("%uid", "'$uid'"), null)
val flow: Flow<Pair<String, String?>> = webViewFlow.transformWhile { (currentUid, result) ->
if (currentUid == uid) {
emit(currentUid to result)
@@ -86,6 +84,10 @@ suspend fun WebView.evaluatePromise(
currentUid != uid
}
launch {
evaluateJavascript((script + then).replace("%uid", "'$uid'"), null)
}
flow.first().second
}
} catch (e: CancellationException) {
@@ -100,7 +102,7 @@ suspend fun WebView.evaluatePromise(
suspend fun getGalleryInfo(galleryID: Int): GalleryInfo {
val result = webView.evaluatePromise("get_gallery_info($galleryID)")
return json.decodeFromString(result!!)
return json.decodeFromString(result)
}
//common.js