mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Delay automatic backup when restoring (#9492)
This commit is contained in:
parent
dbbf6c5de0
commit
f70d5ea976
1 changed files with 8 additions and 1 deletions
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.backup
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import androidx.work.BackoffPolicy
|
||||||
import androidx.work.CoroutineWorker
|
import androidx.work.CoroutineWorker
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
|
@ -22,6 +23,8 @@ import tachiyomi.domain.backup.service.BackupPreferences
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
import kotlin.time.toJavaDuration
|
||||||
|
|
||||||
class BackupCreateJob(private val context: Context, workerParams: WorkerParameters) :
|
class BackupCreateJob(private val context: Context, workerParams: WorkerParameters) :
|
||||||
CoroutineWorker(context, workerParams) {
|
CoroutineWorker(context, workerParams) {
|
||||||
|
@ -29,11 +32,14 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
||||||
private val notifier = BackupNotifier(context)
|
private val notifier = BackupNotifier(context)
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
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<BackupPreferences>()
|
val backupPreferences = Injekt.get<BackupPreferences>()
|
||||||
val uri = inputData.getString(LOCATION_URI_KEY)?.toUri()
|
val uri = inputData.getString(LOCATION_URI_KEY)?.toUri()
|
||||||
?: backupPreferences.backupsDirectory().get().toUri()
|
?: backupPreferences.backupsDirectory().get().toUri()
|
||||||
val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupConst.BACKUP_ALL)
|
val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupConst.BACKUP_ALL)
|
||||||
val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setForeground(getForegroundInfo())
|
setForeground(getForegroundInfo())
|
||||||
|
@ -76,6 +82,7 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
||||||
10,
|
10,
|
||||||
TimeUnit.MINUTES,
|
TimeUnit.MINUTES,
|
||||||
)
|
)
|
||||||
|
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 10.minutes.toJavaDuration())
|
||||||
.addTag(TAG_AUTO)
|
.addTag(TAG_AUTO)
|
||||||
.setInputData(workDataOf(IS_AUTO_BACKUP_KEY to true))
|
.setInputData(workDataOf(IS_AUTO_BACKUP_KEY to true))
|
||||||
.build()
|
.build()
|
||||||
|
|
Loading…
Reference in a new issue