From 4a7a09c43a37e0fa3a30039f0653d278e92e5415 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 21 Aug 2025 14:20:55 -0400 Subject: [PATCH] Tries to avoid crash when lacking google services in the play version. --- .../notifications/PushNotificationUtils.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt index be36c33f9..3973f0758 100644 --- a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt +++ b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt @@ -20,6 +20,7 @@ */ package com.vitorpamplona.amethyst.service.notifications +import android.util.Log import com.google.firebase.messaging.FirebaseMessaging import com.vitorpamplona.amethyst.AccountInfo import com.vitorpamplona.amethyst.service.retryIfException @@ -35,12 +36,16 @@ object PushNotificationUtils { accounts: List, okHttpClient: (String) -> OkHttpClient, ) = with(Dispatchers.IO) { - val token = FirebaseMessaging.getInstance().token.await() - if (hasInit?.equals(accounts) == true && lastToken == token) { - return@with - } + try { + val token = FirebaseMessaging.getInstance().token.await() + if (hasInit?.equals(accounts) == true && lastToken == token) { + return@with + } - registerToken(token, accounts, okHttpClient) + registerToken(token, accounts, okHttpClient) + } catch (e: Exception) { + Log.e("PushNotificationUtils", "Failed to get Firebase token", e) + } } suspend fun checkAndInit(