mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-28 21:02:49 -05:00
Update WorkManager (#8772)
This commit is contained in:
parent
46417fe427
commit
8552838bda
6 changed files with 20 additions and 7 deletions
1
.github/renovate.json
vendored
1
.github/renovate.json
vendored
|
@ -5,7 +5,6 @@
|
|||
"schedule": ["every sunday"],
|
||||
"ignoreDeps": [
|
||||
"androidx.core:core-splashscreen",
|
||||
"androidx.work:work-runtime-ktx",
|
||||
"com.android.tools:r8",
|
||||
"com.google.guava:guava",
|
||||
"com.github.commandiron:WheelPickerCompose"
|
||||
|
|
|
@ -6,6 +6,7 @@ import androidx.core.net.toUri
|
|||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.ForegroundInfo
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkInfo
|
||||
|
@ -25,14 +26,21 @@ import java.util.concurrent.TimeUnit
|
|||
class BackupCreatorJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(context, workerParams) {
|
||||
|
||||
private val notifier = BackupNotifier(context)
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
val backupPreferences = Injekt.get<BackupPreferences>()
|
||||
val notifier = BackupNotifier(context)
|
||||
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())
|
||||
} catch (e: IllegalStateException) {
|
||||
logcat(LogPriority.ERROR, e) { "Not allowed to run on foreground service" }
|
||||
}
|
||||
|
||||
context.notificationManager.notify(Notifications.ID_BACKUP_PROGRESS, notifier.showBackupProgress().build())
|
||||
return try {
|
||||
val location = BackupManager(context).createBackup(uri, flags, isAutoBackup)
|
||||
|
@ -47,6 +55,10 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||
return ForegroundInfo(Notifications.ID_BACKUP_PROGRESS, notifier.showBackupProgress().build())
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun isManualJobRunning(context: Context): Boolean {
|
||||
val list = WorkManager.getInstance(context).getWorkInfosByTag(TAG_MANUAL).get()
|
||||
|
@ -68,7 +80,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
|
|||
.setInputData(workDataOf(IS_AUTO_BACKUP_KEY to true))
|
||||
.build()
|
||||
|
||||
workManager.enqueueUniquePeriodicWork(TAG_AUTO, ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
workManager.enqueueUniquePeriodicWork(TAG_AUTO, ExistingPeriodicWorkPolicy.UPDATE, request)
|
||||
} else {
|
||||
workManager.cancelUniqueWork(TAG_AUTO)
|
||||
}
|
||||
|
|
|
@ -59,7 +59,9 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|||
.setConstraints(constraints)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
// Re-enqueue work because of common support suggestion to change
|
||||
// the settings on the desired time to schedule it at that time
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, request)
|
||||
} else {
|
||||
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class AppUpdateJob(private val context: Context, workerParams: WorkerParameters)
|
|||
.setConstraints(constraints)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.UPDATE, request)
|
||||
}
|
||||
|
||||
fun cancelTask(context: Context) {
|
||||
|
|
|
@ -85,7 +85,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam
|
|||
.setConstraints(constraints)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.UPDATE, request)
|
||||
} else {
|
||||
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ lifecycle-common = { module = "androidx.lifecycle:lifecycle-common", version.ref
|
|||
lifecycle-process = { module = "androidx.lifecycle:lifecycle-process", version.ref = "lifecycle_version" }
|
||||
lifecycle-runtimektx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle_version" }
|
||||
|
||||
work-runtime = "androidx.work:work-runtime-ktx:2.6.0"
|
||||
work-runtime = "androidx.work:work-runtime-ktx:2.8.0-rc01"
|
||||
guava = "com.google.guava:guava:31.1-android"
|
||||
|
||||
paging-runtime = "androidx.paging:paging-runtime:3.1.1"
|
||||
|
|
Loading…
Reference in a new issue