From a430639a9b36a11166d4c5ca907ddafff6f858c3 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Wed, 1 Nov 2023 10:56:29 +0100 Subject: [PATCH] Don't use a goroutine for waiting on receive code --- internal/transport/bridge/recv.go | 17 +++++++---------- internal/transport/receiver.go | 7 +++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/internal/transport/bridge/recv.go b/internal/transport/bridge/recv.go index 3686fd5c..f5189cf3 100644 --- a/internal/transport/bridge/recv.go +++ b/internal/transport/bridge/recv.go @@ -44,6 +44,12 @@ func (r *RecvItem) failed() { r.refresh(r.index) } +func (r *RecvItem) setPath(path string) { + r.URI = storage.NewFileURI(path) + r.Name = r.URI.Name() + r.refresh(r.index) +} + // RecvData is a list of progress bars that track send progress. type RecvData struct { Client *transport.Client @@ -141,17 +147,8 @@ func (d *RecvData) NewReceive(code string) { item := d.NewRecv(code) d.list.Refresh() - path := make(chan string) - - go func() { - item.URI = storage.NewFileURI(<-path) - item.Name = item.URI.Name() - close(path) - d.refresh(item.index) - }() - go func(code string) { - if err := d.Client.NewReceive(code, path, item.update); err != nil { + if err := d.Client.NewReceive(code, item.setPath, item.update); err != nil { d.Client.ShowNotification("Receive failed", "An error occurred when receiving the data.") item.failed() dialog.ShowError(err, d.Window) diff --git a/internal/transport/receiver.go b/internal/transport/receiver.go index dc12fbc2..5c2bfefe 100644 --- a/internal/transport/receiver.go +++ b/internal/transport/receiver.go @@ -27,10 +27,9 @@ func bail(msg *wormhole.IncomingMessage, err error) error { } // NewReceive runs a receive using wormhole-william and handles types accordingly. -func (c *Client) NewReceive(code string, pathname chan string, progress func(int64, int64)) (err error) { +func (c *Client) NewReceive(code string, setPath func(string), progress func(int64, int64)) (err error) { msg, err := c.Receive(context.Background(), code) if err != nil { - pathname <- "" // We want to always send a URI, even on fail, in order to not block goroutines. fyne.LogError("Error on receiving data", err) return bail(msg, err) } @@ -38,7 +37,7 @@ func (c *Client) NewReceive(code string, pathname chan string, progress func(int contents := util.NewProgressReader(msg, progress, msg.TransferBytes64) if msg.Type == wormhole.TransferText { - pathname <- "Text Snippet" + setPath("Text Snippet") text := make([]byte, int(msg.TransferBytes64)) _, err := io.ReadFull(contents, text) @@ -52,7 +51,7 @@ func (c *Client) NewReceive(code string, pathname chan string, progress func(int } path := filepath.Join(c.DownloadPath, msg.Name) - pathname <- path + setPath(path) if !c.OverwriteExisting { if _, err := os.Stat(path); err == nil || os.IsExist(err) {