From f70d5ea97698bc3708c035dc3e4d7a1e894cd765 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 13 May 2023 04:02:11 +0600 Subject: [PATCH] Delay automatic backup when restoring (#9492) --- .../eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt index 4d590431f..a5c4bbf58 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.backup import android.content.Context import android.net.Uri import androidx.core.net.toUri +import androidx.work.BackoffPolicy import androidx.work.CoroutineWorker import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingWorkPolicy @@ -22,6 +23,8 @@ import tachiyomi.domain.backup.service.BackupPreferences import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.minutes +import kotlin.time.toJavaDuration class BackupCreateJob(private val context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams) { @@ -29,11 +32,14 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete private val notifier = BackupNotifier(context) override suspend fun doWork(): Result { + val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true) + + if (isAutoBackup && BackupRestoreJob.isRunning(context)) return Result.retry() + val backupPreferences = Injekt.get() val uri = inputData.getString(LOCATION_URI_KEY)?.toUri() ?: backupPreferences.backupsDirectory().get().toUri() val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupConst.BACKUP_ALL) - val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true) try { setForeground(getForegroundInfo()) @@ -76,6 +82,7 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete 10, TimeUnit.MINUTES, ) + .setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 10.minutes.toJavaDuration()) .addTag(TAG_AUTO) .setInputData(workDataOf(IS_AUTO_BACKUP_KEY to true)) .build()