mirror of
https://github.com/taigrr/crocgui
synced 2025-01-18 04:03:16 -08:00
do work in tmp directory
This way android send/receive is more likely to succeed.
This commit is contained in:
parent
76fc6847f7
commit
9d1a04e586
2
about.go
2
about.go
@ -26,7 +26,7 @@ func aboutTabItem() *container.TabItem {
|
|||||||
aboutInfo.Wrapping = fyne.TextWrapWord
|
aboutInfo.Wrapping = fyne.TextWrapWord
|
||||||
return container.NewTabItemWithIcon("About", theme.InfoIcon(), container.NewBorder(nil,
|
return container.NewTabItemWithIcon("About", theme.InfoIcon(), container.NewBorder(nil,
|
||||||
widget.NewForm(
|
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"))),
|
widget.NewFormItem("croc", widget.NewHyperlink("v8.6.7", parseURL("https://github.com/schollz/croc"))),
|
||||||
),
|
),
|
||||||
nil,
|
nil,
|
||||||
|
2
main.go
2
main.go
@ -13,6 +13,8 @@ import (
|
|||||||
//go:embed metadata/en-US/images/featureGraphic.png
|
//go:embed metadata/en-US/images/featureGraphic.png
|
||||||
var textlogobytes []byte
|
var textlogobytes []byte
|
||||||
|
|
||||||
|
var DEFAULT_DOWNLOAD_DIR string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := app.NewWithID("com.github.howeyc.crocgui")
|
a := app.NewWithID("com.github.howeyc.crocgui")
|
||||||
w := a.NewWindow("croc")
|
w := a.NewWindow("croc")
|
||||||
|
@ -2,7 +2,14 @@
|
|||||||
|
|
||||||
package main
|
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 {
|
func fixpath(fpath string) string {
|
||||||
return fpath
|
return fpath
|
||||||
|
@ -5,7 +5,10 @@ import (
|
|||||||
"strings"
|
"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 {
|
func fixpath(fpath string) string {
|
||||||
if strings.Contains(fpath, "%3A") {
|
if strings.Contains(fpath, "%3A") {
|
||||||
|
31
recv.go
31
recv.go
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -24,6 +26,8 @@ func recvTabItem(a fyne.App) *container.TabItem {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
recvDir, _ := os.MkdirTemp("", "crocgui-recv")
|
||||||
|
|
||||||
prog := widget.NewProgressBar()
|
prog := widget.NewProgressBar()
|
||||||
prog.Hide()
|
prog.Hide()
|
||||||
recvEntry := widget.NewEntry()
|
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 {
|
if cderr != nil {
|
||||||
log.Println("Unable to change to download dir")
|
log.Println("Unable to change to dir:", recvDir, cderr)
|
||||||
}
|
}
|
||||||
status.SetText("")
|
status.SetText("")
|
||||||
rerr := receiver.Receive()
|
rerr := receiver.Receive()
|
||||||
@ -101,6 +105,29 @@ func recvTabItem(a fyne.App) *container.TabItem {
|
|||||||
plural = "s"
|
plural = "s"
|
||||||
}
|
}
|
||||||
status.Text = fmt.Sprintf("Received file%s %s", plural, strings.Join(filesReceived, ","))
|
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,
|
prog,
|
||||||
|
7
send.go
7
send.go
@ -37,7 +37,7 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
|
|||||||
})
|
})
|
||||||
copyCodeButton.Hide()
|
copyCodeButton.Hide()
|
||||||
|
|
||||||
sendDir, _ := os.MkdirTemp("", "crocgui")
|
sendDir, _ := os.MkdirTemp("", "crocgui-send")
|
||||||
|
|
||||||
boxholder := container.NewVBox()
|
boxholder := container.NewVBox()
|
||||||
fileentries := make(map[string]*fyne.Container)
|
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),
|
container.NewHBox(topline, layout.NewSpacer(), addFileButton),
|
||||||
boxholder,
|
boxholder,
|
||||||
widget.NewButtonWithIcon("Send", theme.MailSendIcon(), func() {
|
widget.NewButtonWithIcon("Send", theme.MailSendIcon(), func() {
|
||||||
|
// Only send if files selected
|
||||||
|
if len(fileentries) < 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
addFileButton.Hide()
|
addFileButton.Hide()
|
||||||
randomName := utils.GetRandomName()
|
randomName := utils.GetRandomName()
|
||||||
sender, err := croc.New(croc.Options{
|
sender, err := croc.New(croc.Options{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user