Working on Editing

This commit is contained in:
2026-02-18 21:43:50 -06:00
parent 4066197ec1
commit 94fab7acee
2 changed files with 128 additions and 65 deletions

View File

@@ -261,6 +261,7 @@ func (s *ScreenHome) initMenu() {
s.menuLayout.AddMenuItems(
s.menuLayout.CreateMenuItem("file", "File", nil, 'f',
s.menuLayout.CreateMenuItem("file.openpds", "Open PDS", s.menuOpenPds, 'o'),
s.menuLayout.CreateMenuItem("file.authpds", "Authenticate PDS", s.menuAuthPds, 'a'),
s.menuLayout.CreateMenuItem("file.reloadpds", "Reload PDS", s.menuRefreshPds, 'r'),
s.menuLayout.CreateMenuItem("file.exit", "Exit", s.menuExit, 'x'),
),
@@ -292,11 +293,16 @@ func (s *ScreenHome) update() {
}
recNmInf.SetLabel(fmt.Sprintf("%s Infer Record Names", wrk))
miAuth := s.menuLayout.FindItem("file.authpds")
miReload := s.menuLayout.FindItem("file.reloadpds")
if s.activePds == nil {
miAuth.SetDisabled(true)
miAuth.SetStyle(s.style.Foreground(tcell.ColorGray))
miReload.SetDisabled(true)
miReload.SetStyle(s.style.Foreground(tcell.ColorGray))
} else {
miAuth.SetDisabled(true)
miAuth.SetStyle(s.style.Foreground(tcell.ColorGray))
miReload.SetDisabled(false)
miReload.SetStyle(s.style.Foreground(tcell.ColorLime))
}
@@ -344,43 +350,7 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
return true
}
func (s *ScreenHome) cliAuthPds(args ...string) bool {
if s.activePds == nil {
s.Log("No active PDS.")
return true
}
s.isLoading = true
go func() {
defer func() { s.isLoading = false }()
// Check if we already have authentication.
if !s.r.Auth.HasAuth(s.activePds.Did) {
atid := s.activePds.AtId.String()
callbackRes := make(chan url.Values, 1)
listenPort, err := s.r.Auth.ListenForCallback(callbackRes)
if err != nil {
s.Log("Error Instantiating HTTP Server for Callback: %w", err)
return
}
s.Log("Listening on %d", listenPort)
_, err = s.r.Auth.StartAuthFlow(listenPort, atid, callbackRes)
if err != nil {
s.Log("Error starting auth flow: %w", err)
} else {
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:\nhttp://localhost:%d/auth\nThis url will redirect to the PDS OAuth Page.", listenPort))
s.alert.SetVisible(true)
s.alert.SetActive(true)
go func() {
for s.isLoading {
time.Sleep(100)
}
s.alert.SetVisible(false)
}()
}
}
}()
return true
}
func (s *ScreenHome) cliAuthPds(args ...string) bool { return s.menuAuthPds() }
func (s *ScreenHome) cliBackupPds(args ...string) bool {
if s.activePds == nil {
@@ -480,9 +450,9 @@ func (s *ScreenHome) changePdsList(tn *wd.TreeNode) bool {
auth := s.r.Auth.HasAuth(s.activePds.Did)
if auth {
if tn.Depth() == 0 {
s.pdsListing.SetHintText("(A)dd New Record")
s.pdsListing.SetHintText("┤ Ctrl+A: Add New Record")
} else {
s.pdsListing.SetHintText("(A)dd New Record; (D)elete Record")
s.pdsListing.SetHintText("┤ Ctrl+A: Add New Record │ Ctrl+D: Delete Record")
}
}
@@ -517,6 +487,45 @@ func (s *ScreenHome) updateJsonView(tn *wd.TreeNode) bool {
return true
}
func (s *ScreenHome) menuAuthPds() bool {
s.menuLayout.HideMenu()
if s.activePds == nil {
s.Log("No active PDS.")
return true
}
s.isLoading = true
go func() {
defer func() { s.isLoading = false }()
// Check if we already have authentication.
if !s.r.Auth.HasAuth(s.activePds.Did) {
atid := s.activePds.AtId.String()
callbackRes := make(chan url.Values, 1)
listenPort, err := s.r.Auth.ListenForCallback(callbackRes)
if err != nil {
s.Log("Error Instantiating HTTP Server for Callback: %w", err)
return
}
s.Log("Listening on %d", listenPort)
_, err = s.r.Auth.StartAuthFlow(listenPort, atid, callbackRes)
if err != nil {
s.Log("Error starting auth flow: %w", err)
} else {
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:\nhttp://localhost:%d/auth\nThis url will redirect to the PDS OAuth Page.", listenPort))
s.alert.SetVisible(true)
s.alert.SetActive(true)
go func() {
for s.isLoading {
time.Sleep(100)
}
s.alert.SetVisible(false)
}()
}
}
}()
return true
}
func (s *ScreenHome) menuOpenPds() bool {
s.menuLayout.HideMenu()
s.doOpen = true