fix(library-update-job): Fix disappearing library update job (#1254)
* fix(library-update-job): Fix disappearing library update job * extract to shared utils
This commit is contained in:
parent
98e4c24939
commit
3e55ea8eac
5 changed files with 59 additions and 12 deletions
|
|
@ -23,7 +23,7 @@ import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||||
import eu.kanade.tachiyomi.util.system.isRunning
|
import eu.kanade.tachiyomi.util.system.isRunning
|
||||||
import eu.kanade.tachiyomi.util.system.setForegroundSafely
|
import eu.kanade.tachiyomi.util.system.setForegroundSafely
|
||||||
import eu.kanade.tachiyomi.util.system.workManager
|
import eu.kanade.tachiyomi.util.system.workManager
|
||||||
import kotlinx.coroutines.guava.await
|
import exh.util.WorkerUtil
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
import tachiyomi.domain.backup.service.BackupPreferences
|
import tachiyomi.domain.backup.service.BackupPreferences
|
||||||
|
|
@ -129,19 +129,13 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
||||||
|
|
||||||
// KMK -->
|
// KMK -->
|
||||||
/**
|
/**
|
||||||
* Returns true if a periodic backup job is currently scheduled.
|
* Returns true if a periodic job is currently scheduled.
|
||||||
* @param context The application context.
|
* @param context The application context.
|
||||||
* @return True if a periodic backup job is scheduled, false otherwise.
|
* @return True if a periodic job is scheduled, false otherwise.
|
||||||
* @throws Exception If there is an error retrieving the work info.
|
* @throws Exception If there is an error retrieving the work info.
|
||||||
*/
|
*/
|
||||||
suspend fun isPeriodicBackupScheduled(context: Context): Boolean {
|
suspend fun isPeriodicBackupScheduled(context: Context): Boolean {
|
||||||
val workInfos = context.workManager
|
return WorkerUtil.isPeriodicJobScheduled(context, TAG_AUTO)
|
||||||
.getWorkInfosForUniqueWork(TAG_AUTO)
|
|
||||||
.await()
|
|
||||||
|
|
||||||
return workInfos.any { workInfo ->
|
|
||||||
!workInfo.state.isFinished
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// KMK <--
|
// KMK <--
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ import exh.md.utils.MdUtil
|
||||||
import exh.source.LIBRARY_UPDATE_EXCLUDED_SOURCES
|
import exh.source.LIBRARY_UPDATE_EXCLUDED_SOURCES
|
||||||
import exh.source.MERGED_SOURCE_ID
|
import exh.source.MERGED_SOURCE_ID
|
||||||
import exh.source.mangaDexSourceIds
|
import exh.source.mangaDexSourceIds
|
||||||
|
import exh.util.WorkerUtil
|
||||||
import exh.util.nullIfBlank
|
import exh.util.nullIfBlank
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
|
@ -889,5 +890,17 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
/**
|
||||||
|
* Returns true if a periodic job is currently scheduled.
|
||||||
|
* @param context The application context.
|
||||||
|
* @return True if a periodic job is scheduled, false otherwise.
|
||||||
|
* @throws Exception If there is an error retrieving the work info.
|
||||||
|
*/
|
||||||
|
suspend fun isPeriodicUpdateScheduled(context: Context): Boolean {
|
||||||
|
return WorkerUtil.isPeriodicJobScheduled(context, WORK_NAME_AUTO)
|
||||||
|
}
|
||||||
|
// KMK <--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||||
import eu.kanade.tachiyomi.data.coil.MangaCoverMetadata
|
import eu.kanade.tachiyomi.data.coil.MangaCoverMetadata
|
||||||
import eu.kanade.tachiyomi.data.connections.discord.DiscordRPCService
|
import eu.kanade.tachiyomi.data.connections.discord.DiscordRPCService
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadCache
|
import eu.kanade.tachiyomi.data.download.DownloadCache
|
||||||
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.updater.AppUpdateChecker
|
import eu.kanade.tachiyomi.data.updater.AppUpdateChecker
|
||||||
import eu.kanade.tachiyomi.data.updater.AppUpdateJob
|
import eu.kanade.tachiyomi.data.updater.AppUpdateJob
|
||||||
|
|
@ -510,6 +511,20 @@ class MainActivity : BaseActivity() {
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
launchIO {
|
launchIO {
|
||||||
|
try {
|
||||||
|
if (!LibraryUpdateJob.isPeriodicUpdateScheduled(context)) {
|
||||||
|
LibraryUpdateJob.setupTask(context)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR, e)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
stringResource(KMR.strings.job_failed_schedule_update_check, stringResource(MR.strings.unknown_error)),
|
||||||
|
Toast.LENGTH_LONG,
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (!BackupCreateJob.isPeriodicBackupScheduled(context)) {
|
if (!BackupCreateJob.isPeriodicBackupScheduled(context)) {
|
||||||
BackupCreateJob.setupTask(context)
|
BackupCreateJob.setupTask(context)
|
||||||
|
|
@ -519,7 +534,7 @@ class MainActivity : BaseActivity() {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
stringResource(KMR.strings.job_failed_schedule_update_check, stringResource(MR.strings.unknown_error)),
|
stringResource(KMR.strings.job_failed_schedule_backup_check, stringResource(MR.strings.unknown_error)),
|
||||||
Toast.LENGTH_LONG,
|
Toast.LENGTH_LONG,
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
app/src/main/java/exh/util/WorkerUtil.kt
Normal file
24
app/src/main/java/exh/util/WorkerUtil.kt
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
package exh.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import eu.kanade.tachiyomi.util.system.workManager
|
||||||
|
import kotlinx.coroutines.guava.await
|
||||||
|
|
||||||
|
object WorkerUtil {
|
||||||
|
/**
|
||||||
|
* Returns true if a periodic job is currently scheduled.
|
||||||
|
* @param context The application context.
|
||||||
|
* @param uniqueWorkName The unique work tag to check for scheduled jobs.
|
||||||
|
* @return True if a periodic job is scheduled, false otherwise.
|
||||||
|
* @throws Exception If there is an error retrieving the work info.
|
||||||
|
*/
|
||||||
|
suspend fun isPeriodicJobScheduled(context: Context, uniqueWorkName: String): Boolean {
|
||||||
|
val workInfos = context.workManager
|
||||||
|
.getWorkInfosForUniqueWork(uniqueWorkName)
|
||||||
|
.await()
|
||||||
|
|
||||||
|
return workInfos.any { workInfo ->
|
||||||
|
!workInfo.state.isFinished
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -173,7 +173,8 @@
|
||||||
<string name="current_">Current: %1$s</string>
|
<string name="current_">Current: %1$s</string>
|
||||||
<string name="migrating_all_entries">Migrating all entries from source</string>
|
<string name="migrating_all_entries">Migrating all entries from source</string>
|
||||||
<!-- Misc -->
|
<!-- Misc -->
|
||||||
<string name="job_failed_schedule_update_check">Failed to schedule automatic backup: %s</string>
|
<string name="job_failed_schedule_update_check">Failed to schedule automatic library update: %s</string>
|
||||||
|
<string name="job_failed_schedule_backup_check">Failed to schedule automatic backup: %s</string>
|
||||||
<string name="label_to_be_updated">To be updated</string>
|
<string name="label_to_be_updated">To be updated</string>
|
||||||
<string name="sponsor_me">Sponsor Me</string>
|
<string name="sponsor_me">Sponsor Me</string>
|
||||||
<string name="batch_add_description">Support: MangaDex, E-H, ExH, nH, 8Muses, Tsumino</string>
|
<string name="batch_add_description">Support: MangaDex, E-H, ExH, nH, 8Muses, Tsumino</string>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue