5.1.12 Improved suggestion loading speed / Fixed images not loading

This commit is contained in:
tom5079
2022-01-11 17:11:59 +09:00
parent 152d4e248f
commit 1833c0bde5
7 changed files with 28 additions and 14 deletions

View File

@@ -93,7 +93,7 @@ fun reloadWebView() {
webViewReady = false
webViewFailed = false
evaluationContext.cancelChildren()
evaluationContext.cancelChildren(CancellationException("reload"))
runCatching {
URL(

View File

@@ -56,7 +56,7 @@ suspend fun WebView.evaluate(script: String): String = coroutineScope {
}
} catch (e: CancellationException) {
continue
if (e.message != "reload") result = "null"
}
}
@@ -91,7 +91,7 @@ suspend fun WebView.evaluatePromise(
flow.first().second
}
} catch (e: CancellationException) {
continue
if (e.message != "reload") result = "null"
}
}

View File

@@ -16,8 +16,8 @@
package xyz.quaver.pupil.hitomi
import android.util.Log
import kotlinx.coroutines.*
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import java.util.*
suspend fun doSearch(query: String, sortByPopularity: Boolean = false) : Set<Int> = coroutineScope {

View File

@@ -16,6 +16,7 @@
package xyz.quaver.pupil.hitomi
import android.util.Log
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
@@ -37,9 +38,22 @@ data class Suggestion(val s: String, val t: Int, val u: String, val n: String)
@OptIn(ExperimentalSerializationApi::class)
suspend fun getSuggestionsForQuery(query: String) : List<Suggestion> {
val result = webView.evaluatePromise("get_suggestions_for_query('$query')")
val result = webView.evaluatePromise(
"get_suggestions_for_query('$query', ++search_serial)",
then = """
.then(r => {
let [results, results_serial] = r;
console.log(results_serial, r, search_serial);
if (search_serial !== results_serial) {
Callback.onResult(%uid, '[]');
} else {
Callback.onResult(%uid, JSON.stringify(results));
}
});
""".trimIndent()
)
return Json.decodeFromString<List<List<Suggestion>?>>(result)[0] ?: return emptyList()
return Json.decodeFromString(result) ?: return emptyList()
}
@OptIn(ExperimentalSerializationApi::class)