Fix latency issue

This commit is contained in:
Martin Pander
2026-09-11 13:17:04 +02:00
parent 6b1418fc71
commit 6fbe575471
4 changed files with 26 additions and 17 deletions

View File

@@ -34,7 +34,9 @@ func NewMainPage(common *common.Common) *MainPage {
}
func (m *MainPage) Init() tea.Cmd {
return tea.Batch(m.taskPage.Init(), m.timePage.Init())
// Initialize only the visible page. Messages from commands started for an
// inactive page would be routed to the active page and discarded.
return tea.Batch(m.activePage.Init(), doTick())
}
func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -57,6 +59,14 @@ func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.activePage = activePage.(common.Component)
return m, cmd
case tickMsg:
// Own the single application tick loop here. Pages only react to ticks;
// allowing each page and refresh action to schedule another tick creates
// duplicate loops and eventually floods the CLI wrappers with requests.
activePage, cmd := m.activePage.Update(msg)
m.activePage = activePage.(common.Component)
return m, tea.Batch(cmd, doTick())
case tea.KeyMsg:
// Only handle tab key for page switching when at the top level (no subpages active)
if key.Matches(msg, m.common.Keymap.Next) && !m.common.HasSubpages() {