fix: The trigger for library update wasn't working properly. (#1119)

Missed them, so it was always updating library without actually syncing even when the trigger was on.

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2024-03-17 14:56:00 +11:00 committed by GitHub
parent d12a9d329b
commit a425cae73b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 3 additions and 26 deletions

View File

@ -73,7 +73,6 @@ class SyncPreferences(
syncOnChapterOpen = preferenceStore.getBoolean("sync_on_chapter_open", false).get(), syncOnChapterOpen = preferenceStore.getBoolean("sync_on_chapter_open", false).get(),
syncOnAppStart = preferenceStore.getBoolean("sync_on_app_start", false).get(), syncOnAppStart = preferenceStore.getBoolean("sync_on_app_start", false).get(),
syncOnAppResume = preferenceStore.getBoolean("sync_on_app_resume", false).get(), syncOnAppResume = preferenceStore.getBoolean("sync_on_app_resume", false).get(),
syncOnLibraryUpdate = preferenceStore.getBoolean("sync_on_library_update", false).get(),
) )
} }
@ -86,7 +85,5 @@ class SyncPreferences(
.set(syncTriggerOptions.syncOnAppStart) .set(syncTriggerOptions.syncOnAppStart)
preferenceStore.getBoolean("sync_on_app_resume", false) preferenceStore.getBoolean("sync_on_app_resume", false)
.set(syncTriggerOptions.syncOnAppResume) .set(syncTriggerOptions.syncOnAppResume)
preferenceStore.getBoolean("sync_on_library_update", false)
.set(syncTriggerOptions.syncOnLibraryUpdate)
} }
} }

View File

@ -817,19 +817,11 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
KEY_GROUP_EXTRA to groupExtra, KEY_GROUP_EXTRA to groupExtra,
// SY <-- // SY <--
) )
val request = OneTimeWorkRequestBuilder<LibraryUpdateJob>()
.addTag(TAG)
.addTag(WORK_NAME_MANUAL)
.setInputData(inputData)
.build()
wm.enqueueUniqueWork(WORK_NAME_MANUAL, ExistingWorkPolicy.KEEP, request)
val syncPreferences: SyncPreferences = Injekt.get() val syncPreferences: SyncPreferences = Injekt.get()
// Only proceed with SyncDataJob if sync is enabled and the specific sync on library update flag is set // Always sync the data before library update if syncing is enabled.
val syncTriggerOpt = syncPreferences.getSyncTriggerOptions() if (syncPreferences.isSyncEnabled()) {
if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnLibraryUpdate
) {
// Check if SyncDataJob is already running // Check if SyncDataJob is already running
if (wm.isRunning(SyncDataJob.TAG_MANUAL)) { if (wm.isRunning(SyncDataJob.TAG_MANUAL)) {
// SyncDataJob is already running // SyncDataJob is already running
@ -842,7 +834,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
.build() .build()
// Chain SyncDataJob to run before LibraryUpdateJob // Chain SyncDataJob to run before LibraryUpdateJob
val inputData = workDataOf(KEY_CATEGORY to category?.id)
val libraryUpdateJob = OneTimeWorkRequestBuilder<LibraryUpdateJob>() val libraryUpdateJob = OneTimeWorkRequestBuilder<LibraryUpdateJob>()
.addTag(TAG) .addTag(TAG)
.addTag(WORK_NAME_MANUAL) .addTag(WORK_NAME_MANUAL)
@ -853,7 +844,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
.then(libraryUpdateJob) .then(libraryUpdateJob)
.enqueue() .enqueue()
} else { } else {
val inputData = workDataOf(KEY_CATEGORY to category?.id)
val request = OneTimeWorkRequestBuilder<LibraryUpdateJob>() val request = OneTimeWorkRequestBuilder<LibraryUpdateJob>()
.addTag(TAG) .addTag(TAG)
.addTag(WORK_NAME_MANUAL) .addTag(WORK_NAME_MANUAL)

View File

@ -9,21 +9,18 @@ data class SyncTriggerOptions(
val syncOnChapterOpen: Boolean = false, val syncOnChapterOpen: Boolean = false,
val syncOnAppStart: Boolean = false, val syncOnAppStart: Boolean = false,
val syncOnAppResume: Boolean = false, val syncOnAppResume: Boolean = false,
val syncOnLibraryUpdate: Boolean = false,
) { ) {
fun asBooleanArray() = booleanArrayOf( fun asBooleanArray() = booleanArrayOf(
syncOnChapterRead, syncOnChapterRead,
syncOnChapterOpen, syncOnChapterOpen,
syncOnAppStart, syncOnAppStart,
syncOnAppResume, syncOnAppResume,
syncOnLibraryUpdate,
) )
fun anyEnabled() = syncOnChapterRead || fun anyEnabled() = syncOnChapterRead ||
syncOnChapterOpen || syncOnChapterOpen ||
syncOnAppStart || syncOnAppStart ||
syncOnAppResume || syncOnAppResume
syncOnLibraryUpdate
companion object { companion object {
val mainOptions = persistentListOf( val mainOptions = persistentListOf(
@ -47,11 +44,6 @@ data class SyncTriggerOptions(
getter = SyncTriggerOptions::syncOnAppResume, getter = SyncTriggerOptions::syncOnAppResume,
setter = { options, enabled -> options.copy(syncOnAppResume = enabled) }, setter = { options, enabled -> options.copy(syncOnAppResume = enabled) },
), ),
Entry(
label = MR.strings.sync_on_library_update,
getter = SyncTriggerOptions::syncOnLibraryUpdate,
setter = { options, enabled -> options.copy(syncOnLibraryUpdate = enabled) },
),
) )
fun fromBooleanArray(array: BooleanArray) = SyncTriggerOptions( fun fromBooleanArray(array: BooleanArray) = SyncTriggerOptions(
@ -59,7 +51,6 @@ data class SyncTriggerOptions(
syncOnChapterOpen = array[1], syncOnChapterOpen = array[1],
syncOnAppStart = array[2], syncOnAppStart = array[2],
syncOnAppResume = array[3], syncOnAppResume = array[3],
syncOnLibraryUpdate = array[4],
) )
} }

View File

@ -591,7 +591,6 @@
<string name="sync_on_chapter_open">Sync on Chapter Open</string> <string name="sync_on_chapter_open">Sync on Chapter Open</string>
<string name="sync_on_app_start">Sync on App Start</string> <string name="sync_on_app_start">Sync on App Start</string>
<string name="sync_on_app_resume">Sync on App Resume</string> <string name="sync_on_app_resume">Sync on App Resume</string>
<string name="sync_on_library_update">Sync on Library Update</string>
<string name="sync_library">Sync library</string> <string name="sync_library">Sync library</string>
<!-- Advanced section --> <!-- Advanced section -->