diff --git a/1f40a.png b/1f40a.png deleted file mode 100644 index 793b556..0000000 Binary files a/1f40a.png and /dev/null differ diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..1722a13 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ec6d546 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2021 Chris Howey + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..437136b --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: clean all + +all: crocgui.apk crocgui + +crocgui.apk: main.go platforms_android.go AndroidManifest.xml + fyne package -os android -appID com.github.howeyc.crocgui -icon logo.png + +crocgui: main.go platforms-all.go + go build + +clean: + go clean + rm crocgui.apk diff --git a/README.md b/README.md new file mode 100644 index 0000000..4773a1b --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Croc GUI + +A nice simple GUI for [croc](https://github.com/schollz/croc), designed for +mobile use. diff --git a/go.mod b/go.mod index 90f8571..34292a8 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,3 @@ require ( github.com/schollz/croc/v8 v8.6.7 ) -replace github.com/fyne-io/mobile v0.1.2 => ../mobile diff --git a/go.sum b/go.sum index 56b2947..ae6ebdf 100644 --- a/go.sum +++ b/go.sum @@ -95,6 +95,7 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw= golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6 h1:Tus/Y4w3V77xDsGwKUC8a/QrV7jScpU557J77lFffNs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f h1:aEcjdTsycgPqO/caTgnxfR9xwWOltP/21vtJyFztEy0= golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..ca352b4 Binary files /dev/null and b/logo.png differ diff --git a/main.go b/main.go index 0eafa21..1038db4 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,11 @@ import ( func sendTabItem(w fyne.Window) *container.TabItem { status := widget.NewLabel("") + defer func() { + if r := recover(); r != nil { + status.SetText(fmt.Sprint(r)) + } + }() prog := widget.NewProgressBar() prog.Hide() topline := widget.NewLabel("Pick a file to send") @@ -35,7 +40,7 @@ func sendTabItem(w fyne.Window) *container.TabItem { IsSender: true, SharedSecret: randomName, Debug: false, - RelayAddress: "10.0.1.1:9009", + RelayAddress: "croc.schollz.com:9009", RelayPorts: []string{"9009", "9010", "9011", "9012", "9013"}, RelayPassword: "pass123", Stdout: false, @@ -47,8 +52,14 @@ func sendTabItem(w fyne.Window) *container.TabItem { log.Println(err) } else if f != nil { status.SetText("Receive Code: " + randomName) - fi, _ := os.Stat(f.URI().Path()) - filename = filepath.Base(fi.Name()) + fpath := fixpath(f.URI().Path()) + + fi, sterr := os.Stat(fpath) + if sterr != nil { + status.SetText(fmt.Sprintf("Stat error: %s - %s", fpath, sterr.Error())) + return + } + filename = filepath.Base(fpath) topline.SetText(fmt.Sprintf("Sending file: %s", filename)) totalsize := fi.Size() prog.Max = float64(totalsize) @@ -66,18 +77,20 @@ func sendTabItem(w fyne.Window) *container.TabItem { } } }() - serr := sender.Send(croc.TransferOptions{ - PathToFiles: []string{f.URI().Path()}, - }) - donechan <- true - prog.Hide() - prog.SetValue(0) - topline.SetText("Pick a file to send") - if serr != nil { - log.Println("Send failed:", serr) - } else { - status.SetText(fmt.Sprintf("Sent file %s", filename)) - } + go func() { + serr := sender.Send(croc.TransferOptions{ + PathToFiles: []string{fpath}, + }) + donechan <- true + prog.Hide() + prog.SetValue(0) + topline.SetText("Pick a file to send") + if serr != nil { + log.Println("Send failed:", serr) + } else { + status.SetText(fmt.Sprintf("Sent file %s", filename)) + } + }() } }, w) }), @@ -88,6 +101,12 @@ func sendTabItem(w fyne.Window) *container.TabItem { func recvTabItem() *container.TabItem { status := widget.NewLabel("") + defer func() { + if r := recover(); r != nil { + status.SetText(fmt.Sprint(r)) + } + }() + prog := widget.NewProgressBar() prog.Hide() recvEntry := widget.NewEntry() @@ -101,7 +120,7 @@ func recvTabItem() *container.TabItem { IsSender: false, SharedSecret: recvEntry.Text, Debug: false, - RelayAddress: "10.0.1.1:9009", + RelayAddress: "croc.schollz.com:9009", RelayPassword: "pass123", Stdout: false, NoPrompt: true, @@ -133,6 +152,10 @@ func recvTabItem() *container.TabItem { } } }() + cderr := os.Chdir(DEFAULT_DOWNLOAD_DIR) + if cderr != nil { + log.Println("Unable to change to download dir") + } rerr := receiver.Receive() donechan <- true prog.Hide() @@ -155,5 +178,6 @@ func main() { w := a.NewWindow("croc") w.SetContent(container.NewAppTabs(sendTabItem(w), recvTabItem())) + w.Resize(fyne.NewSize(800, 600)) w.ShowAndRun() } diff --git a/platforms-all.go b/platforms-all.go new file mode 100644 index 0000000..b9fb7af --- /dev/null +++ b/platforms-all.go @@ -0,0 +1,9 @@ +// +build !android + +package main + +const DEFAULT_DOWNLOAD_DIR = "." + +func fixpath(fpath string) string { + return fpath +} diff --git a/platforms_android.go b/platforms_android.go new file mode 100644 index 0000000..9b9a628 --- /dev/null +++ b/platforms_android.go @@ -0,0 +1,18 @@ +package main + +import ( + "net/url" + "strings" +) + +const DEFAULT_DOWNLOAD_DIR = "/storage/emulated/0/Download" + +func fixpath(fpath string) string { + if strings.Contains(fpath, "%3A") { + fpath, _ = url.PathUnescape(fpath) + colIdx := strings.Index(fpath, ":") + fpath = "/storage/emulated/0/" + fpath[colIdx+1:] + } + + return fpath +}