Remove background app update check
We already check in the foreground. If the app isn't being foregrounded at all, then there isn't much point in checking for an update. (cherry picked from commit 42954609b94e13d8fadbf1f3769e9f32fa9e8447) # Conflicts: # app/build.gradle.kts # app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateJob.kt
This commit is contained in:
parent
8fc9e77b77
commit
a275a102e9
@ -1,9 +1,9 @@
|
|||||||
package eu.kanade.tachiyomi
|
package eu.kanade.tachiyomi
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import androidx.work.WorkManager
|
||||||
import eu.kanade.domain.backup.service.BackupPreferences
|
import eu.kanade.domain.backup.service.BackupPreferences
|
||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
import eu.kanade.domain.library.service.LibraryPreferences
|
import eu.kanade.domain.library.service.LibraryPreferences
|
||||||
@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
|||||||
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
|
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
||||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||||
import eu.kanade.tachiyomi.data.updater.AppUpdateJob
|
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
||||||
import eu.kanade.tachiyomi.network.NetworkPreferences
|
import eu.kanade.tachiyomi.network.NetworkPreferences
|
||||||
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
|
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
|
||||||
@ -58,9 +57,6 @@ object Migrations {
|
|||||||
lastVersionCode.set(BuildConfig.VERSION_CODE)
|
lastVersionCode.set(BuildConfig.VERSION_CODE)
|
||||||
|
|
||||||
// Always set up background tasks to ensure they're running
|
// Always set up background tasks to ensure they're running
|
||||||
if (BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
AppUpdateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
ExtensionUpdateJob.setupTask(context)
|
ExtensionUpdateJob.setupTask(context)
|
||||||
LibraryUpdateJob.setupTask(context)
|
LibraryUpdateJob.setupTask(context)
|
||||||
BackupCreatorJob.setupTask(context)
|
BackupCreatorJob.setupTask(context)
|
||||||
@ -74,9 +70,6 @@ object Migrations {
|
|||||||
|
|
||||||
if (oldVersion < 14) {
|
if (oldVersion < 14) {
|
||||||
// Restore jobs after upgrading to Evernote's job scheduler.
|
// Restore jobs after upgrading to Evernote's job scheduler.
|
||||||
if (BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
AppUpdateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
LibraryUpdateJob.setupTask(context)
|
LibraryUpdateJob.setupTask(context)
|
||||||
}
|
}
|
||||||
if (oldVersion < 15) {
|
if (oldVersion < 15) {
|
||||||
@ -107,9 +100,6 @@ object Migrations {
|
|||||||
}
|
}
|
||||||
if (oldVersion < 43) {
|
if (oldVersion < 43) {
|
||||||
// Restore jobs after migrating from Evernote's job scheduler to WorkManager.
|
// Restore jobs after migrating from Evernote's job scheduler to WorkManager.
|
||||||
if (BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
AppUpdateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
LibraryUpdateJob.setupTask(context)
|
LibraryUpdateJob.setupTask(context)
|
||||||
BackupCreatorJob.setupTask(context)
|
BackupCreatorJob.setupTask(context)
|
||||||
|
|
||||||
@ -174,18 +164,8 @@ object Migrations {
|
|||||||
putInt("pref_rotation_type_key", 1)
|
putInt("pref_rotation_type_key", 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable update check for Android 5.x users
|
|
||||||
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
|
|
||||||
AppUpdateJob.cancelTask(context)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (oldVersion < 60) {
|
if (oldVersion < 60) {
|
||||||
// Re-enable update check that was previously accidentally disabled for M
|
|
||||||
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
|
||||||
AppUpdateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate Rotation and Viewer values to default values for viewer_flags
|
// Migrate Rotation and Viewer values to default values for viewer_flags
|
||||||
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
|
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
|
||||||
1 -> OrientationType.FREE.flagValue
|
1 -> OrientationType.FREE.flagValue
|
||||||
@ -355,6 +335,9 @@ object Migrations {
|
|||||||
LibraryUpdateJob.cancelAllWorks(context)
|
LibraryUpdateJob.cancelAllWorks(context)
|
||||||
LibraryUpdateJob.setupTask(context)
|
LibraryUpdateJob.setupTask(context)
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 97) {
|
||||||
|
WorkManager.getInstance(context).cancelAllWorkByTag("UpdateChecker")
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import tachiyomi.core.preference.PreferenceStore
|
|||||||
import tachiyomi.core.util.lang.withIOContext
|
import tachiyomi.core.util.lang.withIOContext
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.concurrent.TimeUnit
|
import kotlin.time.Duration.Companion.days
|
||||||
|
|
||||||
class AppUpdateChecker {
|
class AppUpdateChecker {
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ class AppUpdateChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult {
|
suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult {
|
||||||
// Limit checks to once a day at most
|
// Limit checks to once every 3 days at most
|
||||||
if (isUserPrompt.not() && Date().time < lastAppCheck.get() + TimeUnit.DAYS.toMillis(1)) {
|
if (isUserPrompt.not() && Date().time < lastAppCheck.get() + 3.days.inWholeMilliseconds) {
|
||||||
return AppUpdateResult.NoNewUpdate
|
return AppUpdateResult.NoNewUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.data.updater
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.work.Constraints
|
|
||||||
import androidx.work.CoroutineWorker
|
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
|
||||||
import androidx.work.NetworkType
|
|
||||||
import androidx.work.PeriodicWorkRequestBuilder
|
|
||||||
import androidx.work.WorkManager
|
|
||||||
import androidx.work.WorkerParameters
|
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import logcat.LogPriority
|
|
||||||
import tachiyomi.core.util.system.logcat
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class AppUpdateJob(private val context: Context, workerParams: WorkerParameters) :
|
|
||||||
CoroutineWorker(context, workerParams) {
|
|
||||||
|
|
||||||
override suspend fun doWork() = coroutineScope {
|
|
||||||
try {
|
|
||||||
AppUpdateChecker().checkForUpdate(context)
|
|
||||||
Result.success()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logcat(LogPriority.ERROR, e)
|
|
||||||
Result.failure()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "UpdateChecker"
|
|
||||||
|
|
||||||
fun setupTask(context: Context) {
|
|
||||||
// Never check for updates in builds that don't include the updater
|
|
||||||
if (!BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
cancelTask(context)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val constraints = Constraints(
|
|
||||||
requiredNetworkType = NetworkType.CONNECTED,
|
|
||||||
)
|
|
||||||
|
|
||||||
val request = PeriodicWorkRequestBuilder<AppUpdateJob>(
|
|
||||||
7,
|
|
||||||
TimeUnit.DAYS,
|
|
||||||
3,
|
|
||||||
TimeUnit.HOURS,
|
|
||||||
)
|
|
||||||
.addTag(TAG)
|
|
||||||
.setConstraints(constraints)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.UPDATE, request)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancelTask(context: Context) {
|
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ package exh
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import androidx.work.WorkManager
|
||||||
import eu.kanade.domain.backup.service.BackupPreferences
|
import eu.kanade.domain.backup.service.BackupPreferences
|
||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
import eu.kanade.domain.chapter.interactor.DeleteChapters
|
import eu.kanade.domain.chapter.interactor.DeleteChapters
|
||||||
@ -109,9 +110,6 @@ object EXHMigrations {
|
|||||||
if (oldVersion < BuildConfig.VERSION_CODE) {
|
if (oldVersion < BuildConfig.VERSION_CODE) {
|
||||||
lastVersionCode.set(BuildConfig.VERSION_CODE)
|
lastVersionCode.set(BuildConfig.VERSION_CODE)
|
||||||
|
|
||||||
if (BuildConfig.INCLUDE_UPDATER) {
|
|
||||||
AppUpdateJob.setupTask(context)
|
|
||||||
}
|
|
||||||
ExtensionUpdateJob.setupTask(context)
|
ExtensionUpdateJob.setupTask(context)
|
||||||
LibraryUpdateJob.setupTask(context)
|
LibraryUpdateJob.setupTask(context)
|
||||||
BackupCreatorJob.setupTask(context)
|
BackupCreatorJob.setupTask(context)
|
||||||
@ -518,6 +516,7 @@ object EXHMigrations {
|
|||||||
if (oldVersion under 48) {
|
if (oldVersion under 48) {
|
||||||
LibraryUpdateJob.cancelAllWorks(context)
|
LibraryUpdateJob.cancelAllWorks(context)
|
||||||
LibraryUpdateJob.setupTask(context)
|
LibraryUpdateJob.setupTask(context)
|
||||||
|
WorkManager.getInstance(context).cancelAllWorkByTag("UpdateChecker")
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (oldVersion under 1) { } (1 is current release version)
|
// if (oldVersion under 1) { } (1 is current release version)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user