mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-19 17:49:44 +02:00
Remove tmp chapter files after exiting reader
This commit is contained in:
@@ -27,6 +27,7 @@ import nl.adaptivity.xmlutil.XmlDeclMode
|
||||
import nl.adaptivity.xmlutil.core.XmlVersion
|
||||
import nl.adaptivity.xmlutil.serialization.XML
|
||||
import tachiyomi.core.storage.AndroidStorageFolderProvider
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.data.AndroidDatabaseHandler
|
||||
import tachiyomi.data.Database
|
||||
import tachiyomi.data.DatabaseHandler
|
||||
@@ -111,6 +112,8 @@ class AppModule(val app: Application) : InjektModule {
|
||||
ProtoBuf
|
||||
}
|
||||
|
||||
addSingletonFactory { UniFileTempFileManager(app) }
|
||||
|
||||
addSingletonFactory { ChapterCache(app, get()) }
|
||||
addSingletonFactory { CoverCache(app) }
|
||||
|
||||
|
@@ -55,6 +55,7 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.preference.toggle
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.core.util.lang.launchIO
|
||||
import tachiyomi.core.util.lang.launchNonCancellable
|
||||
import tachiyomi.core.util.lang.withIOContext
|
||||
@@ -85,6 +86,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val downloadManager: DownloadManager = Injekt.get(),
|
||||
private val downloadProvider: DownloadProvider = Injekt.get(),
|
||||
private val tempFileManager: UniFileTempFileManager = Injekt.get(),
|
||||
private val imageSaver: ImageSaver = Injekt.get(),
|
||||
preferences: BasePreferences = Injekt.get(),
|
||||
val readerPreferences: ReaderPreferences = Injekt.get(),
|
||||
@@ -269,7 +271,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
|
||||
val context = Injekt.get<Application>()
|
||||
val source = sourceManager.getOrStub(manga.source)
|
||||
loader = ChapterLoader(context, downloadManager, downloadProvider, manga, source)
|
||||
loader = ChapterLoader(context, downloadManager, downloadProvider, tempFileManager, manga, source)
|
||||
|
||||
loadChapter(loader!!, chapterList.first { chapterId == it.chapter.id })
|
||||
Result.success(true)
|
||||
@@ -904,6 +906,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
private fun deletePendingChapters() {
|
||||
viewModelScope.launchNonCancellable {
|
||||
downloadManager.deletePendingChapters()
|
||||
tempFileManager.deleteTempFiles()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import tachiyomi.core.i18n.stringResource
|
||||
import tachiyomi.core.storage.toTempFile
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.core.util.lang.withIOContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
@@ -24,6 +24,7 @@ class ChapterLoader(
|
||||
private val context: Context,
|
||||
private val downloadManager: DownloadManager,
|
||||
private val downloadProvider: DownloadProvider,
|
||||
private val tempFileManager: UniFileTempFileManager,
|
||||
private val manga: Manga,
|
||||
private val source: Source,
|
||||
) {
|
||||
@@ -85,17 +86,24 @@ class ChapterLoader(
|
||||
skipCache = true,
|
||||
)
|
||||
return when {
|
||||
isDownloaded -> DownloadPageLoader(chapter, manga, source, downloadManager, downloadProvider)
|
||||
isDownloaded -> DownloadPageLoader(
|
||||
chapter,
|
||||
manga,
|
||||
source,
|
||||
downloadManager,
|
||||
downloadProvider,
|
||||
tempFileManager,
|
||||
)
|
||||
source is LocalSource -> source.getFormat(chapter.chapter).let { format ->
|
||||
when (format) {
|
||||
is Format.Directory -> DirectoryPageLoader(format.file)
|
||||
is Format.Zip -> ZipPageLoader(format.file.toTempFile(context))
|
||||
is Format.Zip -> ZipPageLoader(tempFileManager.createTempFile(format.file))
|
||||
is Format.Rar -> try {
|
||||
RarPageLoader(format.file.toTempFile(context))
|
||||
RarPageLoader(tempFileManager.createTempFile(format.file))
|
||||
} catch (e: UnsupportedRarV5Exception) {
|
||||
error(context.stringResource(MR.strings.loader_rar5_error))
|
||||
}
|
||||
is Format.Epub -> EpubPageLoader(format.file.toTempFile(context))
|
||||
is Format.Epub -> EpubPageLoader(tempFileManager.createTempFile(format.file))
|
||||
}
|
||||
}
|
||||
source is HttpSource -> HttpPageLoader(chapter, source)
|
||||
|
@@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import tachiyomi.core.storage.toTempFile
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
@@ -23,6 +23,7 @@ internal class DownloadPageLoader(
|
||||
private val source: Source,
|
||||
private val downloadManager: DownloadManager,
|
||||
private val downloadProvider: DownloadProvider,
|
||||
private val tempFileManager: UniFileTempFileManager,
|
||||
) : PageLoader() {
|
||||
|
||||
private val context: Application by injectLazy()
|
||||
@@ -46,8 +47,8 @@ internal class DownloadPageLoader(
|
||||
zipPageLoader?.recycle()
|
||||
}
|
||||
|
||||
private suspend fun getPagesFromArchive(chapterPath: UniFile): List<ReaderPage> {
|
||||
val loader = ZipPageLoader(chapterPath.toTempFile(context)).also { zipPageLoader = it }
|
||||
private suspend fun getPagesFromArchive(file: UniFile): List<ReaderPage> {
|
||||
val loader = ZipPageLoader(tempFileManager.createTempFile(file)).also { zipPageLoader = it }
|
||||
return loader.getPages()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user