Skip to content

Commit

Permalink
Initial commit of ui rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 4, 2025
1 parent 7d446c1 commit f085af4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 669 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
fyne.io/fyne/v2 v2.5.3
fyne.io/x/fyne v0.0.0-20241224222935-5be10b3dd763
github.com/fynelabs/fyneselfupdate v0.1.1
github.com/fynelabs/selfupdate v0.2.0
github.com/klauspost/compress v1.17.11
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fyne.io/fyne/v2 v2.5.3 h1:k6LjZx6EzRZhClsuzy6vucLZBstdH2USDGHSGWq8ly8=
fyne.io/fyne/v2 v2.5.3/go.mod h1:0GOXKqyvNwk3DLmsFu9v0oYM0ZcD1ysGnlHCerKoAmo=
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
fyne.io/x/fyne v0.0.0-20241224222935-5be10b3dd763 h1:eKeSmgu0Ege3moDYC7ZqYB7ypOgiUzV/cyt1GAAJ/A8=
fyne.io/x/fyne v0.0.0-20241224222935-5be10b3dd763/go.mod h1:pWJAjc53T8QL7CBpByv7zFUI4Au5Pbh6JC30eViEHVU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
Expand Down
71 changes: 0 additions & 71 deletions internal/ui/about.go

This file was deleted.

97 changes: 2 additions & 95 deletions internal/ui/recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,9 @@ package ui

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/Jacalz/rymdport/v3/completion"
"github.com/Jacalz/rymdport/v3/internal/transport"
"github.com/Jacalz/rymdport/v3/internal/transport/bridge"
"github.com/Jacalz/rymdport/v3/internal/util"
)

type recv struct {
codeEntry *completionEntry
data bridge.RecvData

window fyne.Window
}

func newRecvTab(w fyne.Window, c *transport.Client) *container.TabItem {
recv := &recv{window: w}

return &container.TabItem{
Text: "Receive",
Icon: theme.DownloadIcon(),
Content: recv.buildUI(c),
}
}

func (r *recv) buildUI(client *transport.Client) *fyne.Container {
r.codeEntry = newCompletionEntry(client, r.window.Canvas(), client.App)
r.codeEntry.OnSubmitted = func(_ string) { r.onRecv() }

codeButton := &widget.Button{Text: "Receive", Icon: theme.DownloadIcon(), OnTapped: r.onRecv}

r.data = bridge.RecvData{Client: client, Window: r.window}

box := container.NewVBox(&widget.Separator{}, container.NewGridWithColumns(2, r.codeEntry, codeButton), &widget.Separator{})
return container.NewBorder(box, nil, nil, nil, r.data.NewRecvList())
}

func (r *recv) onRecv() {
if err := r.codeEntry.Validate(); err != nil || r.codeEntry.Text == "" {
dialog.ShowInformation("Invalid code", "The code is invalid. Please try again.", r.window)
return
}

r.data.NewReceive(r.codeEntry.Text)
r.codeEntry.SetText("")
}

type completionEntry struct {
widget.Entry
driver desktop.Driver
canvas fyne.Canvas
complete completion.TabCompleter
}

// AcceptsTab overrides tab handling to allow tabs as input.
func (c *completionEntry) AcceptsTab() bool {
return true
}

// TypedKey adapts the key inputs to handle tab completion.
func (c *completionEntry) TypedKey(key *fyne.KeyEvent) {
switch key.Name {
case desktop.KeyShiftLeft, desktop.KeyShiftRight:
case fyne.KeyTab:
if c.driver.CurrentKeyModifiers()&fyne.KeyModifierShift != 0 {
c.setCompletion(c.complete.Previous)
return
}

c.setCompletion(c.complete.Next)
case fyne.KeyEscape:
c.canvas.Unfocus()
default:
c.complete.Reset()
c.Entry.TypedKey(key)
}
}

func (c *completionEntry) setCompletion(lookup func(string) string) {
text := lookup(c.Text)
c.CursorColumn = len(text)
c.SetText(text)
}

func newCompletionEntry(client *transport.Client, canvas fyne.Canvas, app fyne.App) *completionEntry {
entry := &completionEntry{
canvas: canvas,
driver: app.Driver().(desktop.Driver),
Entry: widget.Entry{
PlaceHolder: "Enter code", Scroll: container.ScrollHorizontalOnly, Validator: util.CodeValidator,
},
}
entry.complete.Generate = client.GenerateCodeCompletion
entry.ExtendBaseWidget(entry)
return entry
func createRecvPage(_ fyne.App, _ fyne.Window) fyne.CanvasObject {
return widget.NewLabel("Receive something")
}
97 changes: 2 additions & 95 deletions internal/ui/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,9 @@ package ui

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/Jacalz/rymdport/v3/internal/transport"
"github.com/Jacalz/rymdport/v3/internal/transport/bridge"
"github.com/Jacalz/rymdport/v3/internal/util"
)

type send struct {
contentPicker *dialog.CustomDialog
fileDialog *dialog.FileDialog
directoryDialog *dialog.FileDialog

data bridge.SendData

client *transport.Client
window fyne.Window
}

func newSend(w fyne.Window, c *transport.Client) *send {
return &send{client: c, window: w}
}

func (s *send) newSendTab() *container.TabItem {
return &container.TabItem{
Text: "Send",
Icon: theme.MailSendIcon(),
Content: s.buildUI(s.window),
}
}

func (s *send) buildUI(window fyne.Window) *fyne.Container {
fileChoice := &widget.Button{Text: "File", Icon: theme.FileIcon(), OnTapped: s.onFileSend}
directoryChoice := &widget.Button{Text: "Directory", Icon: theme.FolderOpenIcon(), OnTapped: s.onDirSend}
textChoice := &widget.Button{Text: "Text", Icon: theme.DocumentCreateIcon(), OnTapped: s.onTextSend}
codeChoice := &widget.Check{Text: "Use a custom code", OnChanged: s.onCustomCode, Checked: s.client.CustomCode}
choiceContent := container.NewGridWithColumns(1, fileChoice, directoryChoice, textChoice, codeChoice)
s.contentPicker = dialog.NewCustom("Pick a content type", "Cancel", choiceContent, window)

s.data = bridge.SendData{Client: s.client, Window: window}
contentToSend := &widget.Button{Text: "Add content to send", Icon: theme.ContentAddIcon(), OnTapped: func() {
codeChoice.SetChecked(s.client.CustomCode)
s.contentPicker.Show()
}}

s.fileDialog = dialog.NewFileOpen(s.data.OnFileSelect, window)
s.directoryDialog = dialog.NewFolderOpen(s.data.OnDirSelect, window)

box := container.NewVBox(&widget.Separator{}, contentToSend, &widget.Separator{})
return container.NewBorder(box, nil, nil, nil, s.data.NewSendList())
}

func (s *send) onFileSend() {
s.contentPicker.Hide()
s.fileDialog.Resize(util.WindowSizeToDialog(s.window.Canvas().Size()))
s.fileDialog.Show()
}

func (s *send) onDirSend() {
s.contentPicker.Hide()
s.fileDialog.Resize(util.WindowSizeToDialog(s.window.Canvas().Size()))
s.directoryDialog.Show()
}

func (s *send) onTextSend() {
s.contentPicker.Hide()
s.data.SendText()
}

func (s *send) onCustomCode(enabled bool) {
s.client.CustomCode = enabled
}

func (s *send) newTransfer(uris []fyne.URI) {
if len(uris) == 0 {
return
}

if len(uris) > 1 {
s.data.NewSendFromFiles(uris)
return
}

isDir, err := storage.CanList(uris[0])
if err != nil {
fyne.LogError("Could not check if path is directory", err)
return
}

if !isDir {
reader, err := storage.Reader(uris[0])
s.data.OnFileSelect(reader, err)
} else {
reader, err := storage.ListerForURI(uris[0])
s.data.OnDirSelect(reader, err)
}
func createSendPage(_ fyne.App, _ fyne.Window) fyne.CanvasObject {
return widget.NewLabel("Send something")
}
Loading

0 comments on commit f085af4

Please sign in to comment.