From 161426cdbe7d1998ed88baddd0fc24c671a02b7c Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Tue, 25 Jun 2024 19:06:05 -0300 Subject: [PATCH] wip: oops --- .../tachiyomi/data/library/LibraryUpdateJob.kt | 4 ++++ .../kanade/tachiyomi/data/sync/SyncManager.kt | 3 +-- .../data/sync/service/SyncYomiSyncService.kt | 5 ++--- .../common/util/system/LogcatExtensions.kt | 18 ++++++++++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index 6e22534171..1997ef76d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -477,6 +477,10 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet return false } + val inputData = workDataOf( + KEY_CATEGORY to category?.id, + ) + val syncPreferences: SyncPreferences = Injekt.get() // Always sync the data before library update if syncing is enabled. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt index 3ef70d6530..bc8f7f54c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt @@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.data.backup.create.BackupOptions import eu.kanade.tachiyomi.data.backup.models.Backup import eu.kanade.tachiyomi.data.backup.models.BackupChapter import eu.kanade.tachiyomi.data.backup.models.BackupManga -import eu.kanade.tachiyomi.data.backup.models.BackupSerializer import eu.kanade.tachiyomi.data.backup.restore.BackupRestoreJob import eu.kanade.tachiyomi.data.backup.restore.RestoreOptions import eu.kanade.tachiyomi.data.backup.restore.restorers.MangaRestorer @@ -202,7 +201,7 @@ class SyncManager( val cacheFile = File(context.cacheDir, "tachiyomi_sync_data.proto.gz") return try { cacheFile.outputStream().use { output -> - output.write(ProtoBuf.encodeToByteArray(BackupSerializer, backup)) + output.write(parser.encodeToByteArray(Backup.Serializer(), backup)) Uri.fromFile(cacheFile) } } catch (e: IOException) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt index 2af4d28ffe..e1e6be8ba9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.data.sync.service import android.content.Context import eu.kanade.domain.sync.SyncPreferences import eu.kanade.tachiyomi.data.backup.models.Backup -import eu.kanade.tachiyomi.data.backup.models.BackupSerializer import eu.kanade.tachiyomi.data.sync.SyncNotifier import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.PUT @@ -104,7 +103,7 @@ class SyncYomiSyncService( } return try { - val backup = protoBuf.decodeFromByteArray(BackupSerializer, byteArray) + val backup = parser.decodeFromByteArray(Backup.Serializer(), byteArray) return Pair(SyncData(backup = backup), newETag) } catch (_: SerializationException) { logcat(LogPriority.INFO) { @@ -147,7 +146,7 @@ class SyncYomiSyncService( .writeTimeout(timeout, TimeUnit.SECONDS) .build() - val byteArray = protoBuf.encodeToByteArray(BackupSerializer, backup) + val byteArray = parser.encodeToByteArray(Backup.Serializer(), backup) if (byteArray.isEmpty()) { throw IllegalStateException(context.stringResource(MR.strings.empty_backup_error)) } diff --git a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/LogcatExtensions.kt b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/LogcatExtensions.kt index 115f647f50..683aa84224 100644 --- a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/LogcatExtensions.kt +++ b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/LogcatExtensions.kt @@ -7,12 +7,22 @@ import logcat.logcat inline fun Any.logcat( priority: LogPriority = LogPriority.DEBUG, throwable: Throwable? = null, + tag: String? = null, message: () -> String = { "" }, ) = logcat(priority = priority) { - var msg = message() + val logMessage = StringBuilder() + + if (!tag.isNullOrEmpty()) { + logMessage.append("[$tag] ") + } + + val msg = message() + logMessage.append(msg) + if (throwable != null) { - if (msg.isNotBlank()) msg += "\n" - msg += throwable.asLog() + if (msg.isNotBlank()) logMessage.append("\n") + logMessage.append(throwable.asLog()) } - msg + + logMessage.toString() }