fix: make target progress reflect fresh state

This commit is contained in:
proxyctl coordinator
2026-07-17 09:21:36 +08:00
parent fd113fb316
commit fb456f35e4
6 changed files with 198 additions and 40 deletions
+23 -9
View File
@@ -38,6 +38,7 @@ type Model struct {
pendingActivation app.Intent
status string
applying bool
refreshing bool
profileTransition bool
progressTarget string
}
@@ -46,6 +47,10 @@ type targetOperationDone struct {
result app.Result
}
type refreshDone struct {
result app.Result
}
type profileOperationProgress struct {
result app.Result
updates <-chan app.Result
@@ -68,6 +73,19 @@ func NewModel(application app.Module) Model {
func (m Model) Init() tea.Cmd { return nil }
func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
if completed, ok := message.(refreshDone); ok {
m.refreshing = false
m.snapshot = completed.result.Snapshot
if completed.result.Err != nil {
m.status = "\x1b[31mError: " + completed.result.Err.Error() + "\x1b[0m"
} else {
m.status = completed.result.Notice
}
if m.selected >= len(m.availableTargets()) && m.selected > 0 {
m.selected--
}
return m, nil
}
if progress, ok := message.(profileOperationProgress); ok {
m.snapshot = progress.result.Snapshot
m.progressTarget = ""
@@ -166,15 +184,11 @@ func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
m.page = helpPage
m.status = ""
case "r":
if !m.applying {
result := m.application.Dispatch(app.Intent{Kind: app.RefreshTargets})
m.snapshot = result.Snapshot
m.status = result.Notice
if result.Err != nil {
m.status = "Error: " + result.Err.Error()
}
if m.selected >= len(m.availableTargets()) && m.selected > 0 {
m.selected--
if !m.applying && !m.refreshing {
m.refreshing = true
m.status = "Refreshing Target availability and state…"
return m, func() tea.Msg {
return refreshDone{result: m.application.Dispatch(app.Intent{Kind: app.RefreshTargets})}
}
}
case "up", "k":