Skip to content

Commit

Permalink
Better error checking for cancellations
Browse files Browse the repository at this point in the history
Needs psanford/wormhole-william#53 fixed to work propertly in all cases.
  • Loading branch information
Jacalz committed Aug 4, 2021
1 parent 7882b4b commit b46d678
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
12 changes: 8 additions & 4 deletions internal/transport/bridge/recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bridge

import (
"context"
"errors"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
Expand Down Expand Up @@ -86,13 +87,16 @@ func (p *RecvList) NewReceive(code string) {
}()

go func() {
if err := p.client.NewReceive(ctx, code, path); err != nil {
if err := p.client.NewReceive(ctx, code, path); err == nil {
recv.Status = "Completed"
p.client.ShowNotification("Receive completed", "The data was received successfully.")
} else if errors.Is(err, context.Canceled) {
recv.Status = "Cancelled"
p.client.ShowNotification("Receive cancelled", "The receive was cancelled.")
} else {
recv.Status = "Failed"
p.client.ShowNotification("Receive failed", "An error occurred when receiving the data.")
dialog.ShowError(err, fyne.CurrentApp().Driver().AllWindows()[0])
} else {
recv.Status = "Completed"
p.client.ShowNotification("Receive completed", "The data was received successfully.")
}

cancel()
Expand Down
27 changes: 17 additions & 10 deletions internal/transport/bridge/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bridge

import (
"context"
"errors"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
Expand Down Expand Up @@ -108,12 +109,14 @@ func (p *SendList) OnFileSelect(file fyne.URIReadCloser, err error) {
send.Code = code
p.Refresh()

if res := <-result; res.Error != nil {
if res := <-result; res.Error == nil && res.OK {
p.client.ShowNotification("File send completed", "The file was sent successfully.")
} else if errors.Is(res.Error, context.Canceled) {
p.client.ShowNotification("File send cancelled", "The file send was cancelled.")
} else {
fyne.LogError("Error on sending file", res.Error)
dialog.ShowError(res.Error, fyne.CurrentApp().Driver().AllWindows()[0])
p.client.ShowNotification("File send failed", "An error occurred when sending the file.")
} else if res.OK {
p.client.ShowNotification("File send completed", "The file was sent successfully.")
}
}()
}
Expand Down Expand Up @@ -142,12 +145,14 @@ func (p *SendList) OnDirSelect(dir fyne.ListableURI, err error) {
send.Code = code
p.Refresh()

if res := <-result; res.Error != nil {
if res := <-result; res.Error == nil && res.OK {
p.client.ShowNotification("Directory send completed", "The directory was sent successfully.")
} else if errors.Is(res.Error, context.Canceled) {
p.client.ShowNotification("Directory send cancelled", "The directory send was cancelled.")
} else {
fyne.LogError("Error on sending directory", res.Error)
dialog.ShowError(res.Error, fyne.CurrentApp().Driver().AllWindows()[0])
p.client.ShowNotification("Directory send failed", "An error occurred when sending the directory.")
} else if res.OK {
p.client.ShowNotification("Directory send completed", "The directory was sent successfully.")
}
}()
}
Expand All @@ -169,12 +174,14 @@ func (p *SendList) SendText() {
send.Code = code
p.Refresh()

if res := <-result; res.Error != nil {
fyne.LogError("Error on sending text", res.Error)
if res := <-result; res.Error == nil && res.OK {
p.client.ShowNotification("Text send completed", "The text was sent successfully.")
} else if errors.Is(res.Error, context.Canceled) {
p.client.ShowNotification("Text send cancelled", "The text send was cancelled.")
} else {
fyne.LogError("Error on sending file", res.Error)
dialog.ShowError(res.Error, fyne.CurrentApp().Driver().AllWindows()[0])
p.client.ShowNotification("Text send failed", "An error occurred when sending the text.")
} else if res.OK && p.client.Notifications {
p.client.ShowNotification("Text send completed", "The text was sent successfully.")
}
} else {
p.RemoveItem(p.Length() - 1)
Expand Down

0 comments on commit b46d678

Please sign in to comment.