Skip to content

Commit 2b755d2

Browse files
More bugfixes
1 parent 191bb36 commit 2b755d2

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
4444
threadContainer.Add(progressBarContainer.container)
4545
go downloadChunk(url, path, workerId, outputFile, offset, progressBarContainer)
4646
time.Sleep(50 * time.Millisecond)
47+
activeWorkers++
4748
workerId++
4849
}
4950
for activeWorkers > 0 {
@@ -55,7 +56,6 @@ func startDownload(url string, path string, contentLength int64, outputFile *os.
5556
}
5657

5758
func downloadChunk(url string, path string, workerId int, outputFile *os.File, offset int64, progressBarContainer *ChunkContainer) {
58-
activeWorkers++
5959
success := false
6060

6161
for !success {

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
downloadButton *widget.Button
2828
threadContainer *fyne.Container
2929
usedContainers []*fyne.Container
30+
stopTime int64
3031
activeWorkers int
3132
downloading bool
3233

@@ -110,12 +111,18 @@ func main() {
110111

111112
func cleanContainers() {
112113
for downloading || activeWorkers >= 1 {
114+
if stopTime != 0 {
115+
if time.Now().Unix()-stopTime > int64(timeout) {
116+
enableDownloads()
117+
return
118+
}
119+
}
120+
113121
removeIndex := -1
114122
for index, container := range usedContainers {
115123
threadContainer.Remove(container)
116124
removeIndex = index
117125
}
118-
fmt.Println(len(usedContainers), activeWorkers)
119126
if removeIndex != -1 {
120127
usedContainers = append(usedContainers[:removeIndex], usedContainers[removeIndex+1:]...)
121128
}
@@ -155,6 +162,7 @@ func startDownloadManager(urlEntry *widget.Entry, pathEntry *widget.Entry) {
155162
downloading = false
156163
downloadButton.SetText("Cancelling...")
157164
downloadButton.Disable()
165+
stopTime = time.Now().Unix()
158166
return
159167
}
160168

@@ -218,6 +226,7 @@ func startDownloadManager(urlEntry *widget.Entry, pathEntry *widget.Entry) {
218226
return
219227
}
220228

229+
stopTime = 0
221230
startDownload(url, path, contentLength, outputFile)
222231
enableDownloads()
223232
}

0 commit comments

Comments
 (0)