mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-28 14:04:48 -04:00
Fix progress bar
This commit is contained in:
parent
cf4ba4c8a9
commit
c0fe90554b
1 changed files with 18 additions and 11 deletions
|
@ -66,36 +66,43 @@ func CreateProgressWindow(parent *gtk.Window) (ProgressWindow, error) {
|
|||
}
|
||||
|
||||
func downloadFile(progressWindow *ProgressWindow, client *grab.Client, url string, outputPath string) error {
|
||||
done := false
|
||||
req, err := grab.NewRequest(outputPath, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp := client.Do(req)
|
||||
if err := resp.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
progressWindow.label.SetText(path.Base(resp.Filename))
|
||||
|
||||
go func() {
|
||||
go func(err *error) {
|
||||
for !resp.IsComplete() {
|
||||
glib.IdleAdd(func() {
|
||||
progress := float64(resp.BytesComplete()) / float64(resp.Size())
|
||||
progressWindow.bar.SetFraction(progress)
|
||||
progressWindow.percentLabel.SetText(fmt.Sprintf("%.0f%%", progress*100))
|
||||
for gtk.EventsPending() {
|
||||
gtk.MainIteration()
|
||||
}
|
||||
progressWindow.bar.SetFraction(resp.Progress())
|
||||
progressWindow.percentLabel.SetText(fmt.Sprintf("%.0f%%", 100*resp.Progress()))
|
||||
})
|
||||
}
|
||||
|
||||
*err = resp.Err()
|
||||
|
||||
progressWindow.bar.SetFraction(1)
|
||||
|
||||
glib.IdleAdd(func() {
|
||||
progressWindow.Window.SetTitle("Download Complete")
|
||||
})
|
||||
}()
|
||||
done = true
|
||||
}(&err)
|
||||
|
||||
for {
|
||||
if done {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue