android, desktop: run with stopped chat (#3624)

* android, desktop: run with stopped chat

* way to prevent starting a chat in case of not saved database key

* rename

* change position of a call

* new way of doing the same

* better

* exit process

---------

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Stanislav Dmitrenko
2024-01-02 14:21:39 +00:00
committed by GitHub
co-authored by Evgeny Poberezkin
parent c9b1d54f13
commit e6b5727003
9 changed files with 100 additions and 68 deletions
@@ -13,7 +13,6 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import chat.simplex.common.platform.Log
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.work.*
@@ -21,12 +20,13 @@ import chat.simplex.common.AppLock
import chat.simplex.common.helpers.requiresIgnoringBattery
import chat.simplex.common.model.ChatController
import chat.simplex.common.model.NotificationsMode
import chat.simplex.common.platform.androidAppContext
import chat.simplex.common.platform.*
import chat.simplex.common.views.helpers.*
import kotlinx.coroutines.*
import chat.simplex.res.MR
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource
import kotlin.system.exitProcess
// based on:
// https://robertohuertas.com/2019/06/29/android_foreground_services/
@@ -173,6 +173,11 @@ class SimplexService: Service() {
// Just to make sure that after restart of the app the user will need to re-authenticate
AppLock.clearAuthState()
if (appPreferences.chatStopped.get()) {
stopSelf()
exitProcess(0)
}
// If notification service isn't enabled or battery optimization isn't disabled, we shouldn't restart the service
if (!SimplexApp.context.allowToStartServiceAfterAppExit()) {
return