Compatibility with gpg 2.0 -- call out to gpg commands (on Darwin)
if go openpgp is not compatibile with the local gpg installation.
This commit is contained in:
+183
-15
@@ -49,7 +49,7 @@ func main() {
|
||||
log(Info, " StoreDir = ", store.Dir)
|
||||
err = passgo.GetStore(&store)
|
||||
if err != nil {
|
||||
log(Fatal, err)
|
||||
log(Info, err)
|
||||
}
|
||||
if Config.ClearDelay == 0 {
|
||||
Config.ClearDelay = 45
|
||||
@@ -62,8 +62,10 @@ func main() {
|
||||
|
||||
reload = make(chan struct{})
|
||||
updated = make(chan struct{})
|
||||
chdir = make(chan struct{})
|
||||
passch = make(chan []byte)
|
||||
|
||||
passgo.Identities()
|
||||
go Updater()
|
||||
log(Info, "Staring event loop")
|
||||
go eventLoop()
|
||||
@@ -78,6 +80,7 @@ var (
|
||||
store passgo.Store
|
||||
reload chan struct{}
|
||||
updated chan struct{}
|
||||
chdir chan struct{}
|
||||
passch chan []byte
|
||||
)
|
||||
|
||||
@@ -98,7 +101,8 @@ func Updater() {
|
||||
if err != nil {
|
||||
log(Fatal, err)
|
||||
}
|
||||
watcher.Add(store.Dir)
|
||||
dir := store.Dir
|
||||
watcher.Add(dir)
|
||||
for {
|
||||
select {
|
||||
case <-reload:
|
||||
@@ -107,6 +111,13 @@ func Updater() {
|
||||
update()
|
||||
case e := <-watcher.Errors:
|
||||
log(Info, "Watcher error: ", e)
|
||||
case <-chdir:
|
||||
err := watcher.Remove(dir)
|
||||
if err != nil {
|
||||
log(Info, "Error removing watcher: ", err)
|
||||
}
|
||||
watcher.Add(store.Dir)
|
||||
update()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,10 +162,10 @@ func eventLoop() {
|
||||
margin := layout.UniformInset(ui.Dp(10))
|
||||
|
||||
title := &text.Label{Face: face, Text: "passgo"}
|
||||
dotsbtn := &Button{
|
||||
dotsBtn := &Button{
|
||||
Face: face,
|
||||
Label: "\xe2\x8b\xae",
|
||||
Alignment: text.End,
|
||||
Alignment: text.Middle,
|
||||
Color: black,
|
||||
Background: gray,
|
||||
}
|
||||
@@ -200,6 +211,30 @@ func eventLoop() {
|
||||
}
|
||||
updateBtns()
|
||||
|
||||
idBtns := make([]*Button, 0)
|
||||
|
||||
updateIdBtns := func() {
|
||||
ids, err := passgo.Identities()
|
||||
if err != nil {
|
||||
log(Info, err)
|
||||
return
|
||||
}
|
||||
for i,n := range ids {
|
||||
if i >= len(idBtns) {
|
||||
idBtns = append(idBtns, &Button{
|
||||
Face: face,
|
||||
Label: n,
|
||||
Alignment: text.End,
|
||||
Color: black,
|
||||
Background: gray,
|
||||
})
|
||||
} else {
|
||||
idBtns[i].Label = n
|
||||
}
|
||||
}
|
||||
idBtns = idBtns[:len(ids)]
|
||||
}
|
||||
|
||||
confBtn := &Button{
|
||||
Face: face,
|
||||
Label: "configure",
|
||||
@@ -225,6 +260,14 @@ func eventLoop() {
|
||||
Color: black,
|
||||
Background: gray,
|
||||
}
|
||||
confirmLabel := &text.Label{Face: face, Text: "Password exists. Overwrite?"}
|
||||
yesBtn := &Button{
|
||||
Face: face,
|
||||
Label: "yes",
|
||||
Alignment: text.End,
|
||||
Color: black,
|
||||
Background: gray,
|
||||
}
|
||||
|
||||
promptLabel := &text.Label{Face: face, Text: "passphrase"}
|
||||
promptEd := &text.Editor{Face: face, SingleLine: true, Submit: true}
|
||||
@@ -235,6 +278,22 @@ func eventLoop() {
|
||||
Color: black,
|
||||
Background: gray,
|
||||
}
|
||||
plusBtn := &Button{
|
||||
Face: face,
|
||||
Label: "+",
|
||||
Alignment: text.Middle,
|
||||
Color: black,
|
||||
Background: gray,
|
||||
}
|
||||
|
||||
insertLabel := &text.Label{Face: face, Text: "Insert"}
|
||||
passnameLabel := &text.Label{Face: face, Text: "password name:"}
|
||||
passnameEd := &text.Editor{Face: face, SingleLine: true, Submit: true}
|
||||
passvalLabel := &text.Label{Face: face, Text: "password value:"}
|
||||
passvalEd := &text.Editor{Face: face, SingleLine: true, Submit: true}
|
||||
|
||||
noidLabel := &text.Label{Face: face, Text: "No GPG ids available. Please create a private key"}
|
||||
idLabel := &text.Label{Face: face, Text: "Select ID"}
|
||||
|
||||
anim := &time.Ticker{}
|
||||
animating := false
|
||||
@@ -250,7 +309,7 @@ func eventLoop() {
|
||||
animating = false
|
||||
}
|
||||
|
||||
var listPage, confPage, promptPage, page func()
|
||||
var listPage, idPage, insertPage, confirmPage, confPage, promptPage, page func()
|
||||
|
||||
prompt := func() []byte {
|
||||
page = promptPage
|
||||
@@ -271,14 +330,19 @@ func eventLoop() {
|
||||
key.HideInputOp{}.Add(ops)
|
||||
}
|
||||
var c2 layout.FlexChild
|
||||
if len(passBtns) == 0 {
|
||||
switch {
|
||||
case store.Empty:
|
||||
c2 = flex.End(confBtn.Layout(c, q, ops, cs))
|
||||
if confBtn.Clicked() {
|
||||
log(Info, "Configure")
|
||||
w.Invalidate()
|
||||
page = confPage
|
||||
}
|
||||
} else {
|
||||
case store.Id == "":
|
||||
c2 = flex.End(idLabel.Layout(ops, cs))
|
||||
w.Invalidate()
|
||||
page = idPage
|
||||
default:
|
||||
for lst.Init(c, q, ops, cs, len(passBtns)); lst.More(); lst.Next() {
|
||||
i := lst.Index()
|
||||
btn := passBtns[i]
|
||||
@@ -316,11 +380,6 @@ func eventLoop() {
|
||||
c2 = flex.End(lst.Layout())
|
||||
}
|
||||
mux.Unlock()
|
||||
if dotsbtn.Clicked() {
|
||||
log(Info, "Configure")
|
||||
w.Invalidate()
|
||||
page = confPage
|
||||
}
|
||||
flex.Layout(c1, c2)
|
||||
x := time.Since(overlayStart).Seconds()
|
||||
if x >= fade1b && x < start2 && animating {
|
||||
@@ -372,6 +431,99 @@ func eventLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
idPage = func() {
|
||||
if !animating {
|
||||
animOn()
|
||||
}
|
||||
cs = flex.Rigid()
|
||||
c2 := flex.End(idLabel.Layout(ops, cs))
|
||||
var c3 layout.FlexChild
|
||||
//if len(idBtns) == 0 {
|
||||
updateIdBtns()
|
||||
//}
|
||||
cs = flex.Rigid()
|
||||
if len(idBtns) == 0 { // still zero after update
|
||||
c3 = flex.End(noidLabel.Layout(ops, cs))
|
||||
} else {
|
||||
for lst.Init(c, q, ops, cs, len(idBtns)); lst.More(); lst.Next() {
|
||||
lst.End(idBtns[lst.Index()].Layout(c, q, ops, lst.Constraints()))
|
||||
}
|
||||
c3 = flex.End(lst.Layout())
|
||||
for _, btn := range idBtns {
|
||||
if btn.Clicked() {
|
||||
log(Info, "ID selected: ", btn.Label)
|
||||
store.SetID(btn.Label)
|
||||
w.Invalidate()
|
||||
animOff()
|
||||
page = listPage
|
||||
}
|
||||
}
|
||||
}
|
||||
flex.Layout(c1, c2, c3)
|
||||
}
|
||||
|
||||
var insName, insValue string
|
||||
|
||||
insertPage = func() {
|
||||
cs = flex.Rigid()
|
||||
c2 := flex.End(insertLabel.Layout(ops, cs))
|
||||
|
||||
c3 := flex.End(passnameLabel.Layout(ops, flex.Rigid()))
|
||||
c4 := flex.End(passnameEd.Layout(c, q, ops, flex.Rigid()))
|
||||
c5 := flex.End(passvalLabel.Layout(ops, flex.Rigid()))
|
||||
c6 := flex.End(passvalEd.Layout(c, q, ops, flex.Rigid()))
|
||||
cs = flex.Rigid()
|
||||
al := &layout.Align{Alignment: layout.E}
|
||||
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
||||
btnflx.Init(ops, al.Begin(ops, cs))
|
||||
bc1 := btnflx.End(backBtn.Layout(c, q, ops, btnflx.Rigid()))
|
||||
bc2 := btnflx.End(saveBtn.Layout(c, q, ops, btnflx.Rigid()))
|
||||
c7 := flex.End(al.End(btnflx.Layout(bc1, bc2)))
|
||||
flex.Layout(c1, c2, c3, c4, c5, c6, c7)
|
||||
|
||||
if backBtn.Clicked() {
|
||||
w.Invalidate()
|
||||
page = listPage
|
||||
}
|
||||
if saveBtn.Clicked() {
|
||||
w.Invalidate()
|
||||
page = listPage
|
||||
insName = passnameEd.Text()
|
||||
insValue = passvalEd.Text()
|
||||
for _, n := range pathnames {
|
||||
if insName == n {
|
||||
log(Info,"Password exists")
|
||||
page = confirmPage
|
||||
w.Invalidate()
|
||||
return
|
||||
}
|
||||
}
|
||||
store.Insert(passnameEd.Text(), passvalEd.Text())
|
||||
}
|
||||
}
|
||||
|
||||
confirmPage = func() {
|
||||
cs = flex.Rigid()
|
||||
c2 := flex.End(confirmLabel.Layout(ops, cs))
|
||||
al := &layout.Align{Alignment: layout.E}
|
||||
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
||||
btnflx.Init(ops, al.Begin(ops, flex.Rigid()))
|
||||
bc1 := btnflx.End(backBtn.Layout(c, q, ops, btnflx.Rigid()))
|
||||
bc2 := btnflx.End(yesBtn.Layout(c, q, ops, btnflx.Rigid()))
|
||||
c3 := flex.End(al.End(btnflx.Layout(bc1, bc2)))
|
||||
flex.Layout(c1, c2, c3)
|
||||
|
||||
if backBtn.Clicked() {
|
||||
w.Invalidate()
|
||||
page = insertPage
|
||||
}
|
||||
if yesBtn.Clicked() {
|
||||
w.Invalidate()
|
||||
page = listPage
|
||||
store.Insert(insName, insValue)
|
||||
}
|
||||
}
|
||||
|
||||
confPage = func() {
|
||||
cs = flex.Rigid()
|
||||
c2 := flex.End(storeDirLabel.Layout(ops, cs))
|
||||
@@ -399,10 +551,12 @@ func eventLoop() {
|
||||
log(Info, "Save")
|
||||
go func() { // do not block UI thread
|
||||
store.Dir = storeDirEd.Text()
|
||||
store.Id = ""
|
||||
passgo.GetStore(&store)
|
||||
Config.StoreDir = store.Dir
|
||||
store.Mkdir()
|
||||
saveConf()
|
||||
reload <- struct{}{}
|
||||
chdir <- struct{}{}
|
||||
}()
|
||||
w.Invalidate()
|
||||
page = listPage
|
||||
@@ -477,15 +631,29 @@ func eventLoop() {
|
||||
cs = flex.Rigid()
|
||||
titleflex.Init(ops, cs)
|
||||
cs = titleflex.Rigid()
|
||||
ct2 := titleflex.End(dotsbtn.Layout(c, q, ops, cs))
|
||||
ct2 := titleflex.End(plusBtn.Layout(c, q, ops, cs))
|
||||
cs = titleflex.Rigid()
|
||||
ct3 := titleflex.End(dotsBtn.Layout(c, q, ops, cs))
|
||||
cs = titleflex.Flexible(1.0)
|
||||
cs.Width.Min = cs.Width.Max
|
||||
ct1 := titleflex.End(title.Layout(ops, cs))
|
||||
c1 = flex.End(titleflex.Layout(ct1, ct2))
|
||||
c1 = flex.End(titleflex.Layout(ct1, ct2, ct3))
|
||||
|
||||
page()
|
||||
|
||||
margin.End(dims)
|
||||
|
||||
if dotsBtn.Clicked() {
|
||||
log(Info, "Configure")
|
||||
w.Invalidate()
|
||||
page = confPage
|
||||
}
|
||||
if plusBtn.Clicked() {
|
||||
log(Info, "Plus")
|
||||
w.Invalidate()
|
||||
insName, insValue = "", ""
|
||||
page = insertPage
|
||||
}
|
||||
w.Update(ops)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func (b *Button) Layout(c ui.Config, q input.Queue, ops *ui.Ops, cs layout.Const
|
||||
Alignment: b.Alignment,
|
||||
}
|
||||
ins := layout.UniformInset(ui.Dp(4))
|
||||
paint.ColorOp{Color: b.Color}.Add(ops)
|
||||
//paint.ColorOp{Color: b.Color}.Add(ops)
|
||||
dims = ins.End(l.Layout(ops, ins.Begin(c, ops, cs)))
|
||||
pointer.RectAreaOp{image.Rect(0, 0, dims.Size.X, dims.Size.Y)}.Add(ops)
|
||||
b.Click.Add(ops)
|
||||
|
||||
Reference in New Issue
Block a user