fix(push): suppress notifications when app is in foreground (0.5.12)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
||||
applicationId = "ru.kalinamall.seaca"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 25
|
||||
versionName = "0.5.11"
|
||||
versionCode = 26
|
||||
versionName = "0.5.12"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@@ -54,6 +54,7 @@ dependencies {
|
||||
implementation("androidx.activity:activity-compose:1.9.3")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.3")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.7")
|
||||
implementation("androidx.lifecycle:lifecycle-process:2.8.7")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.1")
|
||||
implementation("androidx.security:security-crypto:1.1.0-alpha06")
|
||||
|
||||
@@ -3,12 +3,14 @@ package ru.kalinamall.seaca
|
||||
import android.app.Application
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import ru.kalinamall.seaca.data.SessionStore
|
||||
import ru.kalinamall.seaca.push.AppForegroundState
|
||||
import ru.kalinamall.seaca.push.NotificationHelper
|
||||
import ru.kalinamall.seaca.push.NotificationSoundResolver
|
||||
|
||||
class SeacaApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
AppForegroundState.bind()
|
||||
val store = SessionStore(this)
|
||||
val settings = runBlocking {
|
||||
NotificationSoundResolver.normalizeStoredSettings(this@SeacaApplication, store)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package ru.kalinamall.seaca.push
|
||||
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
|
||||
/** True, пока хотя бы одна activity приложения видима (ProcessLifecycleOwner.onStart). */
|
||||
object AppForegroundState {
|
||||
@Volatile
|
||||
private var inForeground = false
|
||||
|
||||
fun bind() {
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(
|
||||
object : DefaultLifecycleObserver {
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
inForeground = true
|
||||
}
|
||||
|
||||
override fun onStop(owner: LifecycleOwner) {
|
||||
inForeground = false
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun isInForeground(): Boolean = inForeground
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class SeacaMessagingService : FirebaseMessagingService() {
|
||||
private val repo by lazy { SacRepository(applicationContext) }
|
||||
|
||||
override fun onMessageReceived(message: RemoteMessage) {
|
||||
if (AppForegroundState.isInForeground()) return
|
||||
val mode = runBlocking { repo.session.getNotificationMode() }
|
||||
when (mode) {
|
||||
NotificationMode.OFF -> return
|
||||
|
||||
Reference in New Issue
Block a user