Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions settings/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,24 @@ func Download(paths string, progressChan chan DownloadProgress, cancelChan chan
}
}
d.progress.Active = false
select { // nonblocking update of progress
case d.progressChan <- d.progress:
d.publishProgress()
}

func (d *download) publishProgress() {
progress := d.progress
progress.LocationsToDownload = append([]string(nil), d.progress.LocationsToDownload...)
progress.LocationDetails = make(map[string]*DownloadLocationDetail, len(d.progress.LocationDetails))
for path, detail := range d.progress.LocationDetails {
locationDetail := *detail
progress.LocationDetails[path] = &locationDetail
}

select { // discard queued progress
case <-d.progressChan:
default:
}
select {
case d.progressChan <- progress:
default:
}
}
Expand Down Expand Up @@ -170,10 +186,7 @@ func (d *download) downloadBounds(bounds Bounds, locationName string) (err error
d.progress.LocationDetails[locationName].TotalFiles = countFilesForBounds(bounds)
for i := minLat; i < maxLat; i += GROUP_AREA_BOX_DEGREES {
for j := minLon; j < maxLon; j += GROUP_AREA_BOX_DEGREES {
select { // nonblocking update of progress
case d.progressChan <- d.progress:
default:
}
d.publishProgress()
select { // cancel if sent message
case cancel := <-d.cancelChan:
if cancel {
Expand Down
14 changes: 10 additions & 4 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const SETTINGS_VERSION = 2 // Used for migrations
var Settings = MapdSettings{
SettingsVersion: SETTINGS_VERSION,
downloadProgress: make(chan DownloadProgress, 1),
cancelDownload: make(chan bool, 1),
}

type SpeedLimitPriority string
Expand Down Expand Up @@ -301,6 +300,9 @@ func (s *MapdSettings) GetDownloadProgress() (progress DownloadProgress, success
select {
case progress = <-s.downloadProgress:
s.downloadActive = progress.Active
if !progress.Active {
s.cancelDownload = nil
}
return progress, true
default:
}
Expand All @@ -327,9 +329,11 @@ func (s *MapdSettings) Handle(input custom.MapdIn) {
case custom.MapdInputType_loadRecommendedSettings:
s.Recommended()
case custom.MapdInputType_cancelDownload:
select {
case s.cancelDownload <- true:
default:
if s.downloadActive {
select {
case s.cancelDownload <- true:
default:
}
}
case custom.MapdInputType_download:
path, err := input.Str()
Expand All @@ -338,6 +342,8 @@ func (s *MapdSettings) Handle(input custom.MapdIn) {
return
}
if !s.downloadActive {
s.downloadActive = true
s.cancelDownload = make(chan bool, 1)
go Download(path, s.downloadProgress, s.cancelDownload)
}
case custom.MapdInputType_acceptSpeedLimit:
Expand Down
Loading