From f7903c5c83329d6bd1a8d28e082cc3583acff414 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Fri, 24 Nov 2023 03:49:53 +0800 Subject: [PATCH] desktop: close remote host connecting screen on stop of host (#3440) --- .../kotlin/chat/simplex/common/model/ChatModel.kt | 2 +- .../kotlin/chat/simplex/common/model/SimpleXAPI.kt | 4 ++-- .../simplex/common/views/remote/ConnectMobileView.kt | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index 6739cdee7..18eba71fb 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -113,7 +113,7 @@ object ChatModel { val currentRemoteHost = mutableStateOf(null) val remoteHostId: Long? @Composable get() = remember { currentRemoteHost }.value?.remoteHostId fun remoteHostId(): Long? = currentRemoteHost.value?.remoteHostId - val newRemoteHostPairing = mutableStateOf?>(null) + val remoteHostPairing = mutableStateOf?>(null) val remoteCtrlSession = mutableStateOf(null) fun getUser(userId: Long): User? = if (currentUser.value?.userId == userId) { 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 8f837e1c5..5a706efe6 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 @@ -1836,7 +1836,7 @@ object ChatController { is CR.GroupMemberRatchetSync -> chatModel.updateGroupMemberConnectionStats(rhId, r.groupInfo, r.member, r.ratchetSyncProgress.connectionStats) is CR.RemoteHostSessionCode -> { - chatModel.newRemoteHostPairing.value = r.remoteHost_ to RemoteHostSessionState.PendingConfirmation(r.sessionCode) + chatModel.remoteHostPairing.value = r.remoteHost_ to RemoteHostSessionState.PendingConfirmation(r.sessionCode) } is CR.RemoteHostConnected -> { // TODO needs to update it instead in sessions @@ -1845,7 +1845,7 @@ object ChatController { } is CR.RemoteHostStopped -> { val disconnectedHost = chatModel.remoteHosts.firstOrNull { it.remoteHostId == r.remoteHostId_ } - chatModel.newRemoteHostPairing.value = null + chatModel.remoteHostPairing.value = null if (disconnectedHost != null) { showToast( generalGetString(MR.strings.remote_host_was_disconnected_toast).format(disconnectedHost.hostDeviceName.ifEmpty { disconnectedHost.remoteHostId.toString() }) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/remote/ConnectMobileView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/remote/ConnectMobileView.kt index 163d15ce6..a22cbfd9b 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/remote/ConnectMobileView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/remote/ConnectMobileView.kt @@ -235,7 +235,7 @@ private fun showAddingMobileDevice(connecting: MutableState) { ModalManager.start.showModalCloseable { close -> val invitation = rememberSaveable { mutableStateOf(null) } val port = rememberSaveable { mutableStateOf(null) } - val pairing = remember { chatModel.newRemoteHostPairing } + val pairing = remember { chatModel.remoteHostPairing } val sessionCode = when (val state = pairing.value?.second) { is RemoteHostSessionState.PendingConfirmation -> state.sessionCode else -> null @@ -271,6 +271,7 @@ private fun showAddingMobileDevice(connecting: MutableState) { connecting.value = true invitation.value = r.second port.value = r.third + chatModel.remoteHostPairing.value = null to RemoteHostSessionState.Starting } } onDispose { @@ -279,7 +280,7 @@ private fun showAddingMobileDevice(connecting: MutableState) { chatController.stopRemoteHost(null) } } - chatModel.newRemoteHostPairing.value = null + chatModel.remoteHostPairing.value = null } } } @@ -287,7 +288,7 @@ private fun showAddingMobileDevice(connecting: MutableState) { private fun showConnectMobileDevice(rh: RemoteHostInfo, connecting: MutableState) { ModalManager.start.showModalCloseable { close -> - val pairing = remember { chatModel.newRemoteHostPairing } + val pairing = remember { chatModel.remoteHostPairing } val invitation = rememberSaveable { mutableStateOf(null) } val port = rememberSaveable { mutableStateOf(null) } val sessionCode = when (val state = pairing.value?.second) { @@ -315,6 +316,7 @@ private fun showConnectMobileDevice(rh: RemoteHostInfo, connecting: MutableState remoteHostId = rh_?.remoteHostId invitation.value = inv port.value = r.third + chatModel.remoteHostPairing.value = null to RemoteHostSessionState.Starting } } LaunchedEffect(remember { chatModel.currentRemoteHost }.value) { @@ -334,7 +336,7 @@ private fun showConnectMobileDevice(rh: RemoteHostInfo, connecting: MutableState chatController.stopRemoteHost(remoteHostId) } } - chatModel.newRemoteHostPairing.value = null + chatModel.remoteHostPairing.value = null } } }