Improve handling of missing user-IDs.

This commit is contained in:
gmp
2019-11-20 15:48:56 -05:00
parent 47ffd8f160
commit a1d9ffa6c6
5 changed files with 88 additions and 62 deletions
+4
View File
@@ -9,6 +9,10 @@ import (
"gioui.org/app"
)
var (
noidLabelText = "Enter a GPG key ID above"
)
func init() {
log(Info, "Android start")
// Use a larger font on Android
+4
View File
@@ -10,6 +10,10 @@ import (
"gioui.org/app"
)
var (
noidLabelText = "No GPG ids available. Please create a private key or enter a key ID above"
)
/*func setFont() error {
f, err := os.Open("/System/Library/Fonts/AppleSDGothicNeo.ttc")
if err != nil {
+80 -19
View File
@@ -126,7 +126,7 @@ var (
)
func Updater() {
time.Sleep(time.Second * 2)
//time.Sleep(time.Second * 2)
update := func() {
fmt.Printf("update()\n")
ltmp, err := store.List()
@@ -197,7 +197,7 @@ func eventLoop() {
app.Size(unit.Dp(250), unit.Dp(500)),
app.Title("passgo"))
gtx := &layout.Context{Queue: w.Queue()}
time.Sleep(time.Second/5)
//time.Sleep(time.Second/5)
var margincs layout.Constraints
@@ -254,12 +254,10 @@ func eventLoop() {
}
mux.Unlock()
}
updateBtns()
idBtns := make([]*Button, 0)
updateIdBtns := func() {
//return
log(Info,"passgo.Identities()")
ids, err := passgo.Identities()
if err != nil {
@@ -339,7 +337,7 @@ func eventLoop() {
passvalLabel := th.Label(unit.Sp(fontSize), "password value:")
passvalEd := &widget.Editor{ SingleLine: true, Submit: true }
noidLabel := th.Label(unit.Sp(fontSize), "No GPG ids available. Please create a private key")
noidLabel := th.Label(unit.Sp(fontSize), noidLabelText)
idLabel := th.Label(unit.Sp(fontSize), "Select ID")
anim := &time.Ticker{}
@@ -385,10 +383,10 @@ func eventLoop() {
w.Invalidate()
page = confPage
}
//case store.Id == "":
// idLabel.Layout(gtx)
// w.Invalidate()
// //page = idPage
case store.Id == "":
idLabel.Layout(gtx)
w.Invalidate()
page = idPage
default:
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
lst.Layout(gtx, len(passBtns), func(i int) {
@@ -479,21 +477,71 @@ func eventLoop() {
}
}
updateBtn := &Button{
Size: unit.Sp(fontSize),
Label: "Update",
Alignment: text.Middle,
Color: black,
Background: gray,
}
idEd := &widget.Editor{SingleLine: true, Submit: true}
idSubmitBtn := &Button{
Size: unit.Sp(fontSize),
Label: "Submit",
Alignment: text.Middle,
Color: black,
Background: gray,
}
idPage = func() {
log(Info,"idPage()")
if !animating {
animOn()
}
c2 := flex.Rigid(gtx, func() {
idLabel.Layout(gtx)
})
//if len(idBtns) == 0 {
updateIdBtns()
//}
c3 := flex.Rigid(gtx, func() {
if len(idBtns) == 0 { // still zero after update
var c3 layout.FlexChild
var c4 layout.FlexChild
var c5 layout.FlexChild
var c6 layout.FlexChild
var c7 layout.FlexChild
if len(idBtns) == 0 {
c3 = flex.Rigid(gtx, func() {
updateBtn.Layout(gtx)
})
if updateBtn.Clicked() {
updateIdBtns()
w.Invalidate()
}
c4 = flex.Rigid(gtx, func() {
th.Editor("id").Layout(gtx, idEd)
})
for _, e := range idEd.Events(gtx) {
switch e.(type) {
case widget.SubmitEvent:
log(Info, "Submit")
store.Id = idEd.Text()
page = listPage
}
}
c5 = flex.Rigid(gtx, func() {
idSubmitBtn.Layout(gtx)
})
if idSubmitBtn.Clicked() {
store.Id = idEd.Text()
page = listPage
}
c6 = flex.Rigid(gtx, func() {
noidLabel.Layout(gtx)
} else {
})
} else {
c3 = flex.Rigid(gtx, func() { })
c4 = flex.Rigid(gtx, func() { })
c5 = flex.Rigid(gtx, func() { })
c6 = flex.Rigid(gtx, func() { })
}
c7 = flex.Rigid(gtx, func() {
if len(idBtns) > 0 { // still zero after update
for i := 0; i < len(idBtns); i++ {
lst.Layout(gtx, len(idBtns), func(i int) {
idBtns[i].Layout(gtx)
@@ -510,7 +558,7 @@ func eventLoop() {
}
}
})
flex.Layout(gtx, c1, c2, c3)
flex.Layout(gtx, c1, c2, c3, c4, c5, c6, c7)
}
var insName, insValue string
@@ -629,7 +677,12 @@ func eventLoop() {
}
}
//Do not block the UI thread.
go store.Insert(passnameEd.Text(), passvalEd.Text())
go func() {
err := store.Insert(passnameEd.Text(), passvalEd.Text())
if err != nil {
page = idPage
}
}()
}
}
@@ -656,7 +709,12 @@ func eventLoop() {
if yesBtn.Clicked() {
w.Invalidate()
page = listPage
go store.Insert(insName, insValue)
go func() {
err := store.Insert(insName, insValue)
if err != nil {
page = idPage
}
}()
}
}
@@ -771,6 +829,9 @@ func eventLoop() {
if e.Stage == system.StageRunning {
initPgp(w)
}
go func() {
updateIdBtns()
}()
case system.FrameEvent:
gtx.Reset(e.Config, e.Size)