Skip to content

Commit 6a1908b

Browse files
committed
fix: show connect page in the URI handler
If Toolbox is already opened and URI is executed the setup page from below is never called. I tried a couple of things, including yielding the coroutine - but it seems to be of no help. What works delaying the coroutine for 66 - to 100 milliseconds, these numbers were determined by trial and error. The only explanation that I have is that inspecting the TBX bytecode it seems the UI event is emitted via MutableSharedFlow(replay = 0) which has a buffer of 4 events and a drop oldest strategy. For some reason it seems that the UI collector is not yet active, causing the event to be lost unless we wait > 66 ms. I think this delay ensures the collector is ready before processEvent() is called.
1 parent b7e3073 commit 6a1908b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 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,

0 commit comments

Comments
 (0)