Skip to content

Commit fd55a2c

Browse files
committed
chore: document how TBX handles UI events
1 parent 25e6c44 commit fd55a2c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/kotlin/com/coder/toolbox/CoderToolboxContext.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ data class CoderToolboxContext(
9696
* Forces the title bar on the main page to be refreshed
9797
*/
9898
suspend fun refreshMainPage() {
99+
// the url/title on the main page is only refreshed if
100+
// we're navigating to the main env page from another page.
101+
// If TBX is already on the main page the title is not refreshed
102+
// hence we force a navigation from a blank page.
99103
ui.showUiPage(CoderPage.emptyPage(this))
104+
105+
106+
// Toolbox uses an internal shared flow with a buffer of 4 items and a DROP_OLDEST strategy.
107+
// Both showUiPage and showPluginEnvironmentsPage send events to this flow.
108+
// If we emit two events back-to-back, the first one often gets dropped and only the second is shown.
109+
// To reduce this risk, we add a small delay to let the UI coroutine process the first event.
110+
// Simply yielding the coroutine isn't reliable, especially right after Toolbox starts via URI handling.
111+
// Based on my testing, a 5–10 ms delay is enough to ensure the blank page is processed,
112+
// while still short enough to be invisible to users.
100113
delay(10.milliseconds)
101114
envPageManager.showPluginEnvironmentsPage()
102115
}

0 commit comments

Comments
 (0)