Skip to content

Commit

Permalink
pam/nativemodel: Send qrcode info as a single info message
Browse files Browse the repository at this point in the history
Send the qrcode info message as a single item so that UIs such as GNOME
shell can handle this properly
  • Loading branch information
3v1n0 committed Jul 4, 2024
1 parent 4debbb5 commit fb9bb81
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions pam/internal/adapter/nativemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,29 +586,24 @@ func (m nativeModel) handleQrCode() tea.Cmd {
})
}

if cmd := maybeSendPamError(m.sendInfo(m.uiLayout.GetLabel())); cmd != nil {
return cmd
}
var qrcodeView []string
qrcodeView = append(qrcodeView, m.uiLayout.GetLabel())

qrcode := m.renderQrCode(qrCode)
if cmd := maybeSendPamError(m.sendInfo(qrcode)); cmd != nil {
return cmd
}
qrcodeView = append(qrcodeView, qrcode)

firstQrCodeLine := strings.SplitN(qrcode, "\n", 2)[0]
centeredContent := centerString(m.uiLayout.GetContent(), firstQrCodeLine)
if cmd := maybeSendPamError(m.sendInfo(centeredContent)); cmd != nil {
return cmd
}
qrcodeView = append(qrcodeView, centeredContent)

if code := m.uiLayout.GetCode(); code != "" {
if cmd := maybeSendPamError(m.sendInfo(centerString(code, firstQrCodeLine))); cmd != nil {
return cmd
}
qrcodeView = append(qrcodeView, centerString(code, firstQrCodeLine))
}

// Ass some extra vertical space to improve readability
if cmd := maybeSendPamError(m.sendInfo(" ")); cmd != nil {
qrcodeView = append(qrcodeView, " ")

if cmd := maybeSendPamError(m.sendInfo(strings.Join(qrcodeView, "\n"))); cmd != nil {
return cmd
}

Expand Down

0 comments on commit fb9bb81

Please sign in to comment.