From 1b7dd6b6a0ca518fed6b64e22870d39b199e2d47 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Wed, 15 Oct 2025 17:24:43 -0400 Subject: [PATCH] refactor(login): remove unused field "view" --- internal/login/qr.go | 63 ++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/internal/login/qr.go b/internal/login/qr.go index 79770a0..92c3b2a 100644 --- a/internal/login/qr.go +++ b/internal/login/qr.go @@ -29,13 +29,12 @@ import ( const gatewayURL = "wss://remote-auth-gateway.discord.gg/?v=2" -var remoteAuthLogin = api.EndpointMe + "/remote-auth/login" +var endpointRemoteAuthLogin = api.EndpointMe + "/remote-auth/login" type qrLogin struct { *tview.TextView app *tview.Application cfg *config.Config - view *tview.TextView done func(token string, err error) conn *websocket.Conn privKey *rsa.PrivateKey @@ -44,43 +43,39 @@ type qrLogin struct { } func newQRLogin(app *tview.Application, cfg *config.Config, done func(token string, err error)) *qrLogin { - view := tview.NewTextView(). + q := &qrLogin{ + TextView: tview.NewTextView(), + app: app, + cfg: cfg, + done: done, + } + q.Box = ui.ConfigureBox(q.Box, &cfg.Theme) + + q. SetDynamicColors(true). SetScrollable(true). SetWrap(false). - SetTextAlign(tview.AlignmentCenter) - view.Box = ui.ConfigureBox(view.Box, &cfg.Theme) - view.SetTitle("Login with QR") - - q := &qrLogin{ - app: app, - cfg: cfg, - view: view, - done: done, - } - q.TextView = view - - view.SetChangedFunc(func() { - q.app.QueueUpdateDraw(func() {}) - }) - - view.SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey { - if ev.Key() == tcell.KeyEsc { - q.stop() - if q.done != nil { - q.done("", nil) + SetTextAlign(tview.AlignmentCenter). + SetChangedFunc(func() { + q.app.QueueUpdateDraw(func() {}) + }). + SetTitle("Login with QR"). + SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey { + if ev.Key() == tcell.KeyEsc { + q.stop() + if q.done != nil { + q.done("", nil) + } + return nil } - return nil - } - return ev - }) + return ev + }) return q } - func (q *qrLogin) centerText(s string) string { - _, _, _, height := q.view.GetInnerRect() + _, _, _, height := q.GetInnerRect() if height == 0 { height = 40 } @@ -114,8 +109,8 @@ func (q *qrLogin) writeJSON(data any) error { } type raHello struct { - TimeoutMs int `json:"timeout_ms"` - HeartbeatInterval int `json:"heartbeat_interval"` + TimeoutMs int `json:"timeout_ms"` + HeartbeatInterval int `json:"heartbeat_interval"` } type raNonceProof struct { @@ -139,7 +134,7 @@ func (q *qrLogin) run(ctx context.Context) { setText := func(s string) { q.app.QueueUpdateDraw(func() { - q.view.SetText(q.centerText(s)) + q.SetText(q.centerText(s)) }) } @@ -395,7 +390,7 @@ func exchangeTicket(ctx context.Context, ticket string, fingerprint string, priv if err != nil { return "", err } - req, err := stdhttp.NewRequestWithContext(ctx, stdhttp.MethodPost, remoteAuthLogin, bytes.NewReader(raw)) + req, err := stdhttp.NewRequestWithContext(ctx, stdhttp.MethodPost, endpointRemoteAuthLogin, bytes.NewReader(raw)) if err != nil { return "", err }