From 13217548672a0981efd084738e29f503346db6ef Mon Sep 17 00:00:00 2001 From: Dmitriy Krivoruchko Date: Sat, 23 Jul 2022 09:55:40 +0300 Subject: [PATCH] Http server stop fix --- app/build.gradle | 4 +-- .../data/state/AppStateMachineImpl.kt | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ffc5c998..fba0b9e5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId = "info.dvkr.screenstream" minSdkVersion(21) targetSdkVersion(32) - versionCode = 30904 - versionName = "3.9.4" + versionCode = 30905 + versionName = "3.9.5" resConfigs 'en', 'ru', 'pt-rBR', 'zh-rTW', 'fr-rFR', 'fa', 'it', 'pl', 'hi', 'de', 'sk', 'es', 'ar', 'ja', 'gl', 'ca', 'uk', 'nl' vectorDrawables.useSupportLibrary = true diff --git a/data/src/main/kotlin/info/dvkr/screenstream/data/state/AppStateMachineImpl.kt b/data/src/main/kotlin/info/dvkr/screenstream/data/state/AppStateMachineImpl.kt index a594314f..57d73135 100644 --- a/data/src/main/kotlin/info/dvkr/screenstream/data/state/AppStateMachineImpl.kt +++ b/data/src/main/kotlin/info/dvkr/screenstream/data/state/AppStateMachineImpl.kt @@ -23,8 +23,30 @@ import info.dvkr.screenstream.data.settings.Settings import info.dvkr.screenstream.data.state.helper.BroadcastHelper import info.dvkr.screenstream.data.state.helper.ConnectivityHelper import info.dvkr.screenstream.data.state.helper.NetworkHelper -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.CoroutineExceptionHandler +import kotlinx.coroutines.CoroutineName +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.NonCancellable +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext +import kotlinx.coroutines.withTimeout +import kotlinx.coroutines.withTimeoutOrNull import java.util.concurrent.LinkedBlockingDeque class AppStateMachineImpl( @@ -231,7 +253,11 @@ class AppStateMachineImpl( wakeLock = null sendEvent(InternalEvent.Destroy) - runBlocking(coroutineScope.coroutineContext) { withTimeout(1000) { httpServer.destroy().await() } } + try { + runBlocking(coroutineScope.coroutineContext) { withTimeout(1000) { httpServer.destroy().await() } } + } catch (cause: Throwable) { + XLog.e(getLog("destroy"), cause) + } broadcastHelper.stopListening() connectivityHelper.stopListening() coroutineScope.cancel()