1
0
mirror of https://github.com/taigrr/crocgui synced 2025-01-18 04:03:16 -08:00

Add cancel button, and send code entry

This commit is contained in:
Chris Howey 2021-04-09 19:26:20 -05:00
parent 1ba689f8b8
commit 840fff178c
3 changed files with 141 additions and 98 deletions

View File

@ -3,8 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.howeyc.crocgui"
android:versionCode="10"
android:versionName="1.6.0">
android:versionCode="11"
android:versionName="1.7.0">
<application android:label="Croc">
<activity android:name="org.golang.app.GoNativeActivity"

View File

@ -0,0 +1,2 @@
- Add cancel send button
- User can change/set send code

99
send.go
View File

@ -33,11 +33,11 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
prog := widget.NewProgressBar()
prog.Hide()
topline := widget.NewLabel("Pick a file to send")
var currentCode string
randomCode := utils.GetRandomName()
sendEntry := widget.NewEntry()
sendEntry.SetText(randomCode)
copyCodeButton := widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
if currentCode != "" {
w.Clipboard().SetContent(currentCode)
}
w.Clipboard().SetContent(sendEntry.Text)
})
copyCodeButton.Hide()
@ -70,12 +70,15 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
}
labelFile := widget.NewLabel(filepath.Base(fpath))
newentry := container.NewHBox(labelFile, layout.NewSpacer(), widget.NewButtonWithIcon("", theme.CancelIcon(), func() {
// Can only add/remove if not currently attempting a send
if !sendEntry.Disabled() {
if fe, ok := fileentries[fpath]; ok {
boxholder.Remove(fe)
os.Remove(fpath)
log.Tracef("Removed file from internal cache: %s", fpath)
delete(fileentries, fpath)
}
}
}))
fileentries[fpath] = newentry
boxholder.Add(newentry)
@ -95,21 +98,46 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
}))
debugObjects = append(debugObjects, debugBox)
return container.NewTabItemWithIcon("Send", theme.MailSendIcon(),
container.NewVBox(
container.NewHBox(topline, layout.NewSpacer(), addFileButton),
boxholder,
widget.NewButtonWithIcon("Send", theme.MailSendIcon(), func() {
cancelchan := make(chan bool)
activeButtonHolder := container.NewVBox()
var cancelButton, sendButton *widget.Button
resetSender := func() {
prog.Hide()
prog.SetValue(0)
for _, obj := range activeButtonHolder.Objects {
activeButtonHolder.Remove(obj)
}
activeButtonHolder.Add(sendButton)
for fpath, fe := range fileentries {
boxholder.Remove(fe)
os.Remove(fpath)
log.Tracef("Removed file from internal cache: %s", fpath)
delete(fileentries, fpath)
}
topline.SetText("Pick a file to send")
addFileButton.Show()
if sendEntry.Text == randomCode {
randomCode = utils.GetRandomName()
sendEntry.SetText(randomCode)
}
copyCodeButton.Hide()
sendEntry.Enable()
}
sendButton = widget.NewButtonWithIcon("Send", theme.MailSendIcon(), func() {
// Only send if files selected
if len(fileentries) < 1 {
log.Error("no files selected")
return
}
addFileButton.Hide()
randomName := utils.GetRandomName()
sender, err := croc.New(croc.Options{
IsSender: true,
SharedSecret: randomName,
SharedSecret: sendEntry.Text,
Debug: crocDebugMode(),
RelayAddress: a.Preferences().String("relay-address"),
RelayPorts: strings.Split(a.Preferences().String("relay-ports"), ","),
@ -129,10 +157,15 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
log.Trace("croc sender created")
var filename string
status.SetText("Receive Code: " + randomName)
currentCode = randomName
status.SetText("Receive Code: " + sendEntry.Text)
copyCodeButton.Show()
prog.Show()
for _, obj := range activeButtonHolder.Objects {
activeButtonHolder.Remove(obj)
}
activeButtonHolder.Add(cancelButton)
donechan := make(chan bool)
sendnames := make(map[string]int)
go func() {
@ -160,32 +193,40 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
for fpath := range fileentries {
filepaths = append(filepaths, fpath)
}
sendEntry.Disable()
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)
os.Remove(fpath)
log.Tracef("Removed file from internal cache: %s", fpath)
delete(fileentries, fpath)
}
}
topline.SetText("Pick a file to send")
addFileButton.Show()
if serr != nil {
log.Errorf("Send failed: %s\n", serr)
} else {
status.SetText(fmt.Sprintf("Sent file %s", filename))
}
currentCode = ""
copyCodeButton.Hide()
resetSender()
}()
}),
go func() {
select {
case <-cancelchan:
donechan <- true
status.SetText("Send cancelled.")
}
resetSender()
}()
})
cancelButton = widget.NewButtonWithIcon("Cancel", theme.CancelIcon(), func() {
cancelchan <- true
})
activeButtonHolder.Add(sendButton)
return container.NewTabItemWithIcon("Send", theme.MailSendIcon(),
container.NewVBox(
container.NewHBox(topline, layout.NewSpacer(), addFileButton),
widget.NewForm(&widget.FormItem{Text: "Send Code", Widget: sendEntry}),
boxholder,
activeButtonHolder,
prog,
container.NewHBox(status, copyCodeButton),
debugBox,