mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-31 23:38:23 -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 {
|
func downloadFile(progressWindow *ProgressWindow, client *grab.Client, url string, outputPath string) error {
|
||||||
|
done := false
|
||||||
req, err := grab.NewRequest(outputPath, url)
|
req, err := grab.NewRequest(outputPath, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := client.Do(req)
|
resp := client.Do(req)
|
||||||
if err := resp.Err(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
progressWindow.label.SetText(path.Base(resp.Filename))
|
progressWindow.label.SetText(path.Base(resp.Filename))
|
||||||
|
|
||||||
go func() {
|
go func(err *error) {
|
||||||
for !resp.IsComplete() {
|
for !resp.IsComplete() {
|
||||||
glib.IdleAdd(func() {
|
glib.IdleAdd(func() {
|
||||||
progress := float64(resp.BytesComplete()) / float64(resp.Size())
|
progressWindow.bar.SetFraction(resp.Progress())
|
||||||
progressWindow.bar.SetFraction(progress)
|
progressWindow.percentLabel.SetText(fmt.Sprintf("%.0f%%", 100*resp.Progress()))
|
||||||
progressWindow.percentLabel.SetText(fmt.Sprintf("%.0f%%", progress*100))
|
|
||||||
for gtk.EventsPending() {
|
|
||||||
gtk.MainIteration()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*err = resp.Err()
|
||||||
|
|
||||||
progressWindow.bar.SetFraction(1)
|
progressWindow.bar.SetFraction(1)
|
||||||
|
|
||||||
glib.IdleAdd(func() {
|
glib.IdleAdd(func() {
|
||||||
progressWindow.Window.SetTitle("Download Complete")
|
progressWindow.Window.SetTitle("Download Complete")
|
||||||
})
|
})
|
||||||
}()
|
done = true
|
||||||
|
}(&err)
|
||||||
|
|
||||||
|
for {
|
||||||
|
if done {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue