2019-09-04 22:19:39 -04:00
|
|
|
// +build darwin linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-11-20 14:30:43 -05:00
|
|
|
"fmt"
|
2019-09-06 10:45:18 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-09-05 06:41:39 -04:00
|
|
|
"path"
|
2019-11-20 14:30:43 -05:00
|
|
|
"runtime"
|
|
|
|
"runtime/pprof"
|
2019-10-01 18:22:38 -04:00
|
|
|
"strconv"
|
2019-09-05 06:41:39 -04:00
|
|
|
"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
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
"gioui.org/app"
|
|
|
|
"gioui.org/io/key"
|
|
|
|
"gioui.org/io/system"
|
|
|
|
"gioui.org/layout"
|
|
|
|
"gioui.org/text"
|
|
|
|
"gioui.org/unit"
|
|
|
|
"gioui.org/widget"
|
|
|
|
"gioui.org/widget/material"
|
2019-09-04 22:19:39 -04:00
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
"gioui.org/font/gofont"
|
2019-09-10 11:31:57 -04:00
|
|
|
|
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-10-01 18:22:38 -04:00
|
|
|
"git.wow.st/gmp/rand"
|
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-11-20 14:30:43 -05:00
|
|
|
if false { go func() {
|
|
|
|
f, err := os.Create("cpuprofile")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Can't create CPU profile\n")
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
fmt.Printf("Starting CPU profile\n")
|
|
|
|
if err := pprof.StartCPUProfile(f); err != nil {
|
|
|
|
fmt.Printf("Can't start CPU profile\n")
|
|
|
|
f.Close()
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
fmt.Printf("Stopping CPU profile\n")
|
|
|
|
pprof.StopCPUProfile()
|
|
|
|
f.Close()
|
|
|
|
fmt.Printf("CPU profile written\n")
|
|
|
|
}() }
|
2019-09-06 10:45:18 -04:00
|
|
|
var fd *os.File
|
2019-11-20 14:30:43 -05:00
|
|
|
var err error
|
|
|
|
confDir, err = getConfDir()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Can't get config directory")
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
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-11-20 14:30:43 -05:00
|
|
|
go func() {
|
|
|
|
log(Info,"passgo.Identities()")
|
|
|
|
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-11-20 14:30:43 -05:00
|
|
|
fontSize float32
|
2019-09-10 11:31:57 -04:00
|
|
|
confDir string
|
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-11-20 14:30:43 -05:00
|
|
|
th *material.Theme
|
2019-09-04 22:19:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func Updater() {
|
2019-11-20 14:30:43 -05:00
|
|
|
time.Sleep(time.Second * 2)
|
2019-09-04 22:19:39 -04:00
|
|
|
update := func() {
|
2019-11-20 14:30:43 -05:00
|
|
|
fmt.Printf("update()\n")
|
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 {
|
2019-11-20 14:30:43 -05:00
|
|
|
log(Error, "Config file = ", path.Join(confDir, "config.yml"))
|
|
|
|
log(Fatal, "Cannot open config file: ", err.Error())
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
|
|
|
}
|
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-11-20 14:30:43 -05:00
|
|
|
gofont.Register()
|
|
|
|
th = material.NewTheme()
|
|
|
|
th.TextSize = unit.Sp(fontSize)
|
2019-09-06 21:14:06 -04:00
|
|
|
w := app.NewWindow(
|
2019-11-20 14:30:43 -05:00
|
|
|
app.Size(unit.Dp(250), unit.Dp(500)),
|
|
|
|
app.Title("passgo"))
|
|
|
|
gtx := &layout.Context{Queue: w.Queue()}
|
|
|
|
time.Sleep(time.Second/5)
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
var margincs layout.Constraints
|
2019-11-20 14:30:43 -05:00
|
|
|
|
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
|
|
|
|
2019-09-19 17:28:15 -04:00
|
|
|
sysinset := &layout.Inset{}
|
2019-11-20 14:30:43 -05:00
|
|
|
margin := layout.UniformInset(unit.Dp(10))
|
2019-09-06 10:45:18 -04:00
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
title := th.Body1("passgo")
|
2019-09-10 08:45:59 -04:00
|
|
|
dotsBtn := &Button{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-06 10:46:23 -04:00
|
|
|
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-11-20 14:30:43 -05:00
|
|
|
copied := &Overlay{Size: unit.Sp(fontSize), 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-11-20 14:30:43 -05:00
|
|
|
cleared := &Overlay{Size: unit.Sp(fontSize), Text: "clipboard cleared",
|
2019-09-06 11:55:31 -04:00
|
|
|
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-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-06 10:46:23 -04:00
|
|
|
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() {
|
2019-11-20 14:30:43 -05:00
|
|
|
//return
|
|
|
|
log(Info,"passgo.Identities()")
|
2019-09-10 08:45:59 -04:00
|
|
|
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{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-10 08:45:59 -04:00
|
|
|
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-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-06 10:46:23 -04:00
|
|
|
Label: "configure",
|
|
|
|
Alignment: text.Middle,
|
|
|
|
Color: black,
|
2019-09-06 10:45:18 -04:00
|
|
|
Background: gray,
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
storeDirLabel := th.Label(unit.Sp(fontSize), "Store directory")
|
|
|
|
storeDirEd := &widget.Editor{ SingleLine: true}
|
2019-09-06 10:45:18 -04:00
|
|
|
storeDirEd.SetText(store.Dir)
|
|
|
|
saveBtn := &Button{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-06 10:46:23 -04:00
|
|
|
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{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-06 10:52:27 -04:00
|
|
|
Label: "back",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
confirmLabel := th.Label(unit.Sp(fontSize), "Password exists. Overwrite?")
|
2019-09-10 08:45:59 -04:00
|
|
|
yesBtn := &Button{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-10 08:45:59 -04:00
|
|
|
Label: "yes",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
2019-09-06 10:45:18 -04:00
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
promptLabel := th.Label(unit.Sp(fontSize), "passphrase")
|
|
|
|
promptEd := &widget.Editor{ SingleLine: true, Submit: true }
|
2019-09-06 11:43:14 -04:00
|
|
|
okBtn := &Button{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-06 11:43:14 -04:00
|
|
|
Label: "ok",
|
|
|
|
Alignment: text.End,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
plusBtn := &Button{
|
2019-11-20 14:30:43 -05:00
|
|
|
Size: unit.Sp(fontSize),
|
2019-09-10 08:45:59 -04:00
|
|
|
Label: "+",
|
|
|
|
Alignment: text.Middle,
|
|
|
|
Color: black,
|
|
|
|
Background: gray,
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
insertLabel := th.Label(unit.Sp(fontSize), "Insert")
|
|
|
|
passnameLabel := th.Label(unit.Sp(fontSize), "password name:")
|
|
|
|
passnameEd := &widget.Editor{ SingleLine: true }
|
|
|
|
passvalLabel := th.Label(unit.Sp(fontSize), "password value:")
|
|
|
|
passvalEd := &widget.Editor{ SingleLine: true, Submit: true }
|
2019-09-10 08:45:59 -04:00
|
|
|
|
2019-11-20 14:30:43 -05:00
|
|
|
noidLabel := th.Label(unit.Sp(fontSize), "No GPG ids available. Please create a private key")
|
|
|
|
idLabel := th.Label(unit.Sp(fontSize), "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-11-20 14:30:43 -05:00
|
|
|
anim = time.NewTicker(time.Second / 30)
|
2019-09-06 10:45:18 -04:00
|
|
|
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-11-20 14:30:43 -05:00
|
|
|
_ = idPage
|
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-11-20 14:30:43 -05:00
|
|
|
c2 := flex.Flex(gtx, 1.0, func() {
|
|
|
|
mux.Lock()
|
|
|
|
if lst.Dragging() {
|
|
|
|
key.HideInputOp{}.Add(gtx.Ops)
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
switch {
|
|
|
|
case store.Empty:
|
|
|
|
confBtn.Layout(gtx)
|
|
|
|
if confBtn.Clicked() {
|
|
|
|
log(Info, "Configure")
|
|
|
|
w.Invalidate()
|
|
|
|
page = confPage
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
//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) {
|
|
|
|
btn := passBtns[i]
|
|
|
|
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
|
|
|
btn.Layout(gtx)
|
|
|
|
if btn.Clicked() {
|
|
|
|
log(Info, "Clicked ", btn.Label)
|
|
|
|
// don't block UI thread on decryption attempt
|
|
|
|
go func(name string) {
|
|
|
|
p, err := store.Decrypt(name, prompt)
|
|
|
|
//p, err := store.Decrypt(name)
|
|
|
|
if err == nil {
|
|
|
|
passgo.Clip(p)
|
|
|
|
overlayStart = time.Now()
|
|
|
|
overlay = copied
|
|
|
|
overlay.Color = black
|
|
|
|
overlay.Background = darkgray
|
|
|
|
w.Invalidate()
|
|
|
|
go func() {
|
|
|
|
time.Sleep(time.Millisecond * time.Duration(fade1a*1000))
|
|
|
|
animOn()
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
time.Sleep(time.Millisecond * time.Duration(Config.ClearDelay*1000))
|
|
|
|
log(Info, "clearing clipboard")
|
|
|
|
passgo.Clip("")
|
|
|
|
}()
|
|
|
|
} else {
|
|
|
|
log(Info, "Can't decrypt ", name)
|
|
|
|
log(Info, err)
|
|
|
|
}
|
|
|
|
}(pathnames[i])
|
|
|
|
}
|
|
|
|
})
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
mux.Unlock()
|
|
|
|
})
|
|
|
|
flex.Layout(gtx, 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-11-20 14:30:43 -05:00
|
|
|
gtx.Constraints = margincs
|
|
|
|
al := layout.Align(layout.SE)
|
|
|
|
al.Layout(gtx, func() {
|
|
|
|
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
|
|
|
overlay.Layout(gtx)
|
|
|
|
})
|
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() {
|
2019-11-20 14:30:43 -05:00
|
|
|
log(Info,"idPage()")
|
2019-09-10 08:45:59 -04:00
|
|
|
if !animating {
|
|
|
|
animOn()
|
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
c2 := flex.Rigid(gtx, func() {
|
|
|
|
idLabel.Layout(gtx)
|
|
|
|
})
|
2019-09-10 08:45:59 -04:00
|
|
|
//if len(idBtns) == 0 {
|
2019-09-10 11:36:03 -04:00
|
|
|
updateIdBtns()
|
2019-09-10 08:45:59 -04:00
|
|
|
//}
|
2019-11-20 14:30:43 -05:00
|
|
|
c3 := flex.Rigid(gtx, func() {
|
|
|
|
if len(idBtns) == 0 { // still zero after update
|
|
|
|
noidLabel.Layout(gtx)
|
|
|
|
} else {
|
|
|
|
for i := 0; i < len(idBtns); i++ {
|
|
|
|
lst.Layout(gtx, len(idBtns), func(i int) {
|
|
|
|
idBtns[i].Layout(gtx)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
for _, btn := range idBtns {
|
|
|
|
if btn.Clicked() {
|
|
|
|
log(Info, "ID selected: ", btn.Label)
|
|
|
|
store.SetID(btn.Label)
|
|
|
|
w.Invalidate()
|
|
|
|
animOff()
|
|
|
|
page = listPage
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
}
|
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
})
|
|
|
|
flex.Layout(gtx, c1, c2, c3)
|
2019-09-10 08:45:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var insName, insValue string
|
2019-11-20 14:30:43 -05:00
|
|
|
genBtn := &SelButton{SelColor: gray}
|
|
|
|
genBtn.Button = Button{Size: unit.Sp(fontSize), Label: "generate"}
|
|
|
|
symBtn := &SelButton{SelColor: gray}
|
|
|
|
numBtn := &SelButton{SelColor: gray}
|
|
|
|
symBtn.Button = Button{Size: unit.Sp(fontSize), Label: "@"}
|
|
|
|
numBtn.Button = Button{Size: unit.Sp(fontSize), Label: "#"}
|
|
|
|
symBtn.Select()
|
|
|
|
numBtn.Select()
|
|
|
|
lenEd := &widget.Editor{ SingleLine: true, Alignment: text.End }
|
2019-10-01 18:22:38 -04:00
|
|
|
lenEd.SetText("15")
|
2019-11-20 14:30:43 -05:00
|
|
|
lBtn := &Button{Size: unit.Sp(fontSize), Label: "<", Background: gray}
|
|
|
|
rBtn := &Button{Size: unit.Sp(fontSize), Label: ">", Background: gray}
|
2019-10-01 18:22:38 -04:00
|
|
|
|
|
|
|
updatePw := func() {
|
|
|
|
if !genBtn.Selected {
|
|
|
|
passvalEd.SetText("")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var gen rand.Generator
|
|
|
|
switch {
|
|
|
|
case symBtn.Selected && numBtn.Selected:
|
|
|
|
gen = rand.Char
|
|
|
|
case symBtn.Selected:
|
|
|
|
gen = rand.LettersSymbols
|
|
|
|
case numBtn.Selected:
|
|
|
|
gen = rand.LetterDigits
|
|
|
|
default:
|
|
|
|
gen = rand.Letter
|
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
l, _ := strconv.Atoi(lenEd.Text())
|
|
|
|
pw, _ := rand.Slice(gen, l)
|
2019-10-01 18:22:38 -04:00
|
|
|
passvalEd.SetText(string(pw))
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
|
|
|
|
insertPage = func() {
|
2019-11-20 14:30:43 -05:00
|
|
|
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) })
|
2019-10-01 18:22:38 -04:00
|
|
|
|
2019-09-10 08:45:59 -04:00
|
|
|
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
2019-11-20 14:30:43 -05:00
|
|
|
al := layout.Align(layout.E)
|
|
|
|
c7 := flex.Rigid(gtx, func() {
|
|
|
|
bc1 := btnflx.Rigid(gtx, func() { lBtn.Layout(gtx) })
|
|
|
|
bc2 := btnflx.Rigid(gtx, 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) })
|
|
|
|
|
|
|
|
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) })
|
|
|
|
al.Layout(gtx, func() {
|
|
|
|
btnflx.Layout(gtx, bc1, bc2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
flex.Layout(gtx, c1, c2, c3, c4, c5, c6, c7, c8)
|
2019-10-01 18:22:38 -04:00
|
|
|
|
|
|
|
if lBtn.Clicked() {
|
2019-11-20 14:30:43 -05:00
|
|
|
l, _ := strconv.Atoi(lenEd.Text())
|
2019-10-01 18:22:38 -04:00
|
|
|
if l > 0 {
|
|
|
|
l -= 1
|
|
|
|
}
|
|
|
|
lenEd.SetText(strconv.Itoa(l))
|
|
|
|
updatePw()
|
|
|
|
w.Invalidate()
|
|
|
|
}
|
|
|
|
if rBtn.Clicked() {
|
2019-11-20 14:30:43 -05:00
|
|
|
l, _ := strconv.Atoi(lenEd.Text())
|
|
|
|
lenEd.SetText(strconv.Itoa(l + 1))
|
2019-10-01 18:22:38 -04:00
|
|
|
updatePw()
|
|
|
|
w.Invalidate()
|
|
|
|
}
|
|
|
|
if genBtn.Clicked() {
|
|
|
|
updatePw()
|
|
|
|
w.Invalidate()
|
|
|
|
}
|
|
|
|
if symBtn.Clicked() {
|
|
|
|
updatePw()
|
|
|
|
w.Invalidate()
|
|
|
|
}
|
|
|
|
if numBtn.Clicked() {
|
|
|
|
updatePw()
|
|
|
|
w.Invalidate()
|
|
|
|
}
|
2019-09-10 08:45:59 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
//Do not block the UI thread.
|
|
|
|
go store.Insert(passnameEd.Text(), passvalEd.Text())
|
2019-09-10 08:45:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmPage = func() {
|
2019-11-20 14:30:43 -05:00
|
|
|
c2 := flex.Rigid(gtx, func() {
|
|
|
|
confirmLabel.Layout(gtx)
|
|
|
|
})
|
|
|
|
al := layout.Align(layout.E)
|
2019-09-10 08:45:59 -04:00
|
|
|
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
2019-11-20 14:30:43 -05:00
|
|
|
c3 := flex.Rigid(gtx, func() {
|
|
|
|
bc1 := btnflx.Rigid(gtx, func() { backBtn.Layout(gtx) })
|
|
|
|
bc2 := btnflx.Rigid(gtx, func() { yesBtn.Layout(gtx) })
|
|
|
|
|
|
|
|
al.Layout(gtx, func() {
|
|
|
|
btnflx.Layout(gtx, bc1, bc2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
flex.Layout(gtx, c1, c2, c3)
|
2019-09-10 08:45:59 -04:00
|
|
|
|
|
|
|
if backBtn.Clicked() {
|
|
|
|
w.Invalidate()
|
|
|
|
page = insertPage
|
|
|
|
}
|
|
|
|
if yesBtn.Clicked() {
|
|
|
|
w.Invalidate()
|
|
|
|
page = listPage
|
2019-11-20 14:30:43 -05:00
|
|
|
go store.Insert(insName, insValue)
|
2019-09-10 08:45:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
confPage = func() {
|
2019-11-20 14:30:43 -05:00
|
|
|
c2 := flex.Rigid(gtx, func() { storeDirLabel.Layout(gtx) })
|
|
|
|
c3 := flex.Rigid(gtx, func() { th.Editor("directory").Layout(gtx, storeDirEd) })
|
|
|
|
|
|
|
|
al := layout.Align(layout.E)
|
|
|
|
c4 := flex.Rigid(gtx, func() {
|
|
|
|
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
|
|
|
bc1 := btnflx.Rigid(gtx, func() {
|
|
|
|
backBtn.Layout(gtx)
|
|
|
|
})
|
|
|
|
bc2 := btnflx.Rigid(gtx, func() {
|
|
|
|
saveBtn.Layout(gtx)
|
|
|
|
})
|
|
|
|
al.Layout(gtx, func() {
|
|
|
|
btnflx.Layout(gtx, bc1, bc2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
flex.Layout(gtx, 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
|
2019-11-20 14:30:43 -05:00
|
|
|
for _, e := range promptEd.Events(gtx) {
|
2019-09-06 13:36:06 -04:00
|
|
|
switch e.(type) {
|
2019-11-20 14:30:43 -05:00
|
|
|
case widget.SubmitEvent:
|
2019-09-06 13:36:06 -04:00
|
|
|
log(Info, "Submit")
|
|
|
|
submit = true
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 14:30:43 -05:00
|
|
|
c2 := flex.Rigid(gtx, func() { promptLabel.Layout(gtx) })
|
|
|
|
c3 := flex.Rigid(gtx, func() { th.Editor("password").Layout(gtx, promptEd) })
|
|
|
|
c4 := flex.Rigid(gtx, func() {
|
|
|
|
al := layout.Align(layout.E)
|
|
|
|
btnflx := &layout.Flex{Axis: layout.Horizontal}
|
|
|
|
bc1 := btnflx.Rigid(gtx, func() {
|
|
|
|
backBtn.Layout(gtx)
|
|
|
|
})
|
|
|
|
bc2 := btnflx.Rigid(gtx, func() {
|
|
|
|
okBtn.Layout(gtx)
|
|
|
|
})
|
|
|
|
al.Layout(gtx, func() {
|
|
|
|
btnflx.Layout(gtx, bc1, bc2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
flex.Layout(gtx, 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-11-20 14:30:43 -05:00
|
|
|
ms := &runtime.MemStats{}
|
|
|
|
x := 0
|
|
|
|
var mallocs uint64
|
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-11-20 14:30:43 -05:00
|
|
|
x++
|
|
|
|
if x == 100 {
|
|
|
|
runtime.ReadMemStats(ms)
|
|
|
|
mallocs = ms.Mallocs
|
|
|
|
}
|
2019-09-04 22:19:39 -04:00
|
|
|
switch e := e.(type) {
|
2019-11-20 14:30:43 -05:00
|
|
|
case system.DestroyEvent:
|
2019-09-04 22:19:39 -04:00
|
|
|
return
|
2019-11-20 14:30:43 -05:00
|
|
|
case system.StageEvent:
|
|
|
|
if e.Stage == system.StageRunning {
|
|
|
|
initPgp(w)
|
|
|
|
}
|
|
|
|
case system.FrameEvent:
|
|
|
|
gtx.Reset(e.Config, 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
|
2019-11-20 14:30:43 -05:00
|
|
|
|
|
|
|
sysinset.Layout(gtx, func() {
|
|
|
|
margin.Layout(gtx, func() {
|
|
|
|
margincs = gtx.Constraints
|
|
|
|
c1 = flex.Rigid(gtx, func() {
|
|
|
|
ct2 := titleflex.Rigid(gtx, func() {
|
|
|
|
plusBtn.Layout(gtx)
|
|
|
|
})
|
|
|
|
ct3 := titleflex.Rigid(gtx, func() {
|
|
|
|
dotsBtn.Layout(gtx)
|
|
|
|
})
|
|
|
|
ct1 := titleflex.Flex(gtx, 1.0, func() {
|
|
|
|
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
|
|
|
title.Layout(gtx)
|
|
|
|
})
|
|
|
|
titleflex.Layout(gtx, ct1, ct2, ct3)
|
|
|
|
})
|
|
|
|
|
|
|
|
page()
|
|
|
|
})
|
|
|
|
})
|
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-11-20 14:30:43 -05:00
|
|
|
e.Frame(gtx.Ops)
|
|
|
|
}
|
|
|
|
if x == 100 {
|
|
|
|
x = 0
|
|
|
|
runtime.ReadMemStats(ms)
|
|
|
|
fmt.Printf("mallocs: %d\n", ms.Mallocs-mallocs)
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|
2019-09-05 06:41:39 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-04 22:19:39 -04:00
|
|
|
}
|