-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show proper progress on receiver side, fixes #20
This adds the necessary changes to be able to support full progress on the receiving side as well as sending side. It also cleans up the progress codes a lot and unifies the error handling. Fixes #20
- Loading branch information
Showing
5 changed files
with
82 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package util | ||
|
||
import ( | ||
"sync" | ||
|
||
"fyne.io/fyne/v2/widget" | ||
"github.com/psanford/wormhole-william/wormhole" | ||
) | ||
|
||
// ProgressBar is contains a widget for displaying wormhole send progress. | ||
type ProgressBar struct { | ||
widget.ProgressBar | ||
} | ||
|
||
// WithProgress returns a send option to update the progress. | ||
func (p *ProgressBar) WithProgress() wormhole.SendOption { | ||
once := sync.Once{} | ||
return wormhole.WithProgress(func(sent, total int64) { | ||
once.Do(func() { p.Max = float64(total) }) | ||
p.SetValue(float64(sent)) | ||
}) | ||
} | ||
|
||
// Write updates the progress of a write operation. | ||
func (p *ProgressBar) Write(written []byte) (int, error) { | ||
p.SetValue(p.Value + float64(len(written))) | ||
return 0, nil | ||
} | ||
|
||
// Done sets the value to max to indicate that it is finished. | ||
func (p *ProgressBar) Done() { | ||
p.SetValue(p.Max) | ||
} | ||
|
||
// Failed sets the text to indicate a failure. | ||
func (p *ProgressBar) Failed() { | ||
p.TextFormatter = func() string { return "Failed" } | ||
p.Refresh() | ||
} | ||
|
||
// NewProgressBar creates a new fyne progress bar and update function for wormhole send. | ||
func NewProgressBar() *ProgressBar { | ||
p := &ProgressBar{} | ||
p.ExtendBaseWidget(p) | ||
return p | ||
} |