From 805d9377c8097265cea22bae33981fde39fae587 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Mon, 11 Aug 2025 17:12:05 +0100 Subject: [PATCH] android, desktop: core API event timeout setting --- .../main/java/chat/simplex/app/SimplexService.kt | 2 +- .../kotlin/chat/simplex/common/model/SimpleXAPI.kt | 4 +++- .../common/views/usersettings/DeveloperView.kt | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt index 90e51c7528..68b24c513a 100644 --- a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt +++ b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt @@ -167,7 +167,7 @@ class SimplexService: Service() { } return null } - + private fun createServiceNotification(title: String, text: String): Notification { val pendingIntent: PendingIntent = Intent(this, MainActivity::class.java).let { notificationIntent -> PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 93cae0b787..9411b781ae 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -129,6 +129,7 @@ class AppPreferences { val showInternalErrors = mkBoolPreference(SHARED_PREFS_SHOW_INTERNAL_ERRORS, false) val showSlowApiCalls = mkBoolPreference(SHARED_PREFS_SHOW_SLOW_API_CALLS, false) val terminalAlwaysVisible = mkBoolPreference(SHARED_PREFS_TERMINAL_ALWAYS_VISIBLE, false) + val apiRecvTimeout = mkIntPreference(SHARED_PREFS_API_RECV_TIMEOUT, 15_000_000) val networkUseSocksProxy = mkBoolPreference(SHARED_PREFS_NETWORK_USE_SOCKS_PROXY, false) val networkShowSubscriptionPercentage = mkBoolPreference(SHARED_PREFS_NETWORK_SHOW_SUBSCRIPTION_PERCENTAGE, false) private val _networkProxy = mkStrPreference(SHARED_PREFS_NETWORK_PROXY_HOST_PORT, json.encodeToString(NetworkProxy())) @@ -402,6 +403,7 @@ class AppPreferences { private const val SHARED_PREFS_SHOW_INTERNAL_ERRORS = "ShowInternalErrors" private const val SHARED_PREFS_SHOW_SLOW_API_CALLS = "ShowSlowApiCalls" private const val SHARED_PREFS_TERMINAL_ALWAYS_VISIBLE = "TerminalAlwaysVisible" + private const val SHARED_PREFS_API_RECV_TIMEOUT = "EventPollTimeout" private const val SHARED_PREFS_NETWORK_USE_SOCKS_PROXY = "NetworkUseSocksProxy" private const val SHARED_PREFS_NETWORK_SHOW_SUBSCRIPTION_PERCENTAGE = "ShowSubscriptionPercentage" private const val SHARED_PREFS_NETWORK_PROXY_HOST_PORT = "NetworkProxyHostPort" @@ -787,7 +789,7 @@ object ChatController { } fun recvMsg(ctrl: ChatCtrl): API? { - val rStr = chatRecvMsgWait(ctrl, MESSAGE_TIMEOUT) + val rStr = chatRecvMsgWait(ctrl, appPrefs.apiRecvTimeout.get()) return if (rStr == "") { null } else { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/DeveloperView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/DeveloperView.kt index dcb71a552d..52ee30ff18 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/DeveloperView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/DeveloperView.kt @@ -2,9 +2,11 @@ package chat.simplex.common.views.usersettings import SectionBottomSpacer import SectionDividerSpaced +import SectionItemView import SectionTextFooter import SectionView import androidx.compose.runtime.* +import androidx.compose.runtime.snapshots.toInt import androidx.compose.ui.platform.LocalUriHandler import chat.simplex.common.model.ChatController.appPrefs import chat.simplex.common.platform.* @@ -12,6 +14,7 @@ import dev.icerock.moko.resources.compose.painterResource import dev.icerock.moko.resources.compose.stringResource import chat.simplex.common.views.TerminalView import chat.simplex.common.views.helpers.* +import chat.simplex.common.views.usersettings.networkAndServers.TimeoutSettingRow import chat.simplex.res.MR @Composable @@ -23,7 +26,11 @@ fun DeveloperView(withAuth: (title: String, desc: String, block: () -> Unit) -> AppBarTitle(stringResource(MR.strings.settings_developer_tools)) val developerTools = m.controller.appPrefs.developerTools val devTools = remember { developerTools.state } + val apiRecvTimeout = remember { mutableStateOf(chatModel.controller.appPrefs.apiRecvTimeout.get().toLong()) } val unchangedHints = mutableStateOf(unchangedHintPreferences()) + LaunchedEffect(apiRecvTimeout.value) { + chatModel.controller.appPrefs.apiRecvTimeout.set(apiRecvTimeout.value.toInt()) + } SectionView { InstallTerminalAppItem(uriHandler) ChatConsoleItem { withAuth(generalGetString(MR.strings.auth_open_chat_console), generalGetString(MR.strings.auth_log_in_using_credential)) { ModalManager.start.showModalCloseable { TerminalView(false) } } } @@ -57,6 +64,12 @@ fun DeveloperView(withAuth: (title: String, desc: String, block: () -> Unit) -> } SettingsPreferenceItem(painterResource(MR.images.ic_report), stringResource(MR.strings.show_internal_errors), appPreferences.showInternalErrors) SettingsPreferenceItem(painterResource(MR.images.ic_avg_pace), stringResource(MR.strings.show_slow_api_calls), appPreferences.showSlowApiCalls) + SectionItemView { + TimeoutSettingRow( + "Core API timeout", apiRecvTimeout, + listOf(15_000000, 60_000000, 180_000000, 600_000000, 1200_000000, 1800_000000), stringResource(MR.strings.network_option_seconds_label) + ) + } } } SectionDividerSpaced(maxTopPadding = true)