Fix crash of metadata not available

This commit is contained in:
tarsin committed 2023-02-17 18:02:32 +08:00
1 parent d7438a26fb
commit 67a0893a97
5 files changed
+20 -24

No files matched your search

@@ -46,9 +46,7 @@ import java.util.Set;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicInteger;
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
@@ -191,11 +189,11 @@ public class ArchivePageLoader extends PageLoader2 {
}
private Continuation<? super Unit> continuation = null;
private Continuation<? super Boolean> continuation = null;
@Nullable
@Override
public Object awaitReady(@NonNull Continuation<? super Unit> $completion) {
public Object awaitReady(@NonNull Continuation<? super Boolean> $completion) {
continuation = $completion;
return CoroutineSingletons.COROUTINE_SUSPENDED;
}
@@ -97,8 +97,8 @@ class EhPageLoader(private val mGalleryInfo: GalleryInfo) : PageLoader2(), OnSpi
mSpiderQueen.forceRequest(index)
}
override suspend fun awaitReady() {
mSpiderQueen.awaitReady()
override suspend fun awaitReady(): Boolean {
return mSpiderQueen.awaitReady()
}
override fun onCancelRequest(index: Int) {
@@ -212,10 +212,6 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
MODE_DOWNLOAD -> mDownloadReference++
}
check(mDownloadReference <= 1) { "mDownloadReference can't more than 0" }
launchIO {
prepareJob.join()
updateMode()
}
}
private fun clearMode(@Mode mode: Int) {
@@ -224,10 +220,6 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
MODE_DOWNLOAD -> mDownloadReference--
}
check(!(mReadReference < 0 || mDownloadReference < 0)) { "Mode reference < 0" }
launchIO {
prepareJob.join()
updateMode()
}
}
private val prepareJob = launchIO { doPrepare() }
@@ -436,6 +428,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
@Synchronized
private fun writeSpiderInfoToLocal() {
if (!isReady) return
mSpiderDen.downloadDir?.run { createFile(SPIDER_INFO_FILENAME).also { mSpiderInfo.write(it) } }
mSpiderInfo.saveToCache()
}
@@ -513,17 +506,23 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
@JvmStatic
fun obtainSpiderQueen(galleryInfo: GalleryInfo, @Mode mode: Int): SpiderQueen {
return sQueenMap[galleryInfo.gid]?.apply { setMode(mode) }
?: SpiderQueen(galleryInfo).apply { setMode(mode) }
.also { sQueenMap[galleryInfo.gid] = it }
val gid = galleryInfo.gid
return (sQueenMap[gid] ?: SpiderQueen(galleryInfo).also { sQueenMap[gid] = it }).apply {
setMode(mode)
launchIO { if (awaitReady()) updateMode() }
}
}
@JvmStatic
fun releaseSpiderQueen(queen: SpiderQueen, @Mode mode: Int) {
queen.clearMode(mode)
if (queen.mReadReference == 0 && queen.mDownloadReference == 0) {
queen.stop()
sQueenMap.remove(queen.galleryInfo.gid)
queen.run {
clearMode(mode)
if (mReadReference == 0 && mDownloadReference == 0) {
stop()
sQueenMap.remove(galleryInfo.gid)
} else {
launchIO { if (awaitReady()) updateMode() }
}
}
}
}
@@ -271,8 +271,7 @@ class ReaderActivity : EhActivity() {
mGalleryProvider!!.start()
lifecycleScope.launchUI {
mGalleryProvider!!.awaitReady()
setGallery()
if (mGalleryProvider!!.awaitReady()) setGallery()
}
config = ReaderConfig()
@@ -18,7 +18,7 @@ abstract class PageLoader {
private val mPreloads = MathUtils.clamp(com.hippo.ehviewer.Settings.getPreloadImage(), 0, 100)
abstract suspend fun awaitReady()
abstract suspend fun awaitReady(): Boolean
abstract fun start()