From 0684f5060675cc180c44a2db33f6557f01958f86 Mon Sep 17 00:00:00 2001 From: Den <2119348+dzianisv@users.noreply.github.com> Date: Wed, 3 Jun 2026 03:06:36 -0700 Subject: [PATCH] fix(fdroid): Firebase-free stubs for expo-notifications --- .../tokens/PushTokenModule.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 fdroid/expo-notifications-patches/tokens/PushTokenModule.kt diff --git a/fdroid/expo-notifications-patches/tokens/PushTokenModule.kt b/fdroid/expo-notifications-patches/tokens/PushTokenModule.kt new file mode 100644 index 0000000..b397a78 --- /dev/null +++ b/fdroid/expo-notifications-patches/tokens/PushTokenModule.kt @@ -0,0 +1,42 @@ +package expo.modules.notifications.tokens + +import expo.modules.kotlin.Promise +import expo.modules.kotlin.modules.Module +import expo.modules.kotlin.modules.ModuleDefinition +import expo.modules.notifications.service.delegates.FirebaseMessagingDelegate.Companion.addTokenListener +import expo.modules.notifications.tokens.interfaces.FirebaseTokenListener + +private const val NEW_TOKEN_EVENT_NAME = "onDevicePushToken" +private const val NEW_TOKEN_EVENT_TOKEN_KEY = "devicePushToken" +private const val REGISTRATION_FAIL_CODE = "E_REGISTRATION_FAILED" +private const val UNREGISTER_FOR_NOTIFICATIONS_FAIL_CODE = "E_UNREGISTER_FOR_NOTIFICATIONS_FAILED" + +/** + * Stub PushTokenModule (Firebase-free) for F-Droid builds. + * Push tokens are unavailable without Firebase — getDevicePushTokenAsync rejects with an error. + */ +class PushTokenModule : Module(), FirebaseTokenListener { + override fun onNewToken(token: String) { + runCatching { + sendEvent(NEW_TOKEN_EVENT_NAME, mapOf(NEW_TOKEN_EVENT_TOKEN_KEY to token)) + } + } + + override fun definition() = ModuleDefinition { + Name("ExpoPushTokenManager") + + Events("onDevicePushToken") + + OnCreate { + addTokenListener(this@PushTokenModule) + } + + AsyncFunction("getDevicePushTokenAsync") { promise: Promise -> + promise.reject(REGISTRATION_FAIL_CODE, "Push notifications via FCM are not available in this build (F-Droid). Use local notifications only.", null) + } + + AsyncFunction("unregisterForNotificationsAsync") { promise: Promise -> + promise.resolve(null) + } + } +}