@@ -26,10 +26,11 @@ var (
2626 mainWindow fyne.Window
2727 downloadButton * widget.Button
2828 threadContainer * fyne.Container
29+ usedContainers []* fyne.Container
2930 activeWorkers int
3031 downloading bool
3132
32- workers int = 16
33+ workers int = 32
3334 chunkSize int64 = 512000
3435 timeout int = 10
3536 userAgent string = "go-http-client/paralload"
@@ -106,6 +107,16 @@ func main() {
106107 mainWindow .ShowAndRun ()
107108}
108109
110+ func cleanContainers () {
111+ for downloading || activeWorkers >= 1 {
112+ for _ , container := range usedContainers {
113+ threadContainer .Remove (container )
114+ }
115+ threadContainer .Refresh ()
116+ time .Sleep (50 * time .Millisecond )
117+ }
118+ }
119+
109120func enableDownloads () {
110121 downloadButton .SetText ("Download" )
111122 downloadButton .Enable ()
@@ -212,6 +223,7 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
212223
213224 var workerId int
214225 var offset int64
226+ go cleanContainers ()
215227 for offset = 0 ; offset <= contentLength ; offset += chunkSize {
216228 if ! downloading {
217229 for activeWorkers > 0 {
@@ -231,11 +243,9 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
231243 fyne .NewContainerWithLayout (layout .NewFormLayout (), widget .NewLabel (label ), progressBar ),
232244 }
233245 threadContainer .Add (progressBarContainer .container )
234- threadContainer .Refresh ()
235246 go downloadChunk (url , path , workerId , outputFile , offset , progressBarContainer )
236247 activeWorkers ++
237248 workerId ++
238- time .Sleep (50 * time .Millisecond )
239249 }
240250 for activeWorkers > 0 {
241251 time .Sleep (1 * time .Second )
@@ -298,7 +308,7 @@ func downloadChunk(url string, path string, workerId int, outputFile *os.File, o
298308 success = true
299309 }
300310
301- threadContainer . Remove ( progressBarContainer .container )
311+ usedContainers = append ( usedContainers , progressBarContainer .container )
302312 activeWorkers --
303313}
304314
0 commit comments