Pupil-78 Shorten the timout when hiyobi is down

This commit is contained in:
tom5079
2020-06-20 13:08:03 +09:00
parent 01a01d481d
commit 349da7aa81

View File

@@ -39,6 +39,7 @@ import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.InputStream import java.io.InputStream
import java.net.URL import java.net.URL
import java.util.*
import java.util.concurrent.locks.Lock import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
@@ -166,8 +167,8 @@ class Cache(context: Context) : ContextWrapper(context) {
val mirrors = preference.getString("mirrors", null)?.split('>') ?: listOf() val mirrors = preference.getString("mirrors", null)?.split('>') ?: listOf()
val sources = mapOf( val sources = mapOf(
Code.HITOMI to { xyz.quaver.hitomi.getReader(galleryID) }, Code.HITOMI to { Log.i("PUPILD", "READER - HITOMI"); xyz.quaver.hitomi.getReader(galleryID) },
Code.HIYOBI to { xyz.quaver.hiyobi.getReader(galleryID) } Code.HIYOBI to { Log.i("PUPILD", "READER - HIYOBI"); xyz.quaver.hiyobi.getReader(galleryID) }
).let { ).let {
if (mirrors.isNotEmpty()) if (mirrors.isNotEmpty())
it.toSortedMap( it.toSortedMap(
@@ -180,23 +181,25 @@ class Cache(context: Context) : ContextWrapper(context) {
} }
val reader = if (metadata?.reader == null) { val reader = if (metadata?.reader == null) {
CoroutineScope(Dispatchers.IO).async { var retval: Reader? = null
var retval: Reader? = null
for (source in sources) { for (source in sources) {
retval = try { retval = try {
source.value.invoke() withContext(Dispatchers.IO) {
} catch (e: Exception) { withTimeoutOrNull(1000) {
FirebaseCrashlytics.getInstance().recordException(e) source.value.invoke()
null }
} }
} catch (e: Exception) {
if (retval != null) FirebaseCrashlytics.getInstance().recordException(e)
break null
} }
retval if (retval != null)
}.await() ?: return null break
}
retval
} else } else
metadata.reader metadata.reader