mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-25 12:02:13 +00:00
Register for push notifications on app startup
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user