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