-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
36450f8
commit 1e036e2
Showing
17 changed files
with
1,357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#VERSION = $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || echo v0) | ||
VERSION = $(shell git describe --tags --match=v* 2> /dev/null || echo 0.0.0) | ||
|
||
APPID = com.github.fabiodcorreia.catch-my-file | ||
ICON = assets/icons/icon-512.png | ||
NAME = CatchMyFile | ||
|
||
format: | ||
gofmt -s -w main.go | ||
gofmt -s -w internal/**/*.go | ||
gofmt -s -w cmd/**/*.go | ||
|
||
review: format | ||
@echo "============= Spell Check ============= " | ||
@misspell . | ||
|
||
@echo "============= Ineffectual Assignments Check ============= " | ||
@ineffassign ./... | ||
|
||
@echo "============= Cyclomatic Complexity Check ============= " | ||
@gocyclo -total -over 5 -avg . | ||
|
||
@echo "============= Duplication Check ============= " | ||
@dupl -t 25 | ||
|
||
@echo "============= Repeated Strings Check ============= " | ||
@goconst ./... | ||
|
||
@echo "============= Vet Check ============= " | ||
@go vet ./... | ||
|
||
build: | ||
go mod tidy | ||
go build -tags release -ldflags="-s -w" -o $(NAME) | ||
|
||
darwin: | ||
fyne-cross darwin -arch amd64,arm64 -app-id $(APPID) -icon $(ICON) -app-version $(VERSION) -output $(NAME) | ||
|
||
linux: | ||
fyne-cross linux -arch amd64,arm64 -app-id $(APPID) -icon $(ICON) -app-version $(VERSION) | ||
|
||
windows: | ||
fyne-cross windows -arch amd64 -app-id $(APPID) -icon $(ICON) -app-version $(VERSION) | ||
|
||
bundle: | ||
rm -fr dist | ||
mkdir dist | ||
|
||
mv fyne-cross/dist/linux-amd64/$(NAME).tar.gz $(NAME)-$(VERSION)-linux-amd64.tar.gz | ||
mv fyne-cross/dist/linux-arm64/$(NAME).tar.gz $(NAME)-$(VERSION)-linux-arm64.tar.gz | ||
|
||
(cd fyne-cross/dist/darwin-amd64/ && zip -r $(NAME)-darwin-amd64.zip $(NAME).app/) | ||
mv fyne-cross/dist/darwin-amd64/$(NAME)-darwin-amd64.zip dist/$(NAME)-$(VERSION)-darwin-amd64.zip | ||
|
||
(cd fyne-cross/dist/darwin-arm64/ && zip -r $(NAME)-darwin-arm64.zip $(NAME).app/) | ||
mv fyne-cross/dist/darwin-arm64/$(NAME)-darwin-arm64.zip dist/$(NAME)-$(VERSION)-darwin-arm64.zip | ||
|
||
mv fyne-cross/dist/windows-amd64/$(NAME).exe.zip $(NAME)-$(VERSION)-windows-amd64.zip | ||
|
||
release: darwin freebsd linux windows bundle | ||
|
||
tools: | ||
go get -u github.com/jgautheron/goconst/cmd/goconst | ||
go get -u github.com/mdempsky/unconvert | ||
go get -u github.com/securego/gosec/v2/cmd/gosec | ||
go get -u github.com/alexkohler/prealloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package frontend | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/app" | ||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/theme" | ||
"github.com/fabiodcorreia/catch-my-file/cmd/internal/backend" | ||
) | ||
|
||
const ( | ||
prefPort = "port" | ||
prefHostname = "hostname" | ||
) | ||
|
||
type Frontend struct { | ||
a fyne.App | ||
w fyne.Window | ||
} | ||
|
||
func New() *Frontend { | ||
f := &Frontend{ | ||
a: app.NewWithID("github.fabiodcorreia.catch-my-file"), | ||
} | ||
f.w = f.a.NewWindow("Catch My File") | ||
f.w.Resize(fyne.NewSize(880, 600)) | ||
return f | ||
} | ||
|
||
func (f *Frontend) Run() error { | ||
pl := newPeersList() | ||
rl := newTransferList() | ||
sl := newTransferList() | ||
lt := newLogTable() | ||
f.w.SetContent(container.NewAppTabs( | ||
container.NewTabItemWithIcon("Receiving", theme.DownloadIcon(), rl), | ||
container.NewTabItemWithIcon("Sending", theme.UploadIcon(), sl), | ||
container.NewTabItemWithIcon("Peers", theme.ComputerIcon(), pl), | ||
container.NewTabItemWithIcon("Log", theme.ErrorIcon(), lt), | ||
)) | ||
|
||
hn, err := os.Hostname() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.a.Preferences().SetString(prefHostname, strings.ReplaceAll(hn, ".", "-")) //! ? | ||
f.a.Preferences().SetInt(prefPort, 8820) | ||
|
||
e := backend.NewEngine(f.a.Preferences().String(prefHostname), f.a.Preferences().Int(prefPort)) | ||
|
||
go func() { | ||
for { | ||
select { | ||
case p := <-e.DiscoverPeers(): | ||
pl.NewPeer(p) | ||
case t := <-e.ReceiveTransferNotification(): | ||
rl.NewTransfer(t) | ||
case t := <-pl.SendTransfer: | ||
sl.NewTransfer(t) | ||
case rds := <-e.DiscoverServerError(): | ||
lt.NewLogRecord(time.Now(), rds) | ||
case rdc := <-e.DiscoverClientError(): | ||
lt.NewLogRecord(time.Now(), rdc) | ||
case rts := <-e.TransferServerError(): | ||
lt.NewLogRecord(time.Now(), rts) | ||
} | ||
} | ||
}() | ||
|
||
f.w.CenterOnScreen() | ||
f.w.SetMaster() | ||
f.w.SetOnClosed(func() { | ||
e.Shutdown() | ||
}) | ||
|
||
err = e.Start() | ||
if err != nil { | ||
f.a.SendNotification(fyne.NewNotification("Catch My File - Fail to Start", err.Error())) | ||
return err | ||
} | ||
|
||
f.w.ShowAndRun() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package frontend | ||
|
||
import ( | ||
"time" | ||
|
||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/widget" | ||
) | ||
|
||
type logTable struct { | ||
widget.Table | ||
items []error | ||
} | ||
|
||
func newLogTable() *logTable { | ||
lt := &logTable{ | ||
items: make([]error, 0, 20), | ||
} | ||
lt.Table.Length = lt.Length | ||
lt.Table.CreateCell = lt.CreateCell | ||
lt.Table.UpdateCell = lt.UpdateCell | ||
lt.Table.SetColumnWidth(0, 160) | ||
lt.ExtendBaseWidget(lt) | ||
|
||
return lt | ||
} | ||
|
||
func (lt *logTable) Length() (int, int) { | ||
return len(lt.items), 2 | ||
} | ||
|
||
func (lt *logTable) CreateCell() fyne.CanvasObject { | ||
return widget.NewLabel("Name") | ||
} | ||
|
||
func (lt *logTable) UpdateCell(id widget.TableCellID, item fyne.CanvasObject) { | ||
switch id.Col { | ||
case 0: | ||
item.(*widget.Label).SetText(time.Now().Format("2006-01-02 15:04:05")) | ||
case 1: | ||
item.(*widget.Label).SetText(lt.items[id.Row].Error()) | ||
} | ||
} | ||
|
||
func (lt *logTable) NewLogRecord(t time.Time, err error) { | ||
if err != nil { | ||
lt.items = append(lt.items, err) | ||
lt.Refresh() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package frontend | ||
|
||
import ( | ||
"fmt" | ||
"image/color" | ||
|
||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/canvas" | ||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/dialog" | ||
"fyne.io/fyne/v2/widget" | ||
"github.com/fabiodcorreia/catch-my-file/internal/store" | ||
"github.com/fabiodcorreia/catch-my-file/internal/transfer" | ||
) | ||
|
||
type peersList struct { | ||
widget.List | ||
items []store.Peer | ||
SendTransfer chan *store.Transfer | ||
} | ||
|
||
func newPeersList() *peersList { | ||
p := &peersList{ | ||
items: make([]store.Peer, 0, 1), | ||
SendTransfer: make(chan *store.Transfer, 1), | ||
} | ||
|
||
p.List.Length = p.Length | ||
p.List.CreateItem = p.CreateItem | ||
p.List.UpdateItem = p.UpdateItem | ||
p.ExtendBaseWidget(p) | ||
|
||
return p | ||
} | ||
|
||
func (pl *peersList) Length() int { | ||
return len(pl.items) | ||
} | ||
|
||
func (pl *peersList) CreateItem() fyne.CanvasObject { | ||
return container.NewAdaptiveGrid( | ||
4, | ||
widget.NewLabel(""), //Name | ||
widget.NewLabel(""), //Ip Address | ||
widget.NewLabel(""), //Port | ||
widget.NewButton("", func() {}), | ||
) | ||
} | ||
|
||
func (pl *peersList) UpdateItem(i int, item fyne.CanvasObject) { | ||
item.(*fyne.Container).Objects[0].(*widget.Label).SetText(pl.items[i].Name) | ||
item.(*fyne.Container).Objects[1].(*widget.Label).SetText(pl.items[i].Address.String()) | ||
item.(*fyne.Container).Objects[2].(*widget.Label).SetText(fmt.Sprintf("%d", pl.items[i].Port)) | ||
item.(*fyne.Container).Objects[3] = widget.NewButton("Send File", func() { | ||
dialog.ShowFileOpen(func(uc fyne.URIReadCloser, err error) { | ||
if err != nil || uc == nil { | ||
return | ||
} | ||
|
||
ft, err := transfer.NewFileTransfer(uc.URI().Path()) | ||
if err != nil { | ||
return | ||
} | ||
|
||
rect := canvas.NewRectangle(color.Transparent) | ||
rect.SetMinSize(fyne.NewSize(200, 0)) | ||
|
||
d := dialog.NewCustom( | ||
"Send File Request", | ||
fmt.Sprintf("Preparing %s to send to %s", ft.FileName, pl.items[i].Name), | ||
container.NewMax(rect, widget.NewProgressBarInfinite()), | ||
fyne.CurrentApp().Driver().AllWindows()[0], | ||
) | ||
|
||
tc := transfer.NewClient(pl.items[i].Address, pl.items[i].Port, ft) | ||
|
||
tt := store.NewTransfer("", ft.FileName, float64(ft.FileSize), pl.items[i].Name, nil) | ||
tt.IsToSend = true | ||
|
||
d.Show() | ||
err = tc.SendRequest() | ||
d.Hide() | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
go tc.WaitSendOrStop(tt) | ||
pl.SendTransfer <- tt | ||
}, fyne.CurrentApp().Driver().AllWindows()[0]) | ||
}) | ||
item.Refresh() | ||
} | ||
func (pl *peersList) RemoveItem(i int) { | ||
copy(pl.items[i:], pl.items[i+1:]) | ||
//pl.items[pl.Length()-1] = nil | ||
pl.items = pl.items[:pl.Length()-1] | ||
pl.Refresh() | ||
} | ||
|
||
func (pl *peersList) NewPeer(p store.Peer) { | ||
pl.items = append(pl.items, p) | ||
pl.Refresh() | ||
} |
Oops, something went wrong.