Skip to content

Commit 4707bc8

Browse files
committed
Start to hook up new client code
1 parent 7948858 commit 4707bc8

File tree

7 files changed

+83
-20
lines changed

7 files changed

+83
-20
lines changed

internal/transport/transport.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

internal/ui/components/completion.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package components
2+
3+
import (
4+
"fyne.io/fyne/v2"
5+
"fyne.io/fyne/v2/driver/desktop"
6+
"fyne.io/fyne/v2/widget"
7+
8+
"github.com/Jacalz/rymdport/v3/completion"
9+
)
10+
11+
// NewCompletionEntry returns a new entry widget that allows completing on tab.
12+
func NewCompletionEntry(driver desktop.Driver, generator func(string) []string) *CompletionEntry {
13+
entry := &CompletionEntry{driver: driver}
14+
entry.completer.Generate = generator
15+
entry.ExtendBaseWidget(entry)
16+
return entry
17+
}
18+
19+
// CompletionEntry allows using tab and shift+tab to
20+
// move forwards and backwards from a set of completions.
21+
type CompletionEntry struct {
22+
widget.Entry
23+
driver desktop.Driver
24+
completer completion.TabCompleter
25+
}
26+
27+
// AcceptsTab overrides tab handling to allow tabs as input.
28+
func (c *CompletionEntry) AcceptsTab() bool {
29+
return true
30+
}
31+
32+
// TypedKey adapts the key inputs to handle tab completion.
33+
func (c *CompletionEntry) TypedKey(key *fyne.KeyEvent) {
34+
switch key.Name {
35+
case desktop.KeyShiftLeft, desktop.KeyShiftRight:
36+
case fyne.KeyTab:
37+
completed := ""
38+
39+
if c.driver.CurrentKeyModifiers()&fyne.KeyModifierShift != 0 {
40+
completed = c.completer.Previous(c.Text)
41+
} else {
42+
completed = c.completer.Next(c.Text)
43+
}
44+
45+
c.CursorColumn = len(completed)
46+
c.SetText(completed)
47+
default:
48+
c.completer.Reset()
49+
c.Entry.TypedKey(key)
50+
}
51+
}

internal/ui/recv.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ package ui
33
import (
44
"github.com/Jacalz/rymdport/v3/internal/ui/components"
55
"github.com/Jacalz/rymdport/v3/internal/util"
6+
"github.com/Jacalz/rymdport/v3/internal/wormhole"
67

78
"fyne.io/fyne/v2"
89
"fyne.io/fyne/v2/canvas"
910
"fyne.io/fyne/v2/container"
11+
"fyne.io/fyne/v2/driver/desktop"
1012
"fyne.io/fyne/v2/theme"
1113
"fyne.io/fyne/v2/widget"
1214
)
1315

14-
func buildRecvView(nav *components.StackNavigator, code string) fyne.CanvasObject {
16+
func buildRecvView(_ *wormhole.Client, nav *components.StackNavigator, code string) fyne.CanvasObject {
1517
image := &canvas.Image{FillMode: canvas.ImageFillContain}
1618
image.SetMinSize(fyne.NewSquareSize(150))
1719

@@ -49,20 +51,22 @@ func buildRecvView(nav *components.StackNavigator, code string) fyne.CanvasObjec
4951
)
5052
}
5153

52-
func createRecvPage(nav *components.StackNavigator) fyne.CanvasObject {
54+
func createRecvPage(a fyne.App, client *wormhole.Client, nav *components.StackNavigator) fyne.CanvasObject {
5355
icon := canvas.NewImageFromResource(theme.DownloadIcon())
5456
icon.FillMode = canvas.ImageFillContain
5557
icon.SetMinSize(fyne.NewSquareSize(200))
5658

5759
description := &widget.Label{Text: "Enter a code below to start receiving data.", Alignment: fyne.TextAlignCenter}
5860

59-
code := &widget.Entry{PlaceHolder: "Code from sender", Validator: util.CodeValidator}
61+
code := components.NewCompletionEntry(a.Driver().(desktop.Driver), client.GenerateCodeCompletion)
62+
code.PlaceHolder = "Code from sender"
63+
code.Validator = util.CodeValidator
6064
code.OnSubmitted = func(input string) {
6165
if code.Validator(input) != nil {
6266
return
6367
}
6468

65-
nav.Push(buildRecvView(nav, input), "Receiving Data")
69+
nav.Push(buildRecvView(client, nav, input), "Receiving Data")
6670
}
6771

6872
start := &widget.Button{

internal/ui/setup.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ui
22

33
import (
44
"github.com/Jacalz/rymdport/v3/internal/ui/components"
5+
"github.com/Jacalz/rymdport/v3/internal/wormhole"
56

67
"fyne.io/fyne/v2"
78
"fyne.io/fyne/v2/container"
@@ -18,12 +19,14 @@ func Create(a fyne.App, w fyne.Window) fyne.CanvasObject {
1819
widget.ShowPopUpMenuAtRelativePosition(menu, w.Canvas(), offset, dropdown)
1920
}
2021

22+
client := wormhole.NewClient()
23+
2124
nav := &components.StackNavigator{}
2225
nav.OnBack = nav.Pop
2326
tabs := &container.AppTabs{
2427
Items: []*container.TabItem{
2528
{Text: "Send", Icon: theme.UploadIcon(), Content: createSendPage(w, nav)},
26-
{Text: "Receive", Icon: theme.DownloadIcon(), Content: createRecvPage(nav)},
29+
{Text: "Receive", Icon: theme.DownloadIcon(), Content: createRecvPage(a, client, nav)},
2730
},
2831
}
2932

internal/transport/completion.go renamed to internal/wormhole/completion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transport
1+
package wormhole
22

33
import (
44
"context"
@@ -93,12 +93,12 @@ func (c *Client) activeNameplates() ([]string, error) {
9393
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
9494
defer cancel()
9595

96-
url := c.RendezvousURL
96+
url := c.connection.RendezvousURL
9797
if url == "" {
9898
url = wormhole.DefaultRendezvousURL
9999
}
100100

101-
appID := c.AppID
101+
appID := c.connection.AppID
102102
if appID == "" {
103103
appID = wormhole.WormholeCLIAppID
104104
}

internal/transport/completion_test.go renamed to internal/wormhole/completion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transport
1+
package wormhole
22

33
import (
44
"testing"

internal/wormhole/wormhole.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Package wormhole is a helper around the wormhole package.
2+
package wormhole
3+
4+
import (
5+
"github.com/rymdport/wormhole/wormhole"
6+
)
7+
8+
// NewClient creates a new client object.
9+
func NewClient() *Client {
10+
return &Client{}
11+
}
12+
13+
// Client defines the client for handling sending and receiving.
14+
type Client struct {
15+
connection wormhole.Client
16+
}

0 commit comments

Comments
 (0)