Oauth. Car Backups.

This commit is contained in:
2026-02-04 17:01:54 -06:00
parent 486c07f2d4
commit 4ed5d821da
14 changed files with 524 additions and 62 deletions

View File

@@ -42,8 +42,6 @@ type App struct {
screen AppScreen
repo *data.Repo
AppLogs []data.AppLog
style tcell.Style
}

View File

@@ -22,7 +22,9 @@ THE SOFTWARE.
package app
import (
"context"
"fmt"
"net/url"
"strings"
"git.bullercodeworks.com/brian/expds/data"
@@ -42,6 +44,9 @@ type ScreenHome struct {
w, h int
style tcell.Style
alert *w.Alert
showAlert bool
menuLayout *w.TopMenuLayout
openPdsEntry *w.Field
@@ -66,8 +71,12 @@ type ScreenHome struct {
func (s *ScreenHome) Init(a *App) {
s.a, s.r = a, a.repo
s.r.SetLogFunc(s.Log)
s.style = a.style
s.alert = w.NewAlert("expds.alert", s.style)
s.openPdsEntry = w.NewField("home.openpds.field", s.style)
s.openPdsEntry.SetLabel("ID")
s.openPdsEntry.SetActive(true)
@@ -149,12 +158,16 @@ func (s *ScreenHome) GetName() string { return "home" }
func (s *ScreenHome) HandleResize(ev *tcell.EventResize) {
s.w, s.h = ev.Size()
s.menuLayout.HandleResize(w.Coord{X: s.w, Y: s.h - 1}.ResizeEvent())
s.alert.HandleResize(ev)
s.status.SetPos(w.Coord{X: 0, Y: s.h - 1})
s.status.HandleResize(w.Coord{X: s.w, Y: 1}.ResizeEvent())
}
func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
if s.showAlert {
return s.alert.HandleKey(ev)
}
if ev.Key() == tcell.KeyF12 {
s.toggleCli()
return true
@@ -201,6 +214,9 @@ func (s *ScreenHome) Draw() {
s.a.DrawWidget(s.loading)
}
s.a.DrawWidget(s.status)
if s.showAlert {
s.a.DrawWidget(s.alert)
}
}
func (s *ScreenHome) Exit() error { return nil }
func (s *ScreenHome) Log(t string, a ...any) {
@@ -293,6 +309,8 @@ func (s *ScreenHome) update() {
func (s *ScreenHome) initCli() {
s.cli.SetVisible(true)
s.cli.AddCommand(w.NewCliCommand("getpds", s.cliGetPds))
s.cli.AddCommand(w.NewCliCommand("authpds", s.cliAuthPds))
s.cli.AddCommand(w.NewCliCommand("backuppds", s.cliBackupPds))
}
func (s *ScreenHome) toggleCli() {
@@ -325,14 +343,13 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
return true
}
go func() {
defer func() { s.isLoading = false }()
pds, err := s.r.GetPDS(args[1])
if err != nil {
s.Log(err.Error())
s.isLoading = false
return
} else if pds == nil {
s.Log("PDS (%s) Not Found.", args[1])
s.isLoading = false
return
}
s.doOpen = false
@@ -346,7 +363,53 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
s.layout.ActivateWidget(s.columns)
s.columns.ActivateWidget(s.pdsListing)
s.isLoading = false
}()
return true
}
func (s *ScreenHome) cliAuthPds(args ...string) bool {
if s.activePds == nil {
s.Log("No active PDS.")
return true
}
s.isLoading = true
ctx := context.Background()
go func() {
defer func() { s.isLoading = false }()
atid := s.activePds.AtId.String()
callbackRes := make(chan url.Values, 1)
listenPort, err := s.r.Auth.ListenForCallback(ctx, callbackRes)
if err != nil {
s.Log("Error Instantiating HTTP Server for Callback: %w", err)
return
}
s.Log("Listening on %d", listenPort)
var authUrl string
authUrl, err = s.r.Auth.StartAuthFlow(listenPort, ctx, atid, callbackRes)
if err != nil {
s.Log("Error starting auth flow: %w", err)
}
s.alert.SetTitle("Authentication Started")
s.alert.SetMessage(fmt.Sprintf("OAuth Process Started.\nIf a browser window didn't open, you can open this URL manually:\n%s", authUrl))
s.showAlert = true
}()
return true
}
func (s *ScreenHome) cliBackupPds(args ...string) bool {
if s.activePds == nil {
s.Log("No active PDS.")
return true
}
s.isLoading = true
go func() {
defer func() { s.isLoading = false }()
nm, sz, err := s.activePds.Backup()
if err != nil {
s.Log("Error: %w", err)
return
}
s.Log("Backup Created: %s (%d bytes)", nm, sz)
}()
return true
}