fix: refresh mutations and defer busy quit
This commit is contained in:
+30
-5
@@ -41,6 +41,7 @@ type Model struct {
|
||||
refreshing bool
|
||||
profileTransition bool
|
||||
progressTarget string
|
||||
quitRequested bool
|
||||
}
|
||||
|
||||
type targetOperationDone struct {
|
||||
@@ -76,10 +77,18 @@ func (m Model) Init() tea.Cmd { return nil }
|
||||
// operation start checks it, so a completion can only belong to the one current
|
||||
// operation rather than racing another operation for shared model state.
|
||||
func (m Model) busy() bool {
|
||||
return m.applying || m.refreshing || m.profileTransition || m.pendingActivation.Kind != 0
|
||||
return m.operationInFlight() || m.pendingActivation.Kind != 0
|
||||
}
|
||||
|
||||
func (m Model) operationInFlight() bool {
|
||||
return m.applying || m.refreshing || m.profileTransition
|
||||
}
|
||||
|
||||
func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if key, ok := message.(tea.KeyMsg); ok && m.operationInFlight() && isQuitKey(key) {
|
||||
m.quitRequested = true
|
||||
return m, nil
|
||||
}
|
||||
if completed, ok := message.(refreshDone); ok {
|
||||
if !m.refreshing {
|
||||
return m, nil
|
||||
@@ -99,7 +108,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||
} else if m.selected >= targetCount {
|
||||
m.selected = targetCount - 1
|
||||
}
|
||||
return m, nil
|
||||
return m, m.deferredQuit()
|
||||
}
|
||||
if progress, ok := message.(profileOperationProgress); ok {
|
||||
if !m.profileTransition {
|
||||
@@ -120,7 +129,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||
intent := m.pendingActivation
|
||||
m.profileConfirm = &intent
|
||||
m.status = progress.result.Confirmation
|
||||
return m, nil
|
||||
return m, m.deferredQuit()
|
||||
}
|
||||
if progress.result.Err != nil {
|
||||
m.status = "\x1b[31mError: " + progress.result.Err.Error() + "\x1b[0m"
|
||||
@@ -132,7 +141,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.profileTransition = false
|
||||
m.progressTarget = ""
|
||||
m.pendingActivation = app.Intent{}
|
||||
return m, nil
|
||||
return m, m.deferredQuit()
|
||||
}
|
||||
return m, waitForProfileProgress(progress.updates)
|
||||
}
|
||||
@@ -156,7 +165,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.targetConfirm = nil
|
||||
m.status = completed.result.Notice
|
||||
}
|
||||
return m, nil
|
||||
return m, m.deferredQuit()
|
||||
}
|
||||
key, ok := message.(tea.KeyMsg)
|
||||
if !ok {
|
||||
@@ -179,6 +188,22 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
func isQuitKey(key tea.KeyMsg) bool {
|
||||
switch key.String() {
|
||||
case "q", "esc", "ctrl+c":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) deferredQuit() tea.Cmd {
|
||||
if m.quitRequested {
|
||||
return tea.Quit
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if m.targetConfirm != nil && !m.busy() {
|
||||
switch key.String() {
|
||||
|
||||
Reference in New Issue
Block a user