浏览代码

Fix download cache not updating on location change

arkon 2 年之前
父节点
当前提交
6756bfab75
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt

+ 8 - 1
app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt

@@ -7,6 +7,8 @@ import eu.kanade.domain.download.service.DownloadPreferences
 import eu.kanade.domain.manga.model.Manga
 import eu.kanade.tachiyomi.data.database.models.Chapter
 import eu.kanade.tachiyomi.source.SourceManager
+import kotlinx.coroutines.MainScope
+import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.onEach
 import uy.kohesive.injekt.Injekt
 import uy.kohesive.injekt.api.get
@@ -30,6 +32,8 @@ class DownloadCache(
     private val downloadPreferences: DownloadPreferences = Injekt.get(),
 ) {
 
+    private val scope = MainScope()
+
     /**
      * The interval after which this cache should be invalidated. 1 hour shouldn't cause major
      * issues, as the cache is only used for UI feedback.
@@ -49,6 +53,7 @@ class DownloadCache(
                 lastRenew = 0L // invalidate cache
                 rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
             }
+            .launchIn(scope)
     }
 
     /**
@@ -210,7 +215,9 @@ class DownloadCache(
             .orEmpty()
             .associate { it.name to SourceDirectory(it) }
             .mapNotNullKeys { entry ->
-                sources.find { provider.getSourceDirName(it).equals(entry.key, ignoreCase = true) }?.id
+                sources.find {
+                    provider.getSourceDirName(it).equals(entry.key, ignoreCase = true)
+                }?.id
             }
 
         rootDownloadsDir.files = sourceDirs