From 35c1ab0b80f10d59a76d5afb436e3ae598eca396 Mon Sep 17 00:00:00 2001 From: Galih Fajar Date: Wed, 18 Oct 2023 18:27:06 +0700 Subject: [PATCH 1/3] Support custom code on file transfer by dropping onto the window --- internal/transport/bridge/send.go | 13 ++++++++++++- internal/transport/transport.go | 3 +++ internal/ui/tabs.go | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/transport/bridge/send.go b/internal/transport/bridge/send.go index 3975afd0..2af8c190 100644 --- a/internal/transport/bridge/send.go +++ b/internal/transport/bridge/send.go @@ -294,6 +294,12 @@ func (d *SendData) SendText() { // getCustomCode returns "" if the user has custom codes disabled. // Otherwise, it will ask the user for a code. func (d *SendData) getCustomCode() string { + defer func() { + if d.Client.Drop { + d.Client.Drop = false + } + }() + if !d.Client.CustomCode { return "" } @@ -304,8 +310,13 @@ func (d *SendData) getCustomCode() string { Scroll: container.ScrollBoth, Validator: util.CodeValidator, } + cancelMessage := "Cancel" + + if d.Client.Drop { + cancelMessage = "Use default instead" + } - form := dialog.NewForm("Create custom code", "Confirm", "Cancel", []*widget.FormItem{ + form := dialog.NewForm("Create custom code", "Confirm", cancelMessage, []*widget.FormItem{ { Text: "Code", Widget: codeEntry, HintText: "A code beginning with a number, followed by groups of letters separated with \"-\".", diff --git a/internal/transport/transport.go b/internal/transport/transport.go index 0b533d05..86d72615 100644 --- a/internal/transport/transport.go +++ b/internal/transport/transport.go @@ -27,6 +27,9 @@ type Client struct { // Defines if we should pass a custom code or let wormhole-william generate on for us. CustomCode bool + + // Indicates a file is about to send by dropping file onto the window. + Drop bool } // ShowNotification sends a notification if c.Notifications is true. diff --git a/internal/ui/tabs.go b/internal/ui/tabs.go index d07cbe9d..ff3805e5 100644 --- a/internal/ui/tabs.go +++ b/internal/ui/tabs.go @@ -31,6 +31,8 @@ func Create(app fyne.App, window fyne.Window) *container.AppTabs { tabs.SelectIndex(0) } + send.client.CustomCode = true + send.client.Drop = true send.newTransfer(uris) }) From 9718d315f6b2e9d47a5902d0b33dfec3c6cc00c2 Mon Sep 17 00:00:00 2001 From: Galih Fajar Date: Fri, 20 Oct 2023 15:31:41 +0700 Subject: [PATCH 2/3] Show prompt to use custom code on drop --- internal/transport/bridge/send.go | 13 +------------ internal/transport/transport.go | 3 --- internal/ui/send.go | 11 ++++++----- internal/ui/tabs.go | 9 ++++++--- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/internal/transport/bridge/send.go b/internal/transport/bridge/send.go index 2af8c190..3975afd0 100644 --- a/internal/transport/bridge/send.go +++ b/internal/transport/bridge/send.go @@ -294,12 +294,6 @@ func (d *SendData) SendText() { // getCustomCode returns "" if the user has custom codes disabled. // Otherwise, it will ask the user for a code. func (d *SendData) getCustomCode() string { - defer func() { - if d.Client.Drop { - d.Client.Drop = false - } - }() - if !d.Client.CustomCode { return "" } @@ -310,13 +304,8 @@ func (d *SendData) getCustomCode() string { Scroll: container.ScrollBoth, Validator: util.CodeValidator, } - cancelMessage := "Cancel" - - if d.Client.Drop { - cancelMessage = "Use default instead" - } - form := dialog.NewForm("Create custom code", "Confirm", cancelMessage, []*widget.FormItem{ + form := dialog.NewForm("Create custom code", "Confirm", "Cancel", []*widget.FormItem{ { Text: "Code", Widget: codeEntry, HintText: "A code beginning with a number, followed by groups of letters separated with \"-\".", diff --git a/internal/transport/transport.go b/internal/transport/transport.go index 86d72615..0b533d05 100644 --- a/internal/transport/transport.go +++ b/internal/transport/transport.go @@ -27,9 +27,6 @@ type Client struct { // Defines if we should pass a custom code or let wormhole-william generate on for us. CustomCode bool - - // Indicates a file is about to send by dropping file onto the window. - Drop bool } // ShowNotification sends a notification if c.Notifications is true. diff --git a/internal/ui/send.go b/internal/ui/send.go index 2f213361..425a3924 100644 --- a/internal/ui/send.go +++ b/internal/ui/send.go @@ -39,13 +39,14 @@ func (s *send) buildUI(window fyne.Window) *fyne.Container { fileChoice := &widget.Button{Text: "File", Icon: theme.FileIcon(), OnTapped: s.onFileSend} directoryChoice := &widget.Button{Text: "Directory", Icon: theme.FolderOpenIcon(), OnTapped: s.onDirSend} textChoice := &widget.Button{Text: "Text", Icon: theme.DocumentCreateIcon(), OnTapped: s.onTextSend} - codeChoice := &widget.Check{Text: "Use a custom code", OnChanged: s.onCustomCode} - - choiceContent := container.NewGridWithColumns(1, fileChoice, directoryChoice, textChoice, codeChoice) - s.contentPicker = dialog.NewCustom("Pick a content type", "Cancel", choiceContent, window) s.data = &bridge.SendData{Client: s.client, Window: window, Canvas: s.window.Canvas()} - contentToSend := &widget.Button{Text: "Add content to send", Icon: theme.ContentAddIcon(), OnTapped: s.contentPicker.Show} + contentToSend := &widget.Button{Text: "Add content to send", Icon: theme.ContentAddIcon(), OnTapped: func() { + codeChoice := &widget.Check{Text: "Use a custom code", OnChanged: s.onCustomCode, Checked: s.client.CustomCode} + choiceContent := container.NewGridWithColumns(1, fileChoice, directoryChoice, textChoice, codeChoice) + s.contentPicker = dialog.NewCustom("Pick a content type", "Cancel", choiceContent, window) + s.contentPicker.Show() + }} s.fileDialog = dialog.NewFileOpen(s.data.OnFileSelect, window) s.directoryDialog = dialog.NewFolderOpen(s.data.OnDirSelect, window) diff --git a/internal/ui/tabs.go b/internal/ui/tabs.go index ff3805e5..d69b66b5 100644 --- a/internal/ui/tabs.go +++ b/internal/ui/tabs.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/storage" "github.com/Jacalz/rymdport/v3/internal/transport" @@ -31,9 +32,11 @@ func Create(app fyne.App, window fyne.Window) *container.AppTabs { tabs.SelectIndex(0) } - send.client.CustomCode = true - send.client.Drop = true - send.newTransfer(uris) + confirm := dialog.NewConfirm("Create using custom code", "Create using custom code?", func(custom bool) { + send.client.CustomCode = custom + send.newTransfer(uris) + }, window) + confirm.Show() }) if args := os.Args[1:]; len(args) > 0 { From 5272f6eb810cc364b429ea00264dae0ebba976ff Mon Sep 17 00:00:00 2001 From: Galih Fajar Date: Fri, 20 Oct 2023 19:31:41 +0700 Subject: [PATCH 3/3] Simplfies logic on showing custom code on drop --- internal/ui/send.go | 7 ++++--- internal/ui/tabs.go | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/ui/send.go b/internal/ui/send.go index 425a3924..7e1b3a1b 100644 --- a/internal/ui/send.go +++ b/internal/ui/send.go @@ -39,12 +39,13 @@ func (s *send) buildUI(window fyne.Window) *fyne.Container { fileChoice := &widget.Button{Text: "File", Icon: theme.FileIcon(), OnTapped: s.onFileSend} directoryChoice := &widget.Button{Text: "Directory", Icon: theme.FolderOpenIcon(), OnTapped: s.onDirSend} textChoice := &widget.Button{Text: "Text", Icon: theme.DocumentCreateIcon(), OnTapped: s.onTextSend} + codeChoice := &widget.Check{Text: "Use a custom code", OnChanged: s.onCustomCode, Checked: s.client.CustomCode} + choiceContent := container.NewGridWithColumns(1, fileChoice, directoryChoice, textChoice, codeChoice) + s.contentPicker = dialog.NewCustom("Pick a content type", "Cancel", choiceContent, window) s.data = &bridge.SendData{Client: s.client, Window: window, Canvas: s.window.Canvas()} contentToSend := &widget.Button{Text: "Add content to send", Icon: theme.ContentAddIcon(), OnTapped: func() { - codeChoice := &widget.Check{Text: "Use a custom code", OnChanged: s.onCustomCode, Checked: s.client.CustomCode} - choiceContent := container.NewGridWithColumns(1, fileChoice, directoryChoice, textChoice, codeChoice) - s.contentPicker = dialog.NewCustom("Pick a content type", "Cancel", choiceContent, window) + codeChoice.SetChecked(s.client.CustomCode) s.contentPicker.Show() }} diff --git a/internal/ui/tabs.go b/internal/ui/tabs.go index d69b66b5..525a26eb 100644 --- a/internal/ui/tabs.go +++ b/internal/ui/tabs.go @@ -32,11 +32,10 @@ func Create(app fyne.App, window fyne.Window) *container.AppTabs { tabs.SelectIndex(0) } - confirm := dialog.NewConfirm("Create using custom code", "Create using custom code?", func(custom bool) { + dialog.ShowConfirm("Custom Code", "Use a custom code?", func(custom bool) { send.client.CustomCode = custom send.newTransfer(uris) }, window) - confirm.Show() }) if args := os.Args[1:]; len(args) > 0 {