From 5563418d79596e7185a47fb51f65f14f9828d8d2 Mon Sep 17 00:00:00 2001 From: rhunk <101876869+rhunk@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:12:49 +0100 Subject: [PATCH] fix(core): sync remote in background --- .../me/rhunk/snapenhance/core/SnapEnhance.kt | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt index 703c71d17..6b2a5c632 100644 --- a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt +++ b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt @@ -114,7 +114,9 @@ class SnapEnhance { appContext.isMainActivityPaused = false }) { appContext.reloadConfig() - syncRemote() + appContext.executeAsync { + syncRemote() + } } } } @@ -134,6 +136,11 @@ class SnapEnhance { initWidgetListener() initNative() scope.launch(Dispatchers.IO) { + runCatching { + syncRemote() + }.onFailure { + log.error("Failed to sync remote", it) + } translation.userLocale = getConfigLocale() translation.loadFromCallback { locale -> bridgeClient.fetchLocales(locale) @@ -257,37 +264,35 @@ class SnapEnhance { } private fun syncRemote() { - appContext.executeAsync { - bridgeClient.sync(object : SyncCallback.Stub() { - override fun syncFriend(uuid: String): String? { - return database.getFriendInfo(uuid)?.let { - MessagingFriendInfo( - userId = it.userId!!, - displayName = it.displayName, - mutableUsername = it.mutableUsername!!, - bitmojiId = it.bitmojiAvatarId, - selfieId = it.bitmojiSelfieId, - streaks = if (it.streakLength > 0) { - FriendStreaks( - expirationTimestamp = it.streakExpirationTimestamp, - length = it.streakLength - ) - } else null - ).toSerialized() - } + appContext.bridgeClient.sync(object : SyncCallback.Stub() { + override fun syncFriend(uuid: String): String? { + return appContext.database.getFriendInfo(uuid)?.let { + MessagingFriendInfo( + userId = it.userId!!, + displayName = it.displayName, + mutableUsername = it.mutableUsername!!, + bitmojiId = it.bitmojiAvatarId, + selfieId = it.bitmojiSelfieId, + streaks = if (it.streakLength > 0) { + FriendStreaks( + expirationTimestamp = it.streakExpirationTimestamp, + length = it.streakLength + ) + } else null + ).toSerialized() } + } - override fun syncGroup(uuid: String): String? { - return database.getFeedEntryByConversationId(uuid)?.let { - MessagingGroupInfo( - it.key!!, - it.feedDisplayName!!, - it.participantsSize - ).toSerialized() - } + override fun syncGroup(uuid: String): String? { + return appContext.database.getFeedEntryByConversationId(uuid)?.let { + MessagingGroupInfo( + it.key!!, + it.feedDisplayName!!, + it.participantsSize + ).toSerialized() } - }) - } + } + }) } private fun jetpackComposeResourceHook() {