Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds QR code generation for sends #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ require (
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91
google.golang.org/protobuf v1.27.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect
rsc.io/qr v0.2.0
salsa.debian.org/vasudev/gospake2 v0.0.0-20210510093858-d91629950ad1 // indirect
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
salsa.debian.org/vasudev/gospake2 v0.0.0-20180813171123-adcc69dd31d5/go.mod h1:soKzqXBAtqHTODjyA0VzH2iERtpzN1w65eZUfetn2cQ=
salsa.debian.org/vasudev/gospake2 v0.0.0-20210510093858-d91629950ad1 h1:m65DhEZR/5zbgOGW4sQGDZmIwro+xBGIBQGWm43SlxM=
Expand Down
40 changes: 40 additions & 0 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/psanford/wormhole-william-mobile/internal/picker"
"github.com/psanford/wormhole-william-mobile/ui/plog"
"github.com/psanford/wormhole-william/wormhole"
"rsc.io/qr"
)

type UI struct {
Expand Down Expand Up @@ -225,6 +226,7 @@ func (ui *UI) loop(w *app.Window) error {
case <-cancelChan:
cancel()
statusMsg = "Transfer mid-stream aborted"
qrSendTxtImg.Src = paint.NewImageOp(image.NewGray(image.Rect(0, 0, 0, 0)))
textCodeTxt.SetText("")
transferInProgress = false
w.Invalidate()
Expand All @@ -239,6 +241,17 @@ func (ui *UI) loop(w *app.Window) error {
return
}

qrText := fmt.Sprintf("wormhole:%s?code=%s", conf.RendezvousURL, code)
qrCode, err := qr.Encode(qrText, qr.M)
if err != nil {
statusMsg = fmt.Sprintf("Send err: %s", err)
plog.Printf("Send err: %s", err)
return
}
qrCode.Scale = 1
qrSendTxtImg.Src = paint.NewImageOp(qrCode.Image())
w.Invalidate()

statusMsg = "Waiting for receiver..."
textCodeTxt.SetText(code)

Expand All @@ -256,6 +269,7 @@ func (ui *UI) loop(w *app.Window) error {
} else if s.OK {
statusMsg = "OK!"
}
qrSendTxtImg.Src = paint.NewImageOp(image.NewGray(image.Rect(0, 0, 0, 0)))
textCodeTxt.SetText("")
w.Invalidate()
}()
Expand Down Expand Up @@ -499,6 +513,17 @@ func (ui *UI) sendFile(ctx context.Context, w *app.Window, path, filename string
return
}

qrText := fmt.Sprintf("wormhole:%s?code=%s", ui.wormholeClient.RendezvousURL, code)
qrCode, err := qr.Encode(qrText, qr.M)
if err != nil {
statusMsg = fmt.Sprintf("Send err: %s", err)
plog.Printf("Send err: %s", err)
return
}
qrCode.Scale = 1
qrSendFileImg.Src = paint.NewImageOp(qrCode.Image())
w.Invalidate()

sendFileCodeTxt.SetText(code)
statusMsg = "Waiting for receiver..."

Expand Down Expand Up @@ -549,6 +574,9 @@ var (

recvCodeEditor = new(RichEditor)
recvMsgBtn = new(widget.Clickable)
qrImage = new(widget.Image)
qrSendTxtImg = new(widget.Image)
qrSendFileImg = new(widget.Image)
scanQRBtn = new(widget.Clickable)
recvTxtMsg = new(Copyable)
itemList = &layout.List{
Expand Down Expand Up @@ -686,6 +714,12 @@ var sendTextTab = Tab{
}
return D{}
},
func(gtx C) D {
if transferInProgress || recvCodeEditor.Text() == "" {
gtx = gtx.Disabled()
}
return qrSendTxtImg.Layout(gtx)
},
func(gtx C) D {
if transferInProgress || confirmInProgress {
return material.Button(th, cancelBtn, "Cancel").Layout(gtx)
Expand Down Expand Up @@ -796,6 +830,12 @@ var sendFileTab = Tab{
gtx.Constraints.Max.Y = gtx.Dp(400)
return CopyField(th, sendFileCodeTxt).Layout(gtx)
},
func(gtx C) D {
if transferInProgress || recvCodeEditor.Text() == "" {
gtx = gtx.Disabled()
}
return qrSendFileImg.Layout(gtx)
},
func(gtx C) D {
if transferInProgress || confirmInProgress {
return material.Button(th, cancelBtn, "Cancel").Layout(gtx)
Expand Down