Perform metadata update in global scope
(cherry picked from commit e4dc35674d680b10df2f059a5a51b01f892f9861)
This commit is contained in:
parent
bf7af0c099
commit
6fdff1b03b
@ -48,11 +48,14 @@ import exh.source.mangaDexSourceIds
|
|||||||
import exh.util.executeOnIO
|
import exh.util.executeOnIO
|
||||||
import exh.util.nullIfBlank
|
import exh.util.nullIfBlank
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.supervisorScope
|
import kotlinx.coroutines.supervisorScope
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
@ -79,7 +82,7 @@ class LibraryUpdateService(
|
|||||||
|
|
||||||
private lateinit var wakeLock: PowerManager.WakeLock
|
private lateinit var wakeLock: PowerManager.WakeLock
|
||||||
private lateinit var notifier: LibraryUpdateNotifier
|
private lateinit var notifier: LibraryUpdateNotifier
|
||||||
private lateinit var scope: CoroutineScope
|
private lateinit var ioScope: CoroutineScope
|
||||||
|
|
||||||
private var updateJob: Job? = null
|
private var updateJob: Job? = null
|
||||||
|
|
||||||
@ -174,7 +177,7 @@ class LibraryUpdateService(
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
scope = MainScope()
|
ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
notifier = LibraryUpdateNotifier(this)
|
notifier = LibraryUpdateNotifier(this)
|
||||||
wakeLock = acquireWakeLock(javaClass.name)
|
wakeLock = acquireWakeLock(javaClass.name)
|
||||||
|
|
||||||
@ -186,7 +189,7 @@ class LibraryUpdateService(
|
|||||||
* lock.
|
* lock.
|
||||||
*/
|
*/
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
scope?.cancel()
|
ioScope?.cancel()
|
||||||
updateJob?.cancel()
|
updateJob?.cancel()
|
||||||
if (wakeLock.isHeld) {
|
if (wakeLock.isHeld) {
|
||||||
wakeLock.release()
|
wakeLock.release()
|
||||||
@ -222,7 +225,7 @@ class LibraryUpdateService(
|
|||||||
val mangaList = getMangaToUpdate(intent, target)
|
val mangaList = getMangaToUpdate(intent, target)
|
||||||
.sortedWith(rankingScheme[selectedScheme])
|
.sortedWith(rankingScheme[selectedScheme])
|
||||||
|
|
||||||
updateJob = scope.launchIO {
|
updateJob = ioScope.launch {
|
||||||
try {
|
try {
|
||||||
when (target) {
|
when (target) {
|
||||||
Target.CHAPTERS -> updateChapterList(mangaList)
|
Target.CHAPTERS -> updateChapterList(mangaList)
|
||||||
@ -415,6 +418,7 @@ class LibraryUpdateService(
|
|||||||
|
|
||||||
// Update manga details metadata in the background
|
// Update manga details metadata in the background
|
||||||
if (preferences.autoUpdateMetadata()) {
|
if (preferences.autoUpdateMetadata()) {
|
||||||
|
GlobalScope.launchIO {
|
||||||
val updatedManga = source.getMangaDetails(manga.toMangaInfo())
|
val updatedManga = source.getMangaDetails(manga.toMangaInfo())
|
||||||
val sManga = updatedManga.toSManga()
|
val sManga = updatedManga.toSManga()
|
||||||
// Avoid "losing" existing cover
|
// Avoid "losing" existing cover
|
||||||
@ -427,6 +431,7 @@ class LibraryUpdateService(
|
|||||||
manga.copyFrom(sManga)
|
manga.copyFrom(sManga)
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scope.launchIO {
|
scope.launchIO {
|
||||||
if (source is MangaDex && trackManager.mdList.isLogged) {
|
if (source is MangaDex && trackManager.mdList.isLogged) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user