mirror of
https://github.com/taigrr/crocgui
synced 2025-01-18 04:03:16 -08:00
add ability to send multiple files
This commit is contained in:
parent
883cc70b61
commit
5e9d2a114b
@ -3,8 +3,8 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.github.howeyc.crocgui"
|
package="com.github.howeyc.crocgui"
|
||||||
android:versionCode="4"
|
android:versionCode="5"
|
||||||
android:versionName="1.1.0">
|
android:versionName="1.2.0">
|
||||||
|
|
||||||
<application android:label="Croc"
|
<application android:label="Croc"
|
||||||
tools:targetApi="30"
|
tools:targetApi="30"
|
||||||
|
1
metadata/en-US/changelogs/5.txt
Normal file
1
metadata/en-US/changelogs/5.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
- Ability to send multiple files
|
172
send.go
172
send.go
@ -11,6 +11,7 @@ import (
|
|||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/schollz/croc/v8/src/croc"
|
"github.com/schollz/croc/v8/src/croc"
|
||||||
@ -34,79 +35,114 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
copyCodeButton.Hide()
|
copyCodeButton.Hide()
|
||||||
|
|
||||||
|
boxholder := container.NewVBox()
|
||||||
|
fileentries := make(map[string]*fyne.Container)
|
||||||
|
|
||||||
|
addFileButton := widget.NewButtonWithIcon("", theme.FileIcon(), func() {
|
||||||
|
dialog.ShowFileOpen(func(f fyne.URIReadCloser, e error) {
|
||||||
|
if e != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if f != nil {
|
||||||
|
fpath := fixpath(f.URI().Path())
|
||||||
|
_, sterr := os.Stat(fpath)
|
||||||
|
if sterr != nil {
|
||||||
|
status.SetText(fmt.Sprintf("Stat error: %s - %s", fpath, sterr.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
labelFile := widget.NewLabel(filepath.Base(fpath))
|
||||||
|
newentry := container.NewHBox(labelFile, layout.NewSpacer(), widget.NewButtonWithIcon("", theme.CancelIcon(), func() {
|
||||||
|
if fe, ok := fileentries[fpath]; ok {
|
||||||
|
boxholder.Remove(fe)
|
||||||
|
delete(fileentries, fpath)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
fileentries[fpath] = newentry
|
||||||
|
boxholder.Add(newentry)
|
||||||
|
}
|
||||||
|
}, w)
|
||||||
|
})
|
||||||
|
|
||||||
return container.NewTabItemWithIcon("Send", theme.MailSendIcon(),
|
return container.NewTabItemWithIcon("Send", theme.MailSendIcon(),
|
||||||
container.NewVBox(
|
container.NewVBox(
|
||||||
topline,
|
container.NewHBox(topline, layout.NewSpacer(), addFileButton),
|
||||||
widget.NewButtonWithIcon("File", theme.FileIcon(), func() {
|
boxholder,
|
||||||
dialog.ShowFileOpen(func(f fyne.URIReadCloser, e error) {
|
widget.NewButtonWithIcon("Send", theme.MailSendIcon(), func() {
|
||||||
if e != nil {
|
addFileButton.Hide()
|
||||||
return
|
randomName := utils.GetRandomName()
|
||||||
}
|
sender, err := croc.New(croc.Options{
|
||||||
randomName := utils.GetRandomName()
|
IsSender: true,
|
||||||
sender, err := croc.New(croc.Options{
|
SharedSecret: randomName,
|
||||||
IsSender: true,
|
Debug: false,
|
||||||
SharedSecret: randomName,
|
RelayAddress: a.Preferences().String("relay-address"),
|
||||||
Debug: false,
|
RelayPorts: strings.Split(a.Preferences().String("relay-ports"), ","),
|
||||||
RelayAddress: a.Preferences().String("relay-address"),
|
RelayPassword: a.Preferences().String("relay-password"),
|
||||||
RelayPorts: strings.Split(a.Preferences().String("relay-ports"), ","),
|
Stdout: false,
|
||||||
RelayPassword: a.Preferences().String("relay-password"),
|
NoPrompt: true,
|
||||||
Stdout: false,
|
DisableLocal: a.Preferences().Bool("disable-local"),
|
||||||
NoPrompt: true,
|
NoMultiplexing: a.Preferences().Bool("disable-multiplexing"),
|
||||||
DisableLocal: a.Preferences().Bool("disable-local"),
|
OnlyLocal: a.Preferences().Bool("force-local"),
|
||||||
NoMultiplexing: a.Preferences().Bool("disable-multiplexing"),
|
NoCompress: a.Preferences().Bool("disable-compression"),
|
||||||
OnlyLocal: a.Preferences().Bool("force-local"),
|
})
|
||||||
NoCompress: a.Preferences().Bool("disable-compression"),
|
if err != nil {
|
||||||
})
|
status.SetText("croc error: " + err.Error())
|
||||||
var filename string
|
return
|
||||||
if err != nil {
|
}
|
||||||
log.Println(err)
|
var filename string
|
||||||
} else if f != nil {
|
status.SetText("Receive Code: " + randomName)
|
||||||
fpath := fixpath(f.URI().Path())
|
currentCode = randomName
|
||||||
|
copyCodeButton.Show()
|
||||||
fi, sterr := os.Stat(fpath)
|
prog.Show()
|
||||||
if sterr != nil {
|
donechan := make(chan bool)
|
||||||
status.SetText(fmt.Sprintf("Stat error: %s - %s", fpath, sterr.Error()))
|
sendnames := make(map[string]int)
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(time.Millisecond * 100)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
if sender.Step2FileInfoTransfered {
|
||||||
|
cnum := sender.FilesToTransferCurrentNum
|
||||||
|
fi := sender.FilesToTransfer[cnum]
|
||||||
|
filename = filepath.Base(fi.Name)
|
||||||
|
sendnames[filename] = cnum
|
||||||
|
topline.SetText(fmt.Sprintf("Sending file: %s (%d/%d)", filename, cnum+1, len(sender.FilesToTransfer)))
|
||||||
|
prog.Max = float64(fi.Size)
|
||||||
|
prog.SetValue(float64(sender.TotalSent))
|
||||||
|
}
|
||||||
|
case <-donechan:
|
||||||
|
ticker.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
status.SetText("Receive Code: " + randomName)
|
|
||||||
currentCode = randomName
|
|
||||||
copyCodeButton.Show()
|
|
||||||
filename = filepath.Base(fpath)
|
|
||||||
topline.SetText(fmt.Sprintf("Sending file: %s", filename))
|
|
||||||
totalsize := fi.Size()
|
|
||||||
prog.Max = float64(totalsize)
|
|
||||||
prog.Show()
|
|
||||||
donechan := make(chan bool)
|
|
||||||
go func() {
|
|
||||||
ticker := time.NewTicker(time.Millisecond * 100)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ticker.C:
|
|
||||||
prog.SetValue(float64(sender.TotalSent))
|
|
||||||
case <-donechan:
|
|
||||||
ticker.Stop()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
currentCode = ""
|
|
||||||
copyCodeButton.Hide()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
}, w)
|
}()
|
||||||
|
go func() {
|
||||||
|
var filepaths []string
|
||||||
|
for fpath := range fileentries {
|
||||||
|
filepaths = append(filepaths, fpath)
|
||||||
|
}
|
||||||
|
serr := sender.Send(croc.TransferOptions{
|
||||||
|
PathToFiles: filepaths,
|
||||||
|
})
|
||||||
|
donechan <- true
|
||||||
|
prog.Hide()
|
||||||
|
prog.SetValue(0)
|
||||||
|
for _, fpath := range filepaths {
|
||||||
|
if fe, ok := fileentries[fpath]; ok {
|
||||||
|
boxholder.Remove(fe)
|
||||||
|
delete(fileentries, fpath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
topline.SetText("Pick a file to send")
|
||||||
|
addFileButton.Show()
|
||||||
|
if serr != nil {
|
||||||
|
log.Println("Send failed:", serr)
|
||||||
|
} else {
|
||||||
|
status.SetText(fmt.Sprintf("Sent file %s", filename))
|
||||||
|
}
|
||||||
|
currentCode = ""
|
||||||
|
copyCodeButton.Hide()
|
||||||
|
}()
|
||||||
}),
|
}),
|
||||||
prog,
|
prog,
|
||||||
container.NewHBox(status, copyCodeButton),
|
container.NewHBox(status, copyCodeButton),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user