Skip to content

Commit 1e036e2

Browse files
committed
chore: local and remove branch issue
due to an issue when merging the remote and local dev branch needed to drop the dev branch commits
1 parent 36450f8 commit 1e036e2

File tree

17 files changed

+1357
-0
lines changed

17 files changed

+1357
-0
lines changed

Makefile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#VERSION = $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || echo v0)
2+
VERSION = $(shell git describe --tags --match=v* 2> /dev/null || echo 0.0.0)
3+
4+
APPID = com.github.fabiodcorreia.catch-my-file
5+
ICON = assets/icons/icon-512.png
6+
NAME = CatchMyFile
7+
8+
format:
9+
gofmt -s -w main.go
10+
gofmt -s -w internal/**/*.go
11+
gofmt -s -w cmd/**/*.go
12+
13+
review: format
14+
@echo "============= Spell Check ============= "
15+
@misspell .
16+
17+
@echo "============= Ineffectual Assignments Check ============= "
18+
@ineffassign ./...
19+
20+
@echo "============= Cyclomatic Complexity Check ============= "
21+
@gocyclo -total -over 5 -avg .
22+
23+
@echo "============= Duplication Check ============= "
24+
@dupl -t 25
25+
26+
@echo "============= Repeated Strings Check ============= "
27+
@goconst ./...
28+
29+
@echo "============= Vet Check ============= "
30+
@go vet ./...
31+
32+
build:
33+
go mod tidy
34+
go build -tags release -ldflags="-s -w" -o $(NAME)
35+
36+
darwin:
37+
fyne-cross darwin -arch amd64,arm64 -app-id $(APPID) -icon $(ICON) -app-version $(VERSION) -output $(NAME)
38+
39+
linux:
40+
fyne-cross linux -arch amd64,arm64 -app-id $(APPID) -icon $(ICON) -app-version $(VERSION)
41+
42+
windows:
43+
fyne-cross windows -arch amd64 -app-id $(APPID) -icon $(ICON) -app-version $(VERSION)
44+
45+
bundle:
46+
rm -fr dist
47+
mkdir dist
48+
49+
mv fyne-cross/dist/linux-amd64/$(NAME).tar.gz $(NAME)-$(VERSION)-linux-amd64.tar.gz
50+
mv fyne-cross/dist/linux-arm64/$(NAME).tar.gz $(NAME)-$(VERSION)-linux-arm64.tar.gz
51+
52+
(cd fyne-cross/dist/darwin-amd64/ && zip -r $(NAME)-darwin-amd64.zip $(NAME).app/)
53+
mv fyne-cross/dist/darwin-amd64/$(NAME)-darwin-amd64.zip dist/$(NAME)-$(VERSION)-darwin-amd64.zip
54+
55+
(cd fyne-cross/dist/darwin-arm64/ && zip -r $(NAME)-darwin-arm64.zip $(NAME).app/)
56+
mv fyne-cross/dist/darwin-arm64/$(NAME)-darwin-arm64.zip dist/$(NAME)-$(VERSION)-darwin-arm64.zip
57+
58+
mv fyne-cross/dist/windows-amd64/$(NAME).exe.zip $(NAME)-$(VERSION)-windows-amd64.zip
59+
60+
release: darwin freebsd linux windows bundle
61+
62+
tools:
63+
go get -u github.com/jgautheron/goconst/cmd/goconst
64+
go get -u github.com/mdempsky/unconvert
65+
go get -u github.com/securego/gosec/v2/cmd/gosec
66+
go get -u github.com/alexkohler/prealloc

cmd/frontend/frontend.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package frontend
2+
3+
import (
4+
"os"
5+
"strings"
6+
"time"
7+
8+
"fyne.io/fyne/v2"
9+
"fyne.io/fyne/v2/app"
10+
"fyne.io/fyne/v2/container"
11+
"fyne.io/fyne/v2/theme"
12+
"github.com/fabiodcorreia/catch-my-file/cmd/internal/backend"
13+
)
14+
15+
const (
16+
prefPort = "port"
17+
prefHostname = "hostname"
18+
)
19+
20+
type Frontend struct {
21+
a fyne.App
22+
w fyne.Window
23+
}
24+
25+
func New() *Frontend {
26+
f := &Frontend{
27+
a: app.NewWithID("github.fabiodcorreia.catch-my-file"),
28+
}
29+
f.w = f.a.NewWindow("Catch My File")
30+
f.w.Resize(fyne.NewSize(880, 600))
31+
return f
32+
}
33+
34+
func (f *Frontend) Run() error {
35+
pl := newPeersList()
36+
rl := newTransferList()
37+
sl := newTransferList()
38+
lt := newLogTable()
39+
f.w.SetContent(container.NewAppTabs(
40+
container.NewTabItemWithIcon("Receiving", theme.DownloadIcon(), rl),
41+
container.NewTabItemWithIcon("Sending", theme.UploadIcon(), sl),
42+
container.NewTabItemWithIcon("Peers", theme.ComputerIcon(), pl),
43+
container.NewTabItemWithIcon("Log", theme.ErrorIcon(), lt),
44+
))
45+
46+
hn, err := os.Hostname()
47+
if err != nil {
48+
return err
49+
}
50+
51+
f.a.Preferences().SetString(prefHostname, strings.ReplaceAll(hn, ".", "-")) //! ?
52+
f.a.Preferences().SetInt(prefPort, 8820)
53+
54+
e := backend.NewEngine(f.a.Preferences().String(prefHostname), f.a.Preferences().Int(prefPort))
55+
56+
go func() {
57+
for {
58+
select {
59+
case p := <-e.DiscoverPeers():
60+
pl.NewPeer(p)
61+
case t := <-e.ReceiveTransferNotification():
62+
rl.NewTransfer(t)
63+
case t := <-pl.SendTransfer:
64+
sl.NewTransfer(t)
65+
case rds := <-e.DiscoverServerError():
66+
lt.NewLogRecord(time.Now(), rds)
67+
case rdc := <-e.DiscoverClientError():
68+
lt.NewLogRecord(time.Now(), rdc)
69+
case rts := <-e.TransferServerError():
70+
lt.NewLogRecord(time.Now(), rts)
71+
}
72+
}
73+
}()
74+
75+
f.w.CenterOnScreen()
76+
f.w.SetMaster()
77+
f.w.SetOnClosed(func() {
78+
e.Shutdown()
79+
})
80+
81+
err = e.Start()
82+
if err != nil {
83+
f.a.SendNotification(fyne.NewNotification("Catch My File - Fail to Start", err.Error()))
84+
return err
85+
}
86+
87+
f.w.ShowAndRun()
88+
return nil
89+
}

cmd/frontend/logs.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package frontend
2+
3+
import (
4+
"time"
5+
6+
"fyne.io/fyne/v2"
7+
"fyne.io/fyne/v2/widget"
8+
)
9+
10+
type logTable struct {
11+
widget.Table
12+
items []error
13+
}
14+
15+
func newLogTable() *logTable {
16+
lt := &logTable{
17+
items: make([]error, 0, 20),
18+
}
19+
lt.Table.Length = lt.Length
20+
lt.Table.CreateCell = lt.CreateCell
21+
lt.Table.UpdateCell = lt.UpdateCell
22+
lt.Table.SetColumnWidth(0, 160)
23+
lt.ExtendBaseWidget(lt)
24+
25+
return lt
26+
}
27+
28+
func (lt *logTable) Length() (int, int) {
29+
return len(lt.items), 2
30+
}
31+
32+
func (lt *logTable) CreateCell() fyne.CanvasObject {
33+
return widget.NewLabel("Name")
34+
}
35+
36+
func (lt *logTable) UpdateCell(id widget.TableCellID, item fyne.CanvasObject) {
37+
switch id.Col {
38+
case 0:
39+
item.(*widget.Label).SetText(time.Now().Format("2006-01-02 15:04:05"))
40+
case 1:
41+
item.(*widget.Label).SetText(lt.items[id.Row].Error())
42+
}
43+
}
44+
45+
func (lt *logTable) NewLogRecord(t time.Time, err error) {
46+
if err != nil {
47+
lt.items = append(lt.items, err)
48+
lt.Refresh()
49+
}
50+
}

cmd/frontend/peers.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package frontend
2+
3+
import (
4+
"fmt"
5+
"image/color"
6+
7+
"fyne.io/fyne/v2"
8+
"fyne.io/fyne/v2/canvas"
9+
"fyne.io/fyne/v2/container"
10+
"fyne.io/fyne/v2/dialog"
11+
"fyne.io/fyne/v2/widget"
12+
"github.com/fabiodcorreia/catch-my-file/internal/store"
13+
"github.com/fabiodcorreia/catch-my-file/internal/transfer"
14+
)
15+
16+
type peersList struct {
17+
widget.List
18+
items []store.Peer
19+
SendTransfer chan *store.Transfer
20+
}
21+
22+
func newPeersList() *peersList {
23+
p := &peersList{
24+
items: make([]store.Peer, 0, 1),
25+
SendTransfer: make(chan *store.Transfer, 1),
26+
}
27+
28+
p.List.Length = p.Length
29+
p.List.CreateItem = p.CreateItem
30+
p.List.UpdateItem = p.UpdateItem
31+
p.ExtendBaseWidget(p)
32+
33+
return p
34+
}
35+
36+
func (pl *peersList) Length() int {
37+
return len(pl.items)
38+
}
39+
40+
func (pl *peersList) CreateItem() fyne.CanvasObject {
41+
return container.NewAdaptiveGrid(
42+
4,
43+
widget.NewLabel(""), //Name
44+
widget.NewLabel(""), //Ip Address
45+
widget.NewLabel(""), //Port
46+
widget.NewButton("", func() {}),
47+
)
48+
}
49+
50+
func (pl *peersList) UpdateItem(i int, item fyne.CanvasObject) {
51+
item.(*fyne.Container).Objects[0].(*widget.Label).SetText(pl.items[i].Name)
52+
item.(*fyne.Container).Objects[1].(*widget.Label).SetText(pl.items[i].Address.String())
53+
item.(*fyne.Container).Objects[2].(*widget.Label).SetText(fmt.Sprintf("%d", pl.items[i].Port))
54+
item.(*fyne.Container).Objects[3] = widget.NewButton("Send File", func() {
55+
dialog.ShowFileOpen(func(uc fyne.URIReadCloser, err error) {
56+
if err != nil || uc == nil {
57+
return
58+
}
59+
60+
ft, err := transfer.NewFileTransfer(uc.URI().Path())
61+
if err != nil {
62+
return
63+
}
64+
65+
rect := canvas.NewRectangle(color.Transparent)
66+
rect.SetMinSize(fyne.NewSize(200, 0))
67+
68+
d := dialog.NewCustom(
69+
"Send File Request",
70+
fmt.Sprintf("Preparing %s to send to %s", ft.FileName, pl.items[i].Name),
71+
container.NewMax(rect, widget.NewProgressBarInfinite()),
72+
fyne.CurrentApp().Driver().AllWindows()[0],
73+
)
74+
75+
tc := transfer.NewClient(pl.items[i].Address, pl.items[i].Port, ft)
76+
77+
tt := store.NewTransfer("", ft.FileName, float64(ft.FileSize), pl.items[i].Name, nil)
78+
tt.IsToSend = true
79+
80+
d.Show()
81+
err = tc.SendRequest()
82+
d.Hide()
83+
84+
if err != nil {
85+
return
86+
}
87+
88+
go tc.WaitSendOrStop(tt)
89+
pl.SendTransfer <- tt
90+
}, fyne.CurrentApp().Driver().AllWindows()[0])
91+
})
92+
item.Refresh()
93+
}
94+
func (pl *peersList) RemoveItem(i int) {
95+
copy(pl.items[i:], pl.items[i+1:])
96+
//pl.items[pl.Length()-1] = nil
97+
pl.items = pl.items[:pl.Length()-1]
98+
pl.Refresh()
99+
}
100+
101+
func (pl *peersList) NewPeer(p store.Peer) {
102+
pl.items = append(pl.items, p)
103+
pl.Refresh()
104+
}

0 commit comments

Comments
 (0)