Register for push notifications on app startup

This commit is contained in:
sim
2025-08-05 16:08:37 +02:00
parent 2f89739f76
commit 0c45f69504
2 changed files with 16 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import androidx.work.*
import chat.simplex.app.MainActivity.Companion.OLD_ANDROID_UI_FLAGS
import chat.simplex.app.model.NtfManager
import chat.simplex.app.model.NtfManager.AcceptCallAction
import chat.simplex.app.platform.PushManager
import chat.simplex.app.views.call.CallActivity
import chat.simplex.common.helpers.*
import chat.simplex.common.model.*
@@ -270,6 +271,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
// Prevents from showing "Enable notifications" alert when onboarding wasn't complete yet
if (chatModel.controller.appPrefs.onboardingStage.get() == OnboardingStage.OnboardingComplete) {
SimplexService.showBackgroundServiceNoticeIfNeeded()
PushManager.initStart(context)
if (appPrefs.notificationsMode.get() == NotificationsMode.SERVICE)
withBGApi {
platform.androidServiceStart()

View File

@@ -62,6 +62,20 @@ object PushManager {
}
}
/**
* Register to UnifiedPush distributor if any is already used
*
* To run when the app starts; call [chat.simplex.app.PushService.onUnregistered]
* if the distributor is uninstalled
*/
fun initStart(context: Context) {
Log.d(TAG, "Init UnifiedPush during app startup")
//TODO: limit to once a day to reduce registrations to ntf server ?
UnifiedPush.getAckDistributor(context)?.let {
register(context)
}
}
private fun register(context: Context) {
// TODO: add VAPID
UnifiedPush.register(context)