diff --git a/about.go b/about.go index a0b4ac1..fc00dba 100644 --- a/about.go +++ b/about.go @@ -26,7 +26,7 @@ func aboutTabItem() *container.TabItem { aboutInfo.Wrapping = fyne.TextWrapWord return container.NewTabItemWithIcon("About", theme.InfoIcon(), container.NewBorder(nil, widget.NewForm( - widget.NewFormItem("croc GUI", widget.NewHyperlink("v1.0.0", parseURL("https://github.com/howeyc/crocgui"))), + widget.NewFormItem("croc GUI", widget.NewHyperlink("v1.3.0", parseURL("https://github.com/howeyc/crocgui"))), widget.NewFormItem("croc", widget.NewHyperlink("v8.6.7", parseURL("https://github.com/schollz/croc"))), ), nil, diff --git a/main.go b/main.go index 0d3c361..e08e679 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,8 @@ import ( //go:embed metadata/en-US/images/featureGraphic.png var textlogobytes []byte +var DEFAULT_DOWNLOAD_DIR string + func main() { a := app.NewWithID("com.github.howeyc.crocgui") w := a.NewWindow("croc") diff --git a/platforms-all.go b/platforms-all.go index b9fb7af..1f8419a 100644 --- a/platforms-all.go +++ b/platforms-all.go @@ -2,7 +2,14 @@ package main -const DEFAULT_DOWNLOAD_DIR = "." +import "os" + +func init() { + wd, werr := os.Getwd() + if werr == nil { + DEFAULT_DOWNLOAD_DIR = wd + } +} func fixpath(fpath string) string { return fpath diff --git a/platforms_android.go b/platforms_android.go index 9b9a628..9423aa8 100644 --- a/platforms_android.go +++ b/platforms_android.go @@ -5,7 +5,10 @@ import ( "strings" ) -const DEFAULT_DOWNLOAD_DIR = "/storage/emulated/0/Download" +func init() { + // TODO: android probably has a way to find this + DEFAULT_DOWNLOAD_DIR = "/storage/emulated/0/Download" +} func fixpath(fpath string) string { if strings.Contains(fpath, "%3A") { diff --git a/recv.go b/recv.go index 0742872..5640671 100644 --- a/recv.go +++ b/recv.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "io" + "io/fs" "log" "os" "path/filepath" @@ -24,6 +26,8 @@ func recvTabItem(a fyne.App) *container.TabItem { } }() + recvDir, _ := os.MkdirTemp("", "crocgui-recv") + prog := widget.NewProgressBar() prog.Hide() recvEntry := widget.NewEntry() @@ -73,9 +77,9 @@ func recvTabItem(a fyne.App) *container.TabItem { } } }() - cderr := os.Chdir(DEFAULT_DOWNLOAD_DIR) + cderr := os.Chdir(recvDir) if cderr != nil { - log.Println("Unable to change to download dir") + log.Println("Unable to change to dir:", recvDir, cderr) } status.SetText("") rerr := receiver.Receive() @@ -101,6 +105,29 @@ func recvTabItem(a fyne.App) *container.TabItem { plural = "s" } status.Text = fmt.Sprintf("Received file%s %s", plural, strings.Join(filesReceived, ",")) + filepath.Walk(recvDir, func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() { + newpath := filepath.Join(DEFAULT_DOWNLOAD_DIR, filepath.Base(path)) + ofile, oerr := os.Create(newpath) + if oerr != nil { + status.SetText(oerr.Error()) + return oerr + } + ifile, ierr := os.Open(path) + if ierr != nil { + status.SetText(ierr.Error()) + return ierr + } + io.Copy(ofile, ifile) + ifile.Close() + ofile.Close() + os.Remove(path) + } + return nil + }) } }), prog, diff --git a/send.go b/send.go index bc968bc..5e95afd 100644 --- a/send.go +++ b/send.go @@ -37,7 +37,7 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem { }) copyCodeButton.Hide() - sendDir, _ := os.MkdirTemp("", "crocgui") + sendDir, _ := os.MkdirTemp("", "crocgui-send") boxholder := container.NewVBox() fileentries := make(map[string]*fyne.Container) @@ -82,6 +82,11 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem { container.NewHBox(topline, layout.NewSpacer(), addFileButton), boxholder, widget.NewButtonWithIcon("Send", theme.MailSendIcon(), func() { + // Only send if files selected + if len(fileentries) < 1 { + return + } + addFileButton.Hide() randomName := utils.GetRandomName() sender, err := croc.New(croc.Options{