desktop: close remote host connecting screen on stop of host (#3440)

This commit is contained in:
Stanislav Dmitrenko 2023-11-24 03:49:53 +08:00 committed by GitHub
parent 4d3529a3e0
commit f7903c5c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

View File

@ -113,7 +113,7 @@ object ChatModel {
val currentRemoteHost = mutableStateOf<RemoteHostInfo?>(null)
val remoteHostId: Long? @Composable get() = remember { currentRemoteHost }.value?.remoteHostId
fun remoteHostId(): Long? = currentRemoteHost.value?.remoteHostId
val newRemoteHostPairing = mutableStateOf<Pair<RemoteHostInfo?, RemoteHostSessionState>?>(null)
val remoteHostPairing = mutableStateOf<Pair<RemoteHostInfo?, RemoteHostSessionState>?>(null)
val remoteCtrlSession = mutableStateOf<RemoteCtrlSession?>(null)
fun getUser(userId: Long): User? = if (currentUser.value?.userId == userId) {

View File

@ -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() })

View File

@ -235,7 +235,7 @@ private fun showAddingMobileDevice(connecting: MutableState<Boolean>) {
ModalManager.start.showModalCloseable { close ->
val invitation = rememberSaveable { mutableStateOf<String?>(null) }
val port = rememberSaveable { mutableStateOf<String?>(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<Boolean>) {
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<Boolean>) {
chatController.stopRemoteHost(null)
}
}
chatModel.newRemoteHostPairing.value = null
chatModel.remoteHostPairing.value = null
}
}
}
@ -287,7 +288,7 @@ private fun showAddingMobileDevice(connecting: MutableState<Boolean>) {
private fun showConnectMobileDevice(rh: RemoteHostInfo, connecting: MutableState<Boolean>) {
ModalManager.start.showModalCloseable { close ->
val pairing = remember { chatModel.newRemoteHostPairing }
val pairing = remember { chatModel.remoteHostPairing }
val invitation = rememberSaveable { mutableStateOf<String?>(null) }
val port = rememberSaveable { mutableStateOf<String?>(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
}
}
}