From 5f52cff8cf360d2f2f73ec8fabcf5629f23a1614 Mon Sep 17 00:00:00 2001 From: ehoeve786 <41032835+ehoeve786@users.noreply.github.com> Date: Sun, 1 Nov 2026 09:45:50 -0700 Subject: [PATCH] Open the host that was tapped, not the one the tab showed last The Files and Terminal tabs restore their pager page when reopened, and the pager made whatever page it settled on the current host. So tapping Files (or Terminal) on a host in the Hosts list was overridden by the page the tab showed before, usually the last host connected. The restored page is now ignored; only a page change after that selects a host. Co-Authored-By: Claude Opus 5.5 --- app/src/main/java/com/secrm/ui/HostPager.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/secrm/ui/HostPager.kt b/app/src/main/java/com/secrm/ui/HostPager.kt index 198d307..739feb2 100644 --- a/app/src/main/java/com/secrm/ui/HostPager.kt +++ b/app/src/main/java/com/secrm/ui/HostPager.kt @@ -22,6 +22,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.PointerEventPass import androidx.compose.ui.input.pointer.pointerInput @@ -30,6 +31,7 @@ import androidx.compose.ui.platform.LocalViewConfiguration import androidx.compose.ui.unit.dp import com.secrm.HostSession import com.secrm.SecureRemoteApp +import kotlinx.coroutines.flow.drop import kotlinx.coroutines.launch import kotlin.math.abs @@ -45,7 +47,12 @@ fun HostPager(app: SecureRemoteApp, hosts: List, content: @Composab val pager = rememberPagerState(initialPage = index) { hosts.size } val scope = rememberCoroutineScope() LaunchedEffect(index) { if (pager.currentPage != index) pager.animateScrollToPage(index) } - LaunchedEffect(pager.settledPage) { hosts.getOrNull(pager.settledPage)?.let { app.sessions.select(it.name) } } + // The first page is skipped: it is the page the tab showed last time (restored with the tab), or the page it was on + // when the host list changed, not a swipe. Selecting it would replace the host just tapped on the Hosts screen with + // whichever one the tab showed before. + LaunchedEffect(pager, hosts) { + snapshotFlow { pager.settledPage }.drop(1).collect { page -> hosts.getOrNull(page)?.let { app.sessions.select(it.name) } } + } Column(Modifier.fillMaxSize()) { HorizontalPager(