Skip to content

Commit

Permalink
Update the progress bar dialogs to not use deprecated apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Oct 27, 2023
1 parent 90ef96c commit bf53c9f
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,50 @@ package fyneselfupdate

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)

// NewProgressCallback returns a callback that can be used to present download information during update.
func NewProgressCallback(win fyne.Window) func(float64, error) {
var d dialog.Dialog
var progress fyne.Widget
return func(done float64, fail error) {
if d == nil {
if done < 0 {
//lint:ignore SA1019 upstream will provide a better solution
d = dialog.NewProgressInfinite("Application update", "Downloading update", win)
infinite := widget.NewProgressBarInfinite()
infinite.Start()
progress = infinite
} else {
//lint:ignore SA1019 upstream will provide a better solution
d = dialog.NewProgress("Application update", "Downloading update", win)
progress = widget.NewProgressBar()
}
content := container.NewVBox(widget.NewLabel("Downloading update"), progress)
d = dialog.NewCustomWithoutButtons("Application update", content, win)
d.Show()
}

if fail != nil {
cleanup := func() {
if infinite, ok := progress.(*widget.ProgressBarInfinite); ok {
infinite.Stop()
}

d.Hide()
d = nil
}

if fail != nil {
dialog.ShowError(fail, win)
cleanup()
return
}
if done == 1.0 {
d.Hide()
d = nil
cleanup()
return
}

//lint:ignore SA1019 here until upstream replaces
if progress, ok := d.(*dialog.ProgressDialog); ok {
progress.SetValue(done)
if limited, ok := progress.(*widget.ProgressBar); ok {
limited.SetValue(done)
}
}
}

0 comments on commit bf53c9f

Please sign in to comment.