MCPcopy
hub / github.com/docker/docker-agent / init

Method init

pkg/tui/tui.go:629–673  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

627}
628
629func (m *appModel) init() tea.Cmd {
630 shutdownCmd := m.contextShutdownCmd()
631 // If a different tab should be active on startup, switch to it directly.
632 // The initial tab's pending restore stays lazy — it will be loaded via
633 // handleSwitchTab when the user eventually opens it, just like every
634 // other non-active restored tab.
635 if m.pendingActiveTab != "" {
636 tabID := m.pendingActiveTab
637 m.pendingActiveTab = ""
638 _, switchCmd := m.handleSwitchTab(tabID)
639 return tea.Batch(m.dialogMgr.Init(), switchCmd, shutdownCmd)
640 }
641
642 // If the initial tab has a pending session restore, go through
643 // replaceActiveSession — the same code path as the /sessions command.
644 activeID := m.supervisor.ActiveID()
645 if oldSessionID, ok := m.pendingRestores[activeID]; ok {
646 delete(m.pendingRestores, activeID)
647 if store := m.application.SessionStore(); store != nil {
648 if sess, err := store.GetSession(m.ctx(), oldSessionID); err == nil {
649 _, cmd := m.replaceActiveSession(m.ctx(), sess)
650
651 if m.tuiStore != nil && sess.WorkingDir != "" {
652 if err := m.tuiStore.UpdateTabWorkingDir(m.ctx(), oldSessionID, sess.WorkingDir); err != nil {
653 slog.Warn("Failed to update persisted working dir", "error", err)
654 }
655 }
656
657 cmd = tea.Batch(cmd, m.applySidebarCollapsed(activeID))
658 m.persistActiveTab(sess.ID)
659
660 return tea.Batch(m.dialogMgr.Init(), cmd, shutdownCmd)
661 }
662 }
663 }
664
665 return tea.Batch(
666 shutdownCmd,
667 m.dialogMgr.Init(),
668 m.chatPage.Init(),
669 m.editor.Init(),
670 m.editor.Focus(),
671 m.application.SendFirstMessage(),
672 )
673}
674
675// Update handles messages. It wraps update so the getting-started tour can
676// observe every message that flows through the TUI (to detect completed

Callers 1

InitMethod · 0.95

Calls 14

contextShutdownCmdMethod · 0.95
handleSwitchTabMethod · 0.95
replaceActiveSessionMethod · 0.95
applySidebarCollapsedMethod · 0.95
persistActiveTabMethod · 0.95
BatchMethod · 0.80
ActiveIDMethod · 0.80
UpdateTabWorkingDirMethod · 0.80
WarnMethod · 0.80
SendFirstMessageMethod · 0.80
InitMethod · 0.65
SessionStoreMethod · 0.65

Tested by

no test coverage detected