Make sure to always send finished chapter downloads with the download status (#782)

Due to not immediately sending the status, the finished chapters were already removed from the queue by the time the status was actually send to the client.
This caused the client to never receive a status with the chapters downloaded flag to be true, resulting in the client to not know that a chapter is downloaded
This commit is contained in:
schroda
2023-12-09 01:16:52 +01:00
committed by GitHub
parent 9b27d7ee23
commit df57070b70

View File

@@ -119,14 +119,15 @@ object DownloadManager {
private val notifyFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
private val statusFlow = MutableSharedFlow<Unit>()
val status =
notifyFlow.sample(1.seconds)
.onStart { emit(Unit) }
statusFlow.onStart { emit(Unit) }
.map { getStatus() }
init {
scope.launch {
notifyFlow.sample(1.seconds).collect {
statusFlow.emit(Unit)
sendStatusToAllClients()
}
}
@@ -148,6 +149,10 @@ object DownloadManager {
private fun notifyAllClients(immediate: Boolean = false) {
scope.launch {
notifyFlow.emit(Unit)
if (immediate) {
statusFlow.emit(Unit)
}
}
if (immediate) {
sendStatusToAllClients()