Merge branch 'stable'

This commit is contained in:
Evgeny Poberezkin
2024-12-24 10:24:06 +00:00
5 changed files with 16 additions and 5 deletions
@@ -32,8 +32,10 @@ object MessagesFetcherWorker {
SimplexApp.context.getWorkManagerInstance().enqueueUniqueWork(UNIQUE_WORK_TAG, ExistingWorkPolicy.REPLACE, periodicWorkRequest)
}
fun cancelAll() {
Log.d(TAG, "Worker: canceled all tasks")
fun cancelAll(withLog: Boolean = true) {
if (withLog) {
Log.d(TAG, "Worker: canceled all tasks")
}
SimplexApp.context.getWorkManagerInstance().cancelUniqueWork(UNIQUE_WORK_TAG)
}
}
@@ -33,6 +33,7 @@ import chat.simplex.common.views.helpers.*
import chat.simplex.common.views.onboarding.OnboardingStage
import com.jakewharton.processphoenix.ProcessPhoenix
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.map
import java.io.*
import java.util.*
import java.util.concurrent.TimeUnit
@@ -151,6 +152,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
* */
fun schedulePeriodicServiceRestartWorker() = CoroutineScope(Dispatchers.Default).launch {
if (!allowToStartServiceAfterAppExit()) {
getWorkManagerInstance().cancelUniqueWork(SimplexService.SERVICE_START_WORKER_WORK_NAME_PERIODIC)
return@launch
}
val workerVersion = chatController.appPrefs.autoRestartWorkerVersion.get()
@@ -172,6 +174,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
fun schedulePeriodicWakeUp() = CoroutineScope(Dispatchers.Default).launch {
if (!allowToStartPeriodically()) {
MessagesFetcherWorker.cancelAll(withLog = false)
return@launch
}
MessagesFetcherWorker.scheduleWork()
@@ -227,7 +230,9 @@ class SimplexApp: Application(), LifecycleEventObserver {
SimplexService.safeStopService()
}
}
if (mode != NotificationsMode.SERVICE) {
getWorkManagerInstance().cancelUniqueWork(SimplexService.SERVICE_START_WORKER_WORK_NAME_PERIODIC)
}
if (mode != NotificationsMode.PERIODIC) {
MessagesFetcherWorker.cancelAll()
}
@@ -244,6 +249,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
}
override fun androidChatStopped() {
getWorkManagerInstance().cancelUniqueWork(SimplexService.SERVICE_START_WORKER_WORK_NAME_PERIODIC)
SimplexService.safeStopService()
MessagesFetcherWorker.cancelAll()
}
@@ -139,6 +139,7 @@ class SimplexService: Service() {
if (chatDbStatus != DBMigrationResult.OK) {
Log.w(chat.simplex.app.TAG, "SimplexService: problem with the database: $chatDbStatus")
showPassphraseNotification(chatDbStatus)
androidAppContext.getWorkManagerInstance().cancelUniqueWork(SimplexService.SERVICE_START_WORKER_WORK_NAME_PERIODIC)
safeStopService()
return@withLongRunningApi
}
@@ -681,6 +682,7 @@ class SimplexService: Service() {
}
ChatController.appPrefs.notificationsMode.set(NotificationsMode.OFF)
StartReceiver.toggleReceiver(false)
androidAppContext.getWorkManagerInstance().cancelUniqueWork(SimplexService.SERVICE_START_WORKER_WORK_NAME_PERIODIC)
MessagesFetcherWorker.cancelAll()
safeStopService()
}
@@ -691,6 +691,7 @@ private suspend fun finishMigration(appSettings: AppSettings, close: () -> Unit)
if (user != null) {
startChat(user)
}
platform.androidChatStartedAfterBeingOff()
hideView(close)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.migrate_to_device_chat_migrated), generalGetString(MR.strings.migrate_to_device_finalize_migration))
} catch (e: Exception) {
@@ -78,7 +78,7 @@ fun NotificationsSettingsLayout(
)
}
if (platform.androidIsXiaomiDevice() && (notificationsMode.value == NotificationsMode.PERIODIC || notificationsMode.value == NotificationsMode.SERVICE)) {
SectionTextFooter(stringResource(MR.strings.xiaomi_ignore_battery_optimization))
SectionTextFooter(annotatedStringResource(MR.strings.xiaomi_ignore_battery_optimization))
}
}
SectionBottomSpacer()
@@ -95,7 +95,7 @@ fun NotificationsModeView(
AppBarTitle(stringResource(MR.strings.settings_notifications_mode_title).lowercase().capitalize(Locale.current))
SectionViewSelectable(null, notificationsMode, modes, onNotificationsModeSelected)
if (platform.androidIsXiaomiDevice() && (notificationsMode.value == NotificationsMode.PERIODIC || notificationsMode.value == NotificationsMode.SERVICE)) {
SectionTextFooter(stringResource(MR.strings.xiaomi_ignore_battery_optimization))
SectionTextFooter(annotatedStringResource(MR.strings.xiaomi_ignore_battery_optimization))
}
}
}