@@ -76,6 +76,10 @@ class PcConnectionViewModel(
7676
7777 private val rowStatuses = MutableStateFlow <Map <String , PcRowStatus >>(emptyMap())
7878
79+ // Bumped on every token store mutation so the combine pipeline re-reads
80+ // token-derived state (saved pairings, row actions); the store itself is not observable.
81+ private val tokenRevision = MutableStateFlow (0 )
82+
7983 private data class DiscoveryInputs (
8084 val pcs : List <DiscoveredPc >,
8185 val status : PcDiscoveryStatus ,
@@ -85,7 +89,7 @@ class PcConnectionViewModel(
8589
8690 init {
8791 viewModelScope.launch {
88- combine(discoveryService.pcs, discoveryService.status, rowStatuses, PcConnectionStateHolder .connectionState) { pcs, status, statuses, connection ->
92+ combine(discoveryService.pcs, discoveryService.status, rowStatuses, PcConnectionStateHolder .connectionState, tokenRevision ) { pcs, status, statuses, connection, _ ->
8993 DiscoveryInputs (pcs, status, statuses, connection)
9094 }.collect { inputs ->
9195 val connectedDesktopId = (inputs.connection as ? PcConnectionState .Connected )?.session?.desktopId
@@ -145,6 +149,7 @@ class PcConnectionViewModel(
145149 when (val ping = connector.authenticatedPing(pc, pairing.token)) {
146150 is PcPingResult .Connected -> {
147151 tokenStore.saveToken(pc.desktopId, pairing.token, ping.websocketUrl, pc.displayName)
152+ tokenRevision.update { it + 1 }
148153 PcConnectionStateHolder .setConnected(
149154 PcAuthenticatedSession (pc.desktopId, identityRepository.getDeviceId(), ping.websocketUrl),
150155 pc.displayName
@@ -153,6 +158,7 @@ class PcConnectionViewModel(
153158 }
154159 is PcPingResult .AuthFailed -> {
155160 tokenStore.clearToken(pc.desktopId)
161+ tokenRevision.update { it + 1 }
156162 PcConnectionStateHolder .setDisconnected()
157163 setIdle(pc.desktopId, PcRowStatus .Failed , ping.message)
158164 }
@@ -175,6 +181,7 @@ class PcConnectionViewModel(
175181 when (val result = connector.authenticatedPing(pc, token)) {
176182 is PcPingResult .Connected -> {
177183 tokenStore.saveToken(pc.desktopId, token, result.websocketUrl, pc.displayName)
184+ tokenRevision.update { it + 1 }
178185 PcConnectionStateHolder .setConnected(
179186 PcAuthenticatedSession (pc.desktopId, identityRepository.getDeviceId(), result.websocketUrl),
180187 pc.displayName
@@ -183,6 +190,7 @@ class PcConnectionViewModel(
183190 }
184191 is PcPingResult .AuthFailed -> {
185192 tokenStore.clearToken(pc.desktopId)
193+ tokenRevision.update { it + 1 }
186194 PcConnectionStateHolder .setDisconnected()
187195 setIdle(pc.desktopId, PcRowStatus .Failed , result.message)
188196 }
@@ -208,6 +216,7 @@ class PcConnectionViewModel(
208216 fun confirmUnpair () {
209217 val unpair = _uiState .value.pendingUnpair ? : return
210218 tokenStore.clearToken(unpair.desktopId)
219+ tokenRevision.update { it + 1 }
211220 val connected = PcConnectionStateHolder .connectionState.value as ? PcConnectionState .Connected
212221 if (connected?.session?.desktopId == unpair.desktopId) {
213222 PcConnectionStateHolder .setDisconnected()
0 commit comments