2019-09-04 22:19:39 -04:00
|
|
|
// +build darwin linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-09-06 10:45:18 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-09-05 06:41:39 -04:00
|
|
|
"path"
|
|
|
|
"strings"
|
2019-09-04 22:19:39 -04:00
|
|
|
"sync"
|
2019-09-06 10:45:18 -04:00
|
|
|
"time"
|
2019-09-04 22:19:39 -04:00
|
|
|
|
|
|
|
"gioui.org/ui"
|
|
|
|
"gioui.org/ui/app"
|
|
|
|
"gioui.org/ui/key"
|
|
|
|
"gioui.org/ui/layout"
|
|
|
|
"gioui.org/ui/measure"
|
2019-09-05 06:41:39 -04:00
|
|
|
"gioui.org/ui/text"
|
2019-09-04 22:19:39 -04:00
|
|
|
|
2019-09-10 11:31:57 -04:00
|
|
|
"golang.org/x/image/font/sfnt"
|
|
|
|
|
2019-09-04 22:19:39 -04:00
|
|
|
"github.com/fsnotify/fsnotify"
|
2019-09-06 10:45:18 -04:00
|
|
|
"gopkg.in/yaml.v2"
|
2019-09-04 22:19:39 -04:00
|
|
|
|
2019-09-05 06:41:39 -04:00
|
|
|
"git.wow.st/gmp/passgo"
|
2019-09-04 22:19:39 -04:00
|
|
|
)
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
type conf struct {
|
2019-09-06 21:14:06 -04:00
|
|
|
StoreDir string
|
2019-09-06 13:36:06 -04:00
|
|
|
ClearDelay int
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
|
|
|
|
2019-09-04 22:19:39 -04:00
|
|
|
func main() {
|
2019-09-06 10:45:18 -04:00
|
|
|
var fd *os.File
|
|
|
|
confFile := path.Join(confDir, "config.yml")
|
|
|
|
if _, err := os.Stat(confFile); os.IsNotExist(err) {
|
|
|
|
fd, err = os.Create(confFile)
|
2019-09-06 10:46:23 -04:00
|
|
|
if err != nil {
|
2019-09-06 10:45:18 -04:00
|
|
|
log(Fatal, "Cannot create configuration file: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
confbytes, err := ioutil.ReadFile(confFile)
|
|
|
|
if err != nil {
|
|
|
|
log(Fatal, "Cannot read configuration file: ", err)
|
|
|
|
}
|
|
|
|
if err = yaml.UnmarshalStrict(confbytes, &Config); err != nil {
|
|
|
|
log(Fatal, "Cannot parse configuration file: ", err)
|
|
|
|
}
|
|
|
|
store.Dir = Config.StoreDir
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Info, " StoreDir = ", store.Dir)
|
2019-09-19 17:28:15 -04:00
|
|
|
go func() {
|
|
|
|
err = passgo.GetStore(&store)
|
|
|
|
if err != nil {
|
|
|
|
log(Info, err)
|
|
|
|
}
|
|
|
|
}()
|
2019-09-06 13:36:06 -04:00
|
|
|
if Config.ClearDelay == 0 {
|
|
|
|
Config.ClearDelay = 45
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
|
|
|
|
if fd != nil { // we still have an empty conf file open:
|
|
|
|
Config.StoreDir = store.Dir
|
|
|
|
saveConf(fd)
|
|
|
|
}
|
|
|
|
|
|
|
|
reload = make(chan struct{})
|
2019-09-04 22:19:39 -04:00
|
|
|
updated = make(chan struct{})
|
2019-09-10 08:45:59 -04:00
|
|
|
chdir = make(chan struct{})
|
2019-09-06 11:43:14 -04:00
|
|
|
passch = make(chan []byte)
|
2019-09-06 10:45:18 -04:00
|
|
|
|
2019-09-10 08:45:59 -04:00
|
|
|
passgo.Identities()
|
2019-09-04 22:19:39 -04:00
|
|
|
go Updater()
|
2019-09-05 06:41:39 -04:00
|
|
|
log(Info, "Staring event loop")
|
2019-09-04 22:19:39 -04:00
|
|
|
go eventLoop()
|
|
|
|
app.Main()
|
2019-09-05 06:41:39 -04:00
|
|
|
log(Info, "Event loop returned")
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2019-09-10 11:31:57 -04:00
|
|
|
confDir string
|
|
|
|
regular *sfnt.Font
|
2019-09-06 21:14:06 -04:00
|
|
|
Config conf
|
|
|
|
l []passgo.Pass
|
|
|
|
mux sync.Mutex
|
|
|
|
store passgo.Store
|
|
|
|
reload chan struct{}
|
|
|
|
updated chan struct{}
|
2019-09-10 11:36:03 -04:00
|
|
|
chdir chan struct{}
|
2019-09-06 21:14:06 -04:00
|
|
|
passch chan []byte
|
2019-09-04 22:19:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func Updater() {
|
|
|
|
update := func() {
|
2019-09-05 06:41:39 -04:00
|
|
|
ltmp, err := store.List()
|
2019-09-04 22:19:39 -04:00
|
|
|
if err != nil {
|
2019-09-06 10:45:18 -04:00
|
|
|
log(Info, err)
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|
|
|
|
mux.Lock()
|
|
|
|
l = ltmp
|
|
|
|
mux.Unlock()
|
|
|
|
updated <- struct{}{}
|
|
|
|
}
|
|
|
|
update()
|
|
|
|
|
|
|
|
watcher, err := fsnotify.NewWatcher()
|
|
|
|
if err != nil {
|
|
|
|
log(Fatal, err)
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
dir := store.Dir
|
|
|
|
watcher.Add(dir)
|
2019-09-04 22:19:39 -04:00
|
|
|
for {
|
|
|
|
select {
|
2019-09-06 10:45:18 -04:00
|
|
|
case <-reload:
|
|
|
|
update()
|
2019-09-04 22:19:39 -04:00
|
|
|
case <-watcher.Events:
|
|
|
|
update()
|
|
|
|
case e := <-watcher.Errors:
|
2019-09-05 06:41:39 -04:00
|
|
|
log(Info, "Watcher error: ", e)
|
2019-09-10 08:45:59 -04:00
|
|
|
case <-chdir:
|
|
|
|
err := watcher.Remove(dir)
|
|
|
|
if err != nil {
|
|
|
|
log(Info, "Error removing watcher: ", err)
|
|
|
|
}
|
|
|
|
watcher.Add(store.Dir)
|
|
|
|
update()
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
func saveConf(fds ...*os.File) {
|
|
|
|
var fd *os.File
|
|
|
|
var err error
|
|
|
|
if len(fds) > 0 && fds[0] != nil {
|
|
|
|
fd = fds[0]
|
|
|
|
} else {
|
|
|
|
fd, err = os.Create(path.Join(confDir, "config.yml"))
|
|
|
|
if err != nil {
|
|
|
|
log(Fatal, "Cannot open config file: ", err)
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 12:16:08 -04:00
|
|
|
defer fd.Close()
|
2019-09-06 10:45:18 -04:00
|
|
|
|
|
|
|
confbytes, err := yaml.Marshal(Config)
|
|
|
|
if err != nil {
|
|
|
|
log(Fatal, "Cannot save configuration: ", err)
|
|
|
|
}
|
|
|
|
_, err = fd.Write(confbytes)
|
|
|
|
if err != nil {
|
|
|
|
log(Fatal, "Cannot write to configuration: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 22:19:39 -04:00
|
|
|
func eventLoop() {
|
2019-09-06 21:14:06 -04:00
|
|
|
w := app.NewWindow(
|
|
|
|
app.WithWidth(ui.Dp(250)),
|
|
|
|
app.WithTitle("passgo"))
|
2019-09-04 22:19:39 -04:00
|
|
|
q := w.Queue()
|
2019-09-06 10:45:18 -04:00
|
|
|
var c ui.Config
|
2019-09-04 22:19:39 -04:00
|
|
|
ops := new(ui.Ops)
|
2019-09-06 10:45:18 -04:00
|
|
|
var dims layout.Dimensions
|
|
|
|
var cs layout.Constraints
|
|
|
|
var margincs layout.Constraints
|
2019-09-04 22:19:39 -04:00
|
|
|
var faces measure.Faces
|
2019-09-06 10:45:18 -04:00
|
|
|
var c1 layout.FlexChild // flex child for title bar
|
2019-09-04 22:19:39 -04:00
|
|
|
face := faces.For(regular, ui.Sp(16))
|
|
|
|
|
2019-09-19 17:28:15 -04:00
|
|
|
sysinset := &layout.Inset{}
|
2019-09-04 22:19:39 -04:00
|
|
|
margin := layout.UniformInset(ui.Dp(10))
|
2019-09-06 10:45:18 -04:00
|
|
|
|
2019-09-06 10:46:23 -04:00
|
|
|
title := &text.Label{Face: face, Text: "passgo"}
|
2019-09-10 08:45:59 -04:00
|
|
|
dotsBtn := &Button{
|
2019-09-06 10:46:23 -04:00
|
|
|
Face: face,
|
|
|
|
Label: "\xe2\x8b\xae",
|
2019-09-10 08:45:59 -04:00
|
|
|
Alignment: text.Middle,
|
2019-09-06 10:46:23 -04:00
|
|
|
Color: black,
|
2019-09-06 10:45:18 -04:00
|
|
|
Background: gray,
|
|
|
|
}
|
|
|
|
|
|
|
|
titleflex := &layout.Flex{Axis: layout.Horizontal}
|
|
|
|
|
|
|
|
flex := &layout.Flex{Axis: layout.Vertical}
|
2019-09-04 22:19:39 -04:00
|
|
|
lst := &layout.List{Axis: layout.Vertical}
|
2019-09-05 06:41:39 -04:00
|
|
|
passBtns := make([]*Button, 0)
|
|
|
|
pathnames := make([]string, 0)
|
2019-09-06 10:45:18 -04:00
|
|
|
copied := &Overlay{Face: face, Text: "copied to clipboard",
|
2019-09-06 10:46:23 -04:00
|
|
|
Color: black,
|
2019-09-06 10:45:18 -04:00
|
|
|
Background: darkgray,
|
2019-09-06 10:46:23 -04:00
|
|
|
Alignment: text.Middle,
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
2019-09-06 11:55:31 -04:00
|
|
|
cleared := &Overlay{Face: face, Text: "clipboard cleared",
|
|
|
|
Color: black,
|
|
|
|
Background: darkgray,
|
|
|
|
Alignment: text.Middle,
|
|
|
|
}
|
|
|
|
overlay := copied
|
|
|
|
var overlayStart time.Time
|
2019-09-04 22:19:39 -04:00
|
|
|
|
|
|
|
updateBtns := func() {
|
|
|
|
passBtns = passBtns[:0]
|
|
|
|
pathnames = pathnames[:0]
|
|
|
|
mux.Lock()
|
2019-09-05 06:41:39 -04:00
|
|
|
for _, x := range l {
|
2019-09-04 22:19:39 -04:00
|
|
|
_, n := path.Split(x.Pathname)
|
2019-09-05 06:41:39 -04:00
|
|
|
s := strings.Repeat(" /", x.Level)
|
2019-09-04 22:19:39 -04:00
|
|
|
z := ""
|
2019-09-05 06:41:39 -04:00
|
|
|
if x.Dir {
|
|
|
|
z = "/"
|
|
|
|
}
|
|
|
|
passBtns = append(passBtns, &Button{
|
2019-09-06 10:46:23 -04:00
|
|
|
Face: face,
|
|
|
|
Label: strings.Join([]string{s, n, z}, ""),
|
2019-09-06 10:45:18 -04:00
|
|
|
Background: gray,
|
2019-09-04 22:19:39 -04:00
|
|
|
})
|
|
|
|
pathnames = append(pathnames, x.Pathname)
|
|
|
|
}
|
|
|
|
mux.Unlock()
|
|
|
|
}
|
|
|
|
updateBtns()
|
|
|
|
|
2019-09-10 08:45:59 -04:00
|
|
|
idBtns := make([]*Button, 0)
|
|
|
|
|
|
|
|
updateIdBtns := func() {
|
|
|
|
ids, err := passgo.Identities()
|
|
|
|
if err != nil {
|
|
|
|
log(Info, err)
|
|
|
|
return
|
|
|
|
}
|
2019-09-10 11:36:03 -04:00
|
|
|
for i, n := range ids {
|
2019-09-10 08:45:59 -04:00
|
|
|
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)]
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
confBtn := &Button{
|
2019-09-06 10:46:23 -04:00
|
|
|
Face: face,
|
|
|
|
Label: "configure",
|
|
|
|
Alignment: text.Middle,
|
|
|
|
Color: black,
|
2019-09-06 10:45:18 -04:00
|
|
|
Background: gray,
|
|
|
|
}
|
|
|
|
|
|
|
|
storeDirLabel := &text.Label{Face: face, Text: "Store directory"}
|
|
|
|
storeDirEd := &text.Editor{Face: face, SingleLine: true}
|
|
|
|
storeDirEd.SetText(store.Dir)
|
|
|
|
saveBtn := &Button{
|
2019-09-06 10:46:23 -04:00
|
|
|
Face: face,
|
|
|
|
Label: "save",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
2019-09-06 10:45:18 -04:00
|
|
|
Background: gray,
|
|
|
|
}
|
2019-09-06 10:52:27 -04:00
|
|
|
backBtn := &Button{
|
|
|
|
Face: face,
|
|
|
|
Label: "back",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
confirmLabel := &text.Label{Face: face, Text: "Password exists. Overwrite?"}
|
|
|
|
yesBtn := &Button{
|
|
|
|
Face: face,
|
|
|
|
Label: "yes",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
|
2019-09-06 11:43:14 -04:00
|
|
|
promptLabel := &text.Label{Face: face, Text: "passphrase"}
|
2019-09-06 13:36:06 -04:00
|
|
|
promptEd := &text.Editor{Face: face, SingleLine: true, Submit: true}
|
2019-09-06 11:43:14 -04:00
|
|
|
okBtn := &Button{
|
|
|
|
Face: face,
|
|
|
|
Label: "ok",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
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"}
|
2019-09-06 11:43:14 -04:00
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
anim := &time.Ticker{}
|
|
|
|
animating := false
|
|
|
|
animOn := func() {
|
2019-09-06 21:14:06 -04:00
|
|
|
log(Info, "animOn()")
|
2019-09-06 10:45:18 -04:00
|
|
|
anim = time.NewTicker(time.Second / 120)
|
|
|
|
animating = true
|
|
|
|
w.Invalidate()
|
|
|
|
}
|
|
|
|
animOff := func() {
|
2019-09-06 21:14:06 -04:00
|
|
|
log(Info, "animOff()")
|
2019-09-06 10:45:18 -04:00
|
|
|
anim.Stop()
|
|
|
|
animating = false
|
|
|
|
}
|
|
|
|
|
2019-09-10 08:45:59 -04:00
|
|
|
var listPage, idPage, insertPage, confirmPage, confPage, promptPage, page func()
|
2019-09-06 11:43:14 -04:00
|
|
|
|
|
|
|
prompt := func() []byte {
|
|
|
|
page = promptPage
|
|
|
|
promptEd.SetText("")
|
|
|
|
w.Invalidate()
|
|
|
|
return <-passch
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
|
|
|
|
listPage = func() {
|
2019-09-06 15:14:37 -04:00
|
|
|
// timing variables used for animation
|
|
|
|
fade1a, fade1b := 1.5, 2.0
|
|
|
|
start2 := float64(Config.ClearDelay)
|
2019-09-06 21:14:06 -04:00
|
|
|
fade2a, end := start2+1.5, start2+2.0
|
2019-09-06 15:14:37 -04:00
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
cs = flex.Flexible(1.0)
|
|
|
|
mux.Lock()
|
|
|
|
if lst.Dragging() {
|
|
|
|
key.HideInputOp{}.Add(ops)
|
|
|
|
}
|
|
|
|
var c2 layout.FlexChild
|
2019-09-10 08:45:59 -04:00
|
|
|
switch {
|
|
|
|
case store.Empty:
|
2019-09-06 10:45:18 -04:00
|
|
|
c2 = flex.End(confBtn.Layout(c, q, ops, cs))
|
|
|
|
if confBtn.Clicked() {
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Info, "Configure")
|
2019-09-06 10:45:18 -04:00
|
|
|
w.Invalidate()
|
|
|
|
page = confPage
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
case store.Id == "":
|
|
|
|
c2 = flex.End(idLabel.Layout(ops, cs))
|
|
|
|
w.Invalidate()
|
|
|
|
page = idPage
|
|
|
|
default:
|
2019-09-06 10:45:18 -04:00
|
|
|
for lst.Init(c, q, ops, cs, len(passBtns)); lst.More(); lst.Next() {
|
2019-09-06 10:58:37 -04:00
|
|
|
i := lst.Index()
|
|
|
|
btn := passBtns[i]
|
2019-09-06 10:45:18 -04:00
|
|
|
dims = btn.Layout(c, q, ops, lst.Constraints())
|
|
|
|
lst.End(dims)
|
|
|
|
if btn.Clicked() {
|
|
|
|
log(Info, "Clicked ", btn.Label)
|
|
|
|
// don't block UI thread on decryption attempt
|
|
|
|
go func(name string) {
|
2019-09-06 21:14:06 -04:00
|
|
|
p, err := store.Decrypt(name, prompt)
|
2019-09-06 11:43:14 -04:00
|
|
|
//p, err := store.Decrypt(name)
|
2019-09-06 10:45:18 -04:00
|
|
|
if err == nil {
|
|
|
|
passgo.Clip(p)
|
2019-09-06 11:55:31 -04:00
|
|
|
overlayStart = time.Now()
|
|
|
|
overlay = copied
|
2019-09-06 13:36:06 -04:00
|
|
|
overlay.Color = black
|
|
|
|
overlay.Background = darkgray
|
2019-09-06 15:14:37 -04:00
|
|
|
w.Invalidate()
|
|
|
|
go func() {
|
2019-09-06 16:55:14 -04:00
|
|
|
time.Sleep(time.Millisecond * time.Duration(fade1a*1000))
|
2019-09-06 15:14:37 -04:00
|
|
|
animOn()
|
|
|
|
}()
|
2019-09-06 11:55:31 -04:00
|
|
|
go func() {
|
2019-09-06 16:55:14 -04:00
|
|
|
time.Sleep(time.Millisecond * time.Duration(Config.ClearDelay*1000))
|
2019-09-06 13:36:06 -04:00
|
|
|
log(Info, "clearing clipboard")
|
2019-09-06 11:55:31 -04:00
|
|
|
passgo.Clip("")
|
|
|
|
}()
|
2019-09-06 10:45:18 -04:00
|
|
|
} else {
|
|
|
|
log(Info, "Can't decrypt ", name)
|
|
|
|
log(Info, err)
|
|
|
|
}
|
2019-09-06 10:58:37 -04:00
|
|
|
}(pathnames[i])
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
c2 = flex.End(lst.Layout())
|
|
|
|
}
|
|
|
|
mux.Unlock()
|
|
|
|
flex.Layout(c1, c2)
|
2019-09-06 11:55:31 -04:00
|
|
|
x := time.Since(overlayStart).Seconds()
|
2019-09-06 15:14:37 -04:00
|
|
|
if x >= fade1b && x < start2 && animating {
|
|
|
|
animOff()
|
|
|
|
go func() {
|
2019-09-06 21:14:06 -04:00
|
|
|
time.Sleep(time.Millisecond * time.Duration((start2-x)*1000))
|
2019-09-06 15:14:37 -04:00
|
|
|
w.Invalidate()
|
2019-09-06 21:14:06 -04:00
|
|
|
time.Sleep(time.Millisecond * time.Duration((fade2a-start2)*1000))
|
2019-09-06 15:14:37 -04:00
|
|
|
animOn()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
if (x >= fade1a && x < fade1b) || (x > fade2a && x < end) {
|
|
|
|
if !animating {
|
|
|
|
animOn()
|
|
|
|
}
|
2019-09-06 13:36:06 -04:00
|
|
|
var fade float64
|
|
|
|
switch {
|
|
|
|
case x < fade1b:
|
|
|
|
fade = (fade1b - x) / (fade1b - fade1a)
|
|
|
|
case x > fade2a:
|
|
|
|
fade = (end - x) / (end - fade2a)
|
|
|
|
}
|
2019-09-06 11:55:31 -04:00
|
|
|
overlay.Color.R = uint8(float64(black.R) * fade)
|
|
|
|
overlay.Color.G = uint8(float64(black.G) * fade)
|
|
|
|
overlay.Color.B = uint8(float64(black.B) * fade)
|
|
|
|
overlay.Color.A = uint8(float64(black.A) * fade)
|
|
|
|
overlay.Background.R = uint8(float64(darkgray.R) * fade)
|
|
|
|
overlay.Background.G = uint8(float64(darkgray.G) * fade)
|
|
|
|
overlay.Background.B = uint8(float64(darkgray.B) * fade)
|
|
|
|
overlay.Background.A = uint8(float64(darkgray.A) * fade)
|
2019-09-06 15:14:37 -04:00
|
|
|
}
|
|
|
|
if x <= fade1b || (x > start2 && x < end) {
|
2019-09-06 13:36:06 -04:00
|
|
|
if x > start2 && overlay == copied {
|
|
|
|
overlay = cleared
|
|
|
|
overlay.Color = black
|
|
|
|
overlay.Background = darkgray
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
cs = margincs
|
|
|
|
al := layout.Align{Alignment: layout.SE}
|
|
|
|
cs = al.Begin(ops, cs)
|
|
|
|
cs.Width.Min = cs.Width.Max
|
2019-09-06 11:55:31 -04:00
|
|
|
dims = al.End(overlay.Layout(c, ops, cs))
|
2019-09-06 15:14:37 -04:00
|
|
|
}
|
|
|
|
if x > start2 && x < fade2a {
|
2019-09-06 21:14:06 -04:00
|
|
|
// animOff()
|
2019-09-06 15:14:37 -04:00
|
|
|
}
|
|
|
|
if animating && x > end {
|
2019-09-06 10:45:18 -04:00
|
|
|
animOff()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 08:45:59 -04:00
|
|
|
idPage = func() {
|
|
|
|
if !animating {
|
|
|
|
animOn()
|
|
|
|
}
|
|
|
|
cs = flex.Rigid()
|
|
|
|
c2 := flex.End(idLabel.Layout(ops, cs))
|
|
|
|
var c3 layout.FlexChild
|
|
|
|
//if len(idBtns) == 0 {
|
2019-09-10 11:36:03 -04:00
|
|
|
updateIdBtns()
|
2019-09-10 08:45:59 -04:00
|
|
|
//}
|
|
|
|
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 {
|
2019-09-10 11:36:03 -04:00
|
|
|
log(Info, "Password exists")
|
2019-09-10 08:45:59 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
confPage = func() {
|
|
|
|
cs = flex.Rigid()
|
|
|
|
c2 := flex.End(storeDirLabel.Layout(ops, cs))
|
|
|
|
cs = flex.Rigid()
|
|
|
|
c3 := flex.End(storeDirEd.Layout(c, q, ops, cs))
|
|
|
|
cs = flex.Rigid()
|
|
|
|
al := &layout.Align{Alignment: layout.E}
|
|
|
|
cs = al.Begin(ops, cs)
|
2019-09-06 10:52:27 -04:00
|
|
|
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
|
|
|
btnflx.Init(ops, cs)
|
|
|
|
cs = btnflx.Rigid()
|
|
|
|
bc1 := btnflx.End(backBtn.Layout(c, q, ops, cs))
|
|
|
|
cs = btnflx.Rigid()
|
|
|
|
bc2 := btnflx.End(saveBtn.Layout(c, q, ops, cs))
|
|
|
|
dims = btnflx.Layout(bc1, bc2)
|
2019-09-06 10:45:18 -04:00
|
|
|
c4 := flex.End(al.End(dims))
|
|
|
|
flex.Layout(c1, c2, c3, c4)
|
2019-09-06 10:52:27 -04:00
|
|
|
if backBtn.Clicked() {
|
|
|
|
log(Info, "Back")
|
|
|
|
storeDirEd.SetText(store.Dir)
|
|
|
|
w.Invalidate()
|
|
|
|
page = listPage
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
if saveBtn.Clicked() {
|
|
|
|
log(Info, "Save")
|
|
|
|
go func() { // do not block UI thread
|
|
|
|
store.Dir = storeDirEd.Text()
|
2019-09-10 08:45:59 -04:00
|
|
|
store.Id = ""
|
2019-09-06 10:45:18 -04:00
|
|
|
passgo.GetStore(&store)
|
|
|
|
Config.StoreDir = store.Dir
|
2019-09-10 08:45:59 -04:00
|
|
|
store.Mkdir()
|
2019-09-06 10:45:18 -04:00
|
|
|
saveConf()
|
2019-09-10 08:45:59 -04:00
|
|
|
chdir <- struct{}{}
|
2019-09-06 10:45:18 -04:00
|
|
|
}()
|
2019-09-06 10:52:27 -04:00
|
|
|
w.Invalidate()
|
2019-09-06 10:45:18 -04:00
|
|
|
page = listPage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 21:14:06 -04:00
|
|
|
promptPage = func() {
|
2019-09-06 13:36:06 -04:00
|
|
|
submit := false
|
|
|
|
for e, ok := promptEd.Next(c, q); ok; e, ok = promptEd.Next(c, q) {
|
|
|
|
switch e.(type) {
|
|
|
|
case text.SubmitEvent:
|
|
|
|
log(Info, "Submit")
|
|
|
|
submit = true
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 11:43:14 -04:00
|
|
|
cs = flex.Rigid()
|
|
|
|
c2 := flex.End(promptLabel.Layout(ops, cs))
|
|
|
|
cs = flex.Rigid()
|
|
|
|
c3 := flex.End(promptEd.Layout(c, q, ops, cs))
|
|
|
|
cs = flex.Rigid()
|
|
|
|
al := &layout.Align{Alignment: layout.E}
|
|
|
|
cs = al.Begin(ops, cs)
|
2019-09-06 11:55:31 -04:00
|
|
|
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
|
|
|
btnflx.Init(ops, cs)
|
|
|
|
cs = btnflx.Rigid()
|
|
|
|
bc1 := btnflx.End(backBtn.Layout(c, q, ops, cs))
|
|
|
|
cs = btnflx.Rigid()
|
|
|
|
bc2 := btnflx.End(okBtn.Layout(c, q, ops, cs))
|
|
|
|
dims = btnflx.Layout(bc1, bc2)
|
|
|
|
c4 := flex.End(al.End(dims))
|
2019-09-06 11:43:14 -04:00
|
|
|
flex.Layout(c1, c2, c3, c4)
|
2019-09-06 13:36:06 -04:00
|
|
|
if submit || okBtn.Clicked() {
|
2019-09-06 11:43:14 -04:00
|
|
|
log(Info, "Ok")
|
|
|
|
go func() { // do not block UI thread
|
2019-09-06 21:14:06 -04:00
|
|
|
passch <- []byte(promptEd.Text())
|
2019-09-06 11:43:14 -04:00
|
|
|
}()
|
2019-09-06 11:55:31 -04:00
|
|
|
w.Invalidate()
|
2019-09-06 11:43:14 -04:00
|
|
|
page = listPage
|
|
|
|
}
|
|
|
|
if backBtn.Clicked() {
|
|
|
|
log(Info, "Back")
|
|
|
|
go func() {
|
|
|
|
passch <- nil // cancel prompt
|
|
|
|
}()
|
2019-09-06 11:55:31 -04:00
|
|
|
w.Invalidate()
|
2019-09-06 11:43:14 -04:00
|
|
|
page = listPage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
page = listPage
|
|
|
|
|
2019-09-05 06:41:39 -04:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-updated:
|
|
|
|
log(Info, "UPDATE")
|
2019-09-04 22:19:39 -04:00
|
|
|
updateBtns()
|
2019-09-05 06:41:39 -04:00
|
|
|
w.Invalidate()
|
2019-09-06 10:45:18 -04:00
|
|
|
case <-anim.C:
|
|
|
|
w.Invalidate()
|
2019-09-05 06:41:39 -04:00
|
|
|
case e := <-w.Events():
|
2019-09-04 22:19:39 -04:00
|
|
|
switch e := e.(type) {
|
|
|
|
case app.DestroyEvent:
|
|
|
|
return
|
|
|
|
case app.UpdateEvent:
|
2019-09-06 10:45:18 -04:00
|
|
|
c = &e.Config
|
2019-09-04 22:19:39 -04:00
|
|
|
ops.Reset()
|
2019-09-05 06:41:39 -04:00
|
|
|
faces.Reset(c)
|
2019-09-06 10:45:18 -04:00
|
|
|
cs = layout.RigidConstraints(e.Size)
|
2019-09-19 17:28:15 -04:00
|
|
|
sysinset.Top = e.Insets.Top
|
|
|
|
sysinset.Bottom = e.Insets.Bottom
|
|
|
|
sysinset.Left = e.Insets.Left
|
|
|
|
sysinset.Right = e.Insets.Right
|
|
|
|
cs = sysinset.Begin(c, ops, cs)
|
2019-09-04 22:19:39 -04:00
|
|
|
cs = margin.Begin(c, ops, cs)
|
2019-09-06 10:45:18 -04:00
|
|
|
margincs = cs
|
|
|
|
flex.Init(ops, cs)
|
|
|
|
cs = flex.Rigid()
|
|
|
|
titleflex.Init(ops, cs)
|
|
|
|
cs = titleflex.Rigid()
|
2019-09-10 08:45:59 -04:00
|
|
|
ct2 := titleflex.End(plusBtn.Layout(c, q, ops, cs))
|
|
|
|
cs = titleflex.Rigid()
|
|
|
|
ct3 := titleflex.End(dotsBtn.Layout(c, q, ops, cs))
|
2019-09-06 10:45:18 -04:00
|
|
|
cs = titleflex.Flexible(1.0)
|
|
|
|
cs.Width.Min = cs.Width.Max
|
|
|
|
ct1 := titleflex.End(title.Layout(ops, cs))
|
2019-09-10 08:45:59 -04:00
|
|
|
c1 = flex.End(titleflex.Layout(ct1, ct2, ct3))
|
2019-09-04 22:19:39 -04:00
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
page()
|
|
|
|
|
2019-09-19 17:28:15 -04:00
|
|
|
sysinset.End(margin.End(dims))
|
2019-09-10 08:45:59 -04:00
|
|
|
|
|
|
|
if dotsBtn.Clicked() {
|
|
|
|
log(Info, "Configure")
|
|
|
|
w.Invalidate()
|
|
|
|
page = confPage
|
|
|
|
}
|
|
|
|
if plusBtn.Clicked() {
|
|
|
|
log(Info, "Plus")
|
|
|
|
w.Invalidate()
|
|
|
|
insName, insValue = "", ""
|
|
|
|
page = insertPage
|
|
|
|
}
|
2019-09-05 06:41:39 -04:00
|
|
|
w.Update(ops)
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|
2019-09-05 06:41:39 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|