Skip to content

Commit

Permalink
transport: A small receiver refactor to prepare future changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 14, 2024
1 parent ef9096b commit 0299e37
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/transport/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,30 @@ 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, setPath func(string), progress func(int64, int64)) (err error) {
func (c *Client) NewReceive(code string, setPath func(string), progress func(int64, int64)) error {
msg, err := c.Receive(context.Background(), code)
if err != nil {
fyne.LogError("Error on receiving data", err)
return bail(msg, err)
}

contents := util.NewProgressReader(msg, progress, msg.TransferBytes)

if msg.Type == wormhole.TransferText {
setPath("Text Snippet")
c.showTextReceiveWindow(msg.ReadText())
progress(0, 1) // Make sure that text updates progress.
return nil
}

path := filepath.Join(c.DownloadPath, msg.Name)
setPath(path)

return c.SaveToDisk(msg, path, progress)
}

// SaveToDisk saves the incomming file or directory transfer to the disk.
func (c *Client) SaveToDisk(msg *wormhole.IncomingMessage, path string, progress func(int64, int64)) (err error) {
contents := util.NewProgressReader(msg, progress, msg.TransferBytes)

if !c.OverwriteExisting {
if _, err := os.Stat(path); err == nil || os.IsExist(err) {
new, err := addFileIncrement(path)
Expand Down

0 comments on commit 0299e37

Please sign in to comment.