mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-26 09:44:55 +00:00
Use default distributor when selecting Instant for the first time
This commit is contained in:
@@ -240,7 +240,14 @@ class SimplexApp: Application(), LifecycleEventObserver {
|
||||
}
|
||||
if (mode == NotificationsMode.INSTANT) {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
SimplexService.initUnifiedPush(this) {
|
||||
/**
|
||||
* If the user re-selects INSTANT, then we don't use default distributor - so it's possible to use
|
||||
* a non-default distrib
|
||||
*/
|
||||
val activity = if (chatModel.controller.appPrefs.notificationsMode.get() != NotificationsMode.INSTANT) {
|
||||
mainActivity.get()
|
||||
} else null
|
||||
SimplexService.initUnifiedPush(activity, this) {
|
||||
// Change notifications mode only if everything is correctly setup
|
||||
chatModel.controller.appPrefs.notificationsMode.set(mode)
|
||||
}
|
||||
|
||||
@@ -428,8 +428,11 @@ class SimplexService: Service() {
|
||||
|
||||
private fun getPreferences(context: Context): SharedPreferences = context.getSharedPreferences(SHARED_PREFS_ID, Context.MODE_PRIVATE)
|
||||
|
||||
suspend fun initUnifiedPush(scope: CoroutineScope, onSuccess: () -> Unit) {
|
||||
PushManager.initUnifiedPush(androidAppContext, scope, onSuccess)
|
||||
/**
|
||||
* @param activity if not null, try default distrib
|
||||
*/
|
||||
suspend fun initUnifiedPush(activity: Activity?, scope: CoroutineScope, onSuccess: () -> Unit) {
|
||||
PushManager.initUnifiedPush(androidAppContext, activity, scope, onSuccess)
|
||||
}
|
||||
|
||||
fun showBackgroundServiceNoticeIfNeeded(showOffAlert: Boolean = true) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package chat.simplex.app.platform
|
||||
|
||||
import SectionItemView
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
@@ -36,13 +37,28 @@ object PushManager {
|
||||
* If a single distrib is available, use it
|
||||
* If many, ask distributor to use with a dialog
|
||||
* Else alert about missing service
|
||||
*
|
||||
* @param activity if not null: try to use default distrib
|
||||
*/
|
||||
suspend fun initUnifiedPush(context: Context, scope: CoroutineScope, onSuccess: () -> Unit) {
|
||||
suspend fun initUnifiedPush(context: Context, activity: Activity?, scope: CoroutineScope, onSuccess: () -> Unit) {
|
||||
val vapid = getVapidKey(scope)
|
||||
?: run {
|
||||
Log.w(TAG, "Tried to init UnifiedPush but couldn't find VAPID key")
|
||||
return
|
||||
}
|
||||
activity?.let {
|
||||
UnifiedPush.tryUseDefaultDistributor(activity) { success ->
|
||||
if (success) {
|
||||
register(context, vapid)
|
||||
onSuccess()
|
||||
} else {
|
||||
initUnifiedPushWithDialogs(context, vapid, onSuccess)
|
||||
}
|
||||
}
|
||||
} ?: initUnifiedPushWithDialogs(context, vapid, onSuccess)
|
||||
}
|
||||
|
||||
private fun initUnifiedPushWithDialogs(context: Context, vapid: String, onSuccess: () -> Unit) {
|
||||
val distributors = UnifiedPush.getDistributors(context)
|
||||
when (distributors.size) {
|
||||
0 -> {
|
||||
|
||||
Reference in New Issue
Block a user