Update to latest Gio release. Install a system font on Darwin to

get access to Unicode glyphs.
This commit is contained in:
Greg 2019-12-18 13:30:56 -05:00
parent 4d6a8fd86a
commit 3163a75b93
8 changed files with 74 additions and 68 deletions

1
.gitignore vendored
View File

@ -2,4 +2,3 @@ cmd/passgo/passgo
cmd/passgo-gui/passgo-gui
nohup.out
*.apk
PgpConnect.jar

BIN
PgpConnect.jar Normal file

Binary file not shown.

View File

@ -7,6 +7,7 @@ import (
"git.wow.st/gmp/passgo"
"gioui.org/app"
"gioui.org/font/gofont"
)
var (
@ -17,6 +18,7 @@ func init() {
log(Info, "Android start")
// Use a larger font on Android
fontSize = 24
gofont.Register()
}
func initPgp(w *app.Window) {

View File

@ -8,41 +8,43 @@ import (
"path"
"gioui.org/app"
"gioui.org/font"
"gioui.org/font/gofont"
"gioui.org/font/opentype"
"gioui.org/text"
)
var (
noidLabelText = "No GPG ids available. Please create a private key or enter a key ID above"
)
/*func setFont() error {
func setFont() error {
f, err := os.Open("/System/Library/Fonts/AppleSDGothicNeo.ttc")
if err != nil {
log(Info, "Cannot open system font.")
log(Info, "Cannot open system font collection")
return err
}
collection, err := sfnt.ParseCollectionReaderAt(f)
fnts, err := opentype.ParseCollectionReaderAt(f)
if err != nil {
log(Info, "Cannot parse system font.")
log(Info, "Cannot parse font collection")
return err
}
regular, err = collection.Font(0)
face, err := fnts.Font(0)
if err != nil {
log(Info, "Cannot access first font in collection.")
log(Info, "Cannot access font from font collection")
return err
}
font.Register(text.Font{}, face)
return nil
}*/
}
func init() {
fontSize = 16
//err := setFont()
//if err != nil {
// regular, err = sfnt.Parse(goregular.TTF)
// if err != nil {
// log(Fatal, "Cannot parse default font: ", err)
// }
//}
err := setFont()
if err != nil {
gofont.Register()
}
}
func initPgp(w *app.Window) {

View File

@ -23,7 +23,7 @@ import (
"gioui.org/widget"
"gioui.org/widget/material"
"gioui.org/font/gofont"
//"gioui.org/font/gofont"
"github.com/fsnotify/fsnotify"
"gopkg.in/yaml.v2"
@ -190,14 +190,14 @@ func saveConf(fds ...*os.File) {
}
func eventLoop() {
gofont.Register()
//gofont.Register()
th = material.NewTheme()
th.TextSize = unit.Sp(fontSize)
w := app.NewWindow(
app.Size(unit.Dp(250), unit.Dp(500)),
app.Title("passgo"))
initPgp(w)
gtx := &layout.Context{Queue: w.Queue()}
gtx := layout.NewContext(w.Queue())
//time.Sleep(time.Second/5)
var margincs layout.Constraints
@ -371,7 +371,7 @@ func eventLoop() {
start2 := float64(Config.ClearDelay)
fade2a, end := start2+1.5, start2+2.0
c2 := flex.Flex(gtx, 1.0, func() {
c2 := layout.Flexed(1.0, func() {
mux.Lock()
if lst.Dragging() {
key.HideInputOp{}.Add(gtx.Ops)
@ -497,7 +497,7 @@ func eventLoop() {
if !animating {
animOn()
}
c2 := flex.Rigid(gtx, func() {
c2 := layout.Rigid(func() {
idLabel.Layout(gtx)
})
var c3 layout.FlexChild
@ -506,14 +506,14 @@ func eventLoop() {
var c6 layout.FlexChild
var c7 layout.FlexChild
if len(idBtns) == 0 {
c3 = flex.Rigid(gtx, func() {
c3 = layout.Rigid(func() {
updateBtn.Layout(gtx)
})
if updateBtn.Clicked() {
updateIdBtns()
w.Invalidate()
}
c4 = flex.Rigid(gtx, func() {
c4 = layout.Rigid(func() {
th.Editor("id").Layout(gtx, idEd)
})
for _, e := range idEd.Events(gtx) {
@ -524,23 +524,23 @@ func eventLoop() {
page = listPage
}
}
c5 = flex.Rigid(gtx, func() {
c5 = layout.Rigid(func() {
idSubmitBtn.Layout(gtx)
})
if idSubmitBtn.Clicked() {
store.Id = idEd.Text()
page = listPage
}
c6 = flex.Rigid(gtx, func() {
c6 = layout.Rigid(func() {
noidLabel.Layout(gtx)
})
} else {
c3 = flex.Rigid(gtx, func() { })
c4 = flex.Rigid(gtx, func() { })
c5 = flex.Rigid(gtx, func() { })
c6 = flex.Rigid(gtx, func() { })
c3 = layout.Rigid(func() { })
c4 = layout.Rigid(func() { })
c5 = layout.Rigid(func() { })
c6 = layout.Rigid(func() { })
}
c7 = flex.Rigid(gtx, func() {
c7 = layout.Rigid(func() {
if len(idBtns) > 0 { // still zero after update
for i := 0; i < len(idBtns); i++ {
lst.Layout(gtx, len(idBtns), func(i int) {
@ -597,34 +597,34 @@ func eventLoop() {
}
insertPage = func() {
c2 := flex.Rigid(gtx, func() { insertLabel.Layout(gtx) })
c3 := flex.Rigid(gtx, func() { passnameLabel.Layout(gtx) })
c4 := flex.Rigid(gtx, func() { th.Editor("name").Layout(gtx, passnameEd) })
c5 := flex.Rigid(gtx, func() { passvalLabel.Layout(gtx) })
c6 := flex.Rigid(gtx, func() { th.Editor("password").Layout(gtx, passvalEd) })
c2 := layout.Rigid(func() { insertLabel.Layout(gtx) })
c3 := layout.Rigid(func() { passnameLabel.Layout(gtx) })
c4 := layout.Rigid(func() { th.Editor("name").Layout(gtx, passnameEd) })
c5 := layout.Rigid(func() { passvalLabel.Layout(gtx) })
c6 := layout.Rigid(func() { th.Editor("password").Layout(gtx, passvalEd) })
btnflx := &layout.Flex{Axis: layout.Horizontal}
al := layout.Align(layout.E)
c7 := flex.Rigid(gtx, func() {
bc1 := btnflx.Rigid(gtx, func() { lBtn.Layout(gtx) })
bc2 := btnflx.Rigid(gtx, func() {
c7 := layout.Rigid(func() {
bc1 := layout.Rigid(func() { lBtn.Layout(gtx) })
bc2 := layout.Rigid(func() {
gtx.Constraints.Width.Min = 60
th.Editor("len").Layout(gtx, lenEd)
})
bc3 := btnflx.Rigid(gtx, func() { rBtn.Layout(gtx) })
bc4 := btnflx.Rigid(gtx, func() { symBtn.Layout(gtx) })
bc5 := btnflx.Rigid(gtx, func() { numBtn.Layout(gtx) })
bc6 := btnflx.Rigid(gtx, func() { genBtn.Layout(gtx) })
bc3 := layout.Rigid(func() { rBtn.Layout(gtx) })
bc4 := layout.Rigid(func() { symBtn.Layout(gtx) })
bc5 := layout.Rigid(func() { numBtn.Layout(gtx) })
bc6 := layout.Rigid(func() { genBtn.Layout(gtx) })
al.Layout(gtx, func() {
btnflx.Layout(gtx, bc1, bc2, bc3, bc4, bc5, bc6)
})
})
c8 := flex.Rigid(gtx, func() {
bc1 := btnflx.Rigid(gtx, func() { backBtn.Layout(gtx) })
bc2 := btnflx.Rigid(gtx, func() { saveBtn.Layout(gtx) })
c8 := layout.Rigid(func() {
bc1 := layout.Rigid(func() { backBtn.Layout(gtx) })
bc2 := layout.Rigid(func() { saveBtn.Layout(gtx) })
al.Layout(gtx, func() {
btnflx.Layout(gtx, bc1, bc2)
})
@ -687,14 +687,14 @@ func eventLoop() {
}
confirmPage = func() {
c2 := flex.Rigid(gtx, func() {
c2 := layout.Rigid(func() {
confirmLabel.Layout(gtx)
})
al := layout.Align(layout.E)
btnflx := &layout.Flex{Axis: layout.Horizontal}
c3 := flex.Rigid(gtx, func() {
bc1 := btnflx.Rigid(gtx, func() { backBtn.Layout(gtx) })
bc2 := btnflx.Rigid(gtx, func() { yesBtn.Layout(gtx) })
c3 := layout.Rigid(func() {
bc1 := layout.Rigid(func() { backBtn.Layout(gtx) })
bc2 := layout.Rigid(func() { yesBtn.Layout(gtx) })
al.Layout(gtx, func() {
btnflx.Layout(gtx, bc1, bc2)
@ -719,16 +719,16 @@ func eventLoop() {
}
confPage = func() {
c2 := flex.Rigid(gtx, func() { storeDirLabel.Layout(gtx) })
c3 := flex.Rigid(gtx, func() { th.Editor("directory").Layout(gtx, storeDirEd) })
c2 := layout.Rigid(func() { storeDirLabel.Layout(gtx) })
c3 := layout.Rigid(func() { th.Editor("directory").Layout(gtx, storeDirEd) })
al := layout.Align(layout.E)
c4 := flex.Rigid(gtx, func() {
c4 := layout.Rigid(func() {
btnflx := &layout.Flex{Axis: layout.Horizontal}
bc1 := btnflx.Rigid(gtx, func() {
bc1 := layout.Rigid(func() {
backBtn.Layout(gtx)
})
bc2 := btnflx.Rigid(gtx, func() {
bc2 := layout.Rigid(func() {
saveBtn.Layout(gtx)
})
al.Layout(gtx, func() {
@ -768,15 +768,15 @@ func eventLoop() {
submit = true
}
}
c2 := flex.Rigid(gtx, func() { promptLabel.Layout(gtx) })
c3 := flex.Rigid(gtx, func() { th.Editor("password").Layout(gtx, promptEd) })
c4 := flex.Rigid(gtx, func() {
c2 := layout.Rigid(func() { promptLabel.Layout(gtx) })
c3 := layout.Rigid(func() { th.Editor("password").Layout(gtx, promptEd) })
c4 := layout.Rigid(func() {
al := layout.Align(layout.E)
btnflx := &layout.Flex{Axis: layout.Horizontal}
bc1 := btnflx.Rigid(gtx, func() {
bc1 := layout.Rigid(func() {
backBtn.Layout(gtx)
})
bc2 := btnflx.Rigid(gtx, func() {
bc2 := layout.Rigid(func() {
okBtn.Layout(gtx)
})
al.Layout(gtx, func() {
@ -842,14 +842,14 @@ func eventLoop() {
sysinset.Layout(gtx, func() {
margin.Layout(gtx, func() {
margincs = gtx.Constraints
c1 = flex.Rigid(gtx, func() {
ct2 := titleflex.Rigid(gtx, func() {
c1 = layout.Rigid(func() {
ct2 := layout.Rigid(func() {
plusBtn.Layout(gtx)
})
ct3 := titleflex.Rigid(gtx, func() {
ct3 := layout.Rigid(func() {
dotsBtn.Layout(gtx)
})
ct1 := titleflex.Flex(gtx, 1.0, func() {
ct1 := layout.Flexed(1.0, func() {
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
title.Layout(gtx)
})

View File

@ -34,7 +34,7 @@ func (b *Overlay) Layout(gtx *layout.Context) {
ins := layout.UniformInset(unit.Dp(1))
ins.Layout(gtx, func() {
st := layout.Stack{}
c2 := st.Rigid(gtx, func() {
c2 := layout.Stacked(func() {
l := th.Label(b.Size, b.Text)
ins := layout.UniformInset(unit.Dp(4))
l.Color = b.Color
@ -43,7 +43,7 @@ func (b *Overlay) Layout(gtx *layout.Context) {
})
pointer.Rect(image.Rect(0, 0, gtx.Dimensions.Size.X, gtx.Dimensions.Size.Y)).Add(gtx.Ops)
})
c1 := st.Expand(gtx, func() {
c1 := layout.Expanded(func() {
layoutRRect(b.Background, gtx)
})
st.Layout(gtx, c1, c2)
@ -67,7 +67,7 @@ type Button struct {
}
func layoutRRect(col color.RGBA, gtx *layout.Context) {
r := float32(gtx.Config.Px(unit.Dp(4)))
r := float32(gtx.Px(unit.Dp(4)))
sz := image.Point{X: gtx.Constraints.Width.Min, Y: gtx.Constraints.Height.Min}
w, h := float32(sz.X), float32(sz.Y)
rect := f32.Rectangle{
@ -92,7 +92,7 @@ func (b *Button) Layout(gtx *layout.Context) {
ins := layout.UniformInset(unit.Dp(1))
ins.Layout(gtx, func() {
st := layout.Stack{}
c2 := st.Rigid(gtx, func() {
c2 := layout.Stacked(func() {
l := th.Label(b.Size, b.Label)
ins := layout.UniformInset(unit.Dp(4))
//paint.ColorOp{Color: b.Color}.Add(ops)
@ -102,7 +102,7 @@ func (b *Button) Layout(gtx *layout.Context) {
pointer.Rect(image.Rect(0, 0, gtx.Dimensions.Size.X, gtx.Dimensions.Size.Y)).Add(gtx.Ops)
b.Click.Add(gtx.Ops)
})
c1 := st.Expand(gtx, func() {
c1 := layout.Expanded(func() {
gtx.Constraints.Width.Min = mwidth
layoutRRect(b.Background, gtx)
})

3
go.mod
View File

@ -3,11 +3,12 @@ module git.wow.st/gmp/passgo
go 1.13
require (
gioui.org v0.0.0-20191126175243-2ca2e5462f16
gioui.org v0.0.0-20191218180754-3dd7c8121c67
git.wow.st/gmp/clip v0.0.0-20191001134149-1458ba6a7cf5
git.wow.st/gmp/rand v0.0.0-20191001220155-a81bebfaf8b0
github.com/fsnotify/fsnotify v1.4.7
github.com/jcmdev0/gpgagent v0.0.0-20180509014935-5601b32d936c
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
gopkg.in/yaml.v2 v2.2.7
)

2
go.sum
View File

@ -1,6 +1,8 @@
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20191126175243-2ca2e5462f16 h1:p31rtmKm51xpj2QtqGNlljAyHEP1oStU8MDRl2Dv7Gs=
gioui.org v0.0.0-20191126175243-2ca2e5462f16/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
gioui.org v0.0.0-20191218180754-3dd7c8121c67 h1:y9md+l1thtMqJu/ulhF1Upv3pnOpGotpJDssO8X3LbY=
gioui.org v0.0.0-20191218180754-3dd7c8121c67/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
git.wow.st/gmp/clip v0.0.0-20191001134149-1458ba6a7cf5 h1:OKeTjZST+/TKvtdA258NXJH+/gIx/xwyZxKrAezNFvk=
git.wow.st/gmp/clip v0.0.0-20191001134149-1458ba6a7cf5/go.mod h1:NLdpaBoMQNFqncwP8OVRNWUDw1Kt9XWm3snfT7cXu24=
git.wow.st/gmp/rand v0.0.0-20191001220155-a81bebfaf8b0 h1:08wP00wvbDINsct1fzKV1xGGLvvtNsSb2X4CtIdpBzM=