@@ -32,7 +32,7 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
3232 return
3333 }
3434 for activeWorkers >= workers {
35- time .Sleep (500 * time .Millisecond )
35+ time .Sleep (200 * time .Millisecond )
3636 }
3737 label := fmt .Sprintf ("Worker %v/%v" , workerId , int64 (contentLength / chunkSize ))
3838 progressBar := widget .NewProgressBar ()
@@ -43,17 +43,19 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
4343 }
4444 threadContainer .Add (progressBarContainer .container )
4545 go downloadChunk (url , path , workerId , outputFile , offset , progressBarContainer )
46- activeWorkers ++
46+ time . Sleep ( 50 * time . Millisecond )
4747 workerId ++
4848 }
4949 for activeWorkers > 0 {
5050 time .Sleep (1 * time .Second )
5151 }
52- dialog .ShowInformation ("Download Complete" , "Your file has been successfully downloaded!" , mainWindow )
53- enableDownloads ()
52+ if downloading {
53+ dialog .ShowInformation ("Download Complete" , "Your file has been successfully downloaded!" , mainWindow )
54+ }
5455}
5556
5657func downloadChunk (url string , path string , workerId int , outputFile * os.File , offset int64 , progressBarContainer * ChunkContainer ) {
58+ activeWorkers ++
5759 success := false
5860
5961 for ! success {
@@ -100,14 +102,15 @@ func downloadChunk(url string, path string, workerId int, outputFile *os.File, o
100102 )
101103 if err != nil {
102104 if err .Error () == "cancelled" {
103- break
105+ activeWorkers --
106+ return
104107 }
105108 dialog .ShowInformation ("Error (retrying)" , fmt .Sprintf ("Worker %v has ran into an error:\n %v" , workerId , wrapText (err .Error ())), mainWindow )
106109 continue
107110 }
108111 success = true
109112 }
110113
111- usedContainers = append (usedContainers , progressBarContainer .container )
112114 activeWorkers --
115+ usedContainers = append (usedContainers , progressBarContainer .container )
113116}
0 commit comments