okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffeat(api)!: migrate daemon and clients to protocol 361c43ca

main
1.4 KiB47 linesraw
1package tui
2
3import (
4	"fmt"
5
6	tea "charm.land/bubbletea/v2"
7)
8
9// Sign-in startup can finish after its screen closes. Cleanup must still run;
10// credential mutation outcomes remain visible without selecting a stale flow.
11func (m *AppModel) handleLoginOutcome(msg tea.Msg) (bool, tea.Cmd) {
12	switch result := msg.(type) {
13	case signInStartedMsg, signInStatusMsg, signInPollMsg:
14		var cmd tea.Cmd
15		m.Login, cmd = m.Login.Update(msg)
16		return true, cmd
17	case providerSavedMsg:
18		if m.State == AppStateLogin && !m.Login.closed && result.Gen == m.Login.Generation {
19			return false, nil
20		}
21		if result.Err != nil {
22			message := operationError(result.Err, "Provider update failed: ", "Provider update may have been accepted; check your accounts before trying again.")
23			m.AddError(message)
24			if m.State == AppStateLogin {
25				m.Login.Error = message
26			}
27		} else {
28			m.AddNotice(fmt.Sprintf("Provider %s saved.", result.Name))
29		}
30		return true, nil
31	case signInsLoadedMsg:
32		if !result.Mutation || m.State == AppStateLogin && !m.Login.closed && result.Gen == m.Login.Generation {
33			return false, nil
34		}
35		if result.Err != nil {
36			message := operationError(result.Err, "Account update failed: ", "Account update may have been accepted; check your accounts before trying again.")
37			m.AddError(message)
38			if m.State == AppStateLogin {
39				m.Login.Error = message
40			}
41		} else {
42			m.AddNotice("Account update saved.")
43		}
44		return true, nil
45	}
46	return false, nil
47}