Skip to content

Commit 81921d7

Browse files
authored
Improve uri handling workflow (#214)
This PR addresses two issues in the URI handler workflow to improve user experience and reliability. 1. Streamline version fallback behavior Problem: When the URI handler receives a build number that is no longer available, the application would fall back to the latest version but display a confirmation dialog. Netflix reported that this confirmation dialog disrupts the user workflow. Solution: Removed the confirmation dialog and replaced it with logging. The handler now silently falls back to the latest available version when the requested build number is unavailable, maintaining a seamless user experience. 2. Fix connect page not displaying when Toolbox is already open Problem: When Toolbox is already running and a URI is executed, the connect page fails to display. Investigation revealed that the UI event emitted via MutableSharedFlow(replay = 0) is lost because the UI collector is not yet active when processEvent() is called. Solution: Introduced a 66-100ms delay before emitting the UI event. This delay ensures the collector is ready to receive events, preventing them from being dropped. The timing was determined through testing and appears to account for the collector initialization time. Note: The delay in fix #2 is a workaround for what appears to be a timing issue with the MutableSharedFlow collector initialization.
1 parent 3ac53e8 commit 81921d7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## Unreleased
44

5+
### Changed
6+
7+
- URI handling no longer waits for confirmation to use latest build if the provided build number is too old
8+
9+
### Fixed
10+
11+
- IDE is now launched when URI is handled by an already running Toolbox instance.
12+
513
## 0.7.1 - 2025-10-13
614

715
### Fixed

src/main/kotlin/com/coder/toolbox/util/CoderProtocolHandler.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import kotlinx.coroutines.time.withTimeout
2626
import java.net.URI
2727
import java.util.UUID
2828
import kotlin.time.Duration
29+
import kotlin.time.Duration.Companion.milliseconds
2930
import kotlin.time.Duration.Companion.minutes
3031
import kotlin.time.Duration.Companion.seconds
3132
import kotlin.time.toJavaDuration
@@ -111,6 +112,18 @@ open class CoderProtocolHandler(
111112
CoderCliSetupContext.token = token
112113
}
113114
CoderCliSetupWizardState.goToStep(WizardStep.CONNECT)
115+
116+
// If Toolbox is already opened and URI is executed the setup page
117+
// from below is never called. I tried a couple of things, including
118+
// yielding the coroutine - but it seems to be of no help. What works
119+
// delaying the coroutine for 66 - to 100 milliseconds, these numbers
120+
// were determined by trial and error.
121+
// The only explanation that I have is that inspecting the TBX bytecode it seems the
122+
// UI event is emitted via MutableSharedFlow(replay = 0) which has a buffer of 4 events
123+
// and a drop oldest strategy. For some reason it seems that the UI collector
124+
// is not yet active, causing the event to be lost unless we wait > 66 ms.
125+
// I think this delay ensures the collector is ready before processEvent() is called.
126+
delay(100.milliseconds)
114127
context.ui.showUiPage(
115128
CoderCliSetupWizardPage(
116129
context, settingsPage, visibilityState, true,
@@ -369,10 +382,7 @@ open class CoderProtocolHandler(
369382
val buildNumberIsNotAvailable = availableVersions.firstOrNull { it.contains(buildNumber) } == null
370383
if (buildNumberIsNotAvailable) {
371384
val selectedIde = availableVersions.maxOf { it }
372-
context.logAndShowInfo(
373-
"$productCode-$buildNumber not available",
374-
"$productCode-$buildNumber is not available, we've selected the latest $selectedIde"
375-
)
385+
context.logger.info("$productCode-$buildNumber is not available, we've selected the latest $selectedIde")
376386
return selectedIde
377387
}
378388
return "$productCode-$buildNumber"

0 commit comments

Comments
 (0)