diff --git a/src/app/components/browse/status-bar/status-bar.component.ts b/src/app/components/browse/status-bar/status-bar.component.ts index 522525d..4ed1789 100644 --- a/src/app/components/browse/status-bar/status-bar.component.ts +++ b/src/app/components/browse/status-bar/status-bar.component.ts @@ -29,9 +29,11 @@ export class StatusBarComponent { ref: ChangeDetectorRef ) { downloadService.onDownloadUpdated(() => { - this.downloading = downloadService.downloadCount > 0 - this.percent = downloadService.totalPercent - ref.detectChanges() + setTimeout(() => { // Make sure this is the last callback executed to get the accurate downloadCount + this.downloading = downloadService.downloadCount > 0 + this.percent = downloadService.totalPercent + ref.detectChanges() + }, 0) }) searchService.onSearchChanged(() => { diff --git a/src/app/core/services/download.service.ts b/src/app/core/services/download.service.ts index 4161f0e..107dda1 100644 --- a/src/app/core/services/download.service.ts +++ b/src/app/core/services/download.service.ts @@ -46,7 +46,7 @@ export class DownloadService { } onDownloadUpdated(callback: (download: DownloadProgress) => void) { - const debouncedCallback = _.throttle(callback, 30) + const debouncedCallback = _.throttle(callback, 30, { trailing: false }) this.downloadUpdatedEmitter.subscribe((download: DownloadProgress) => { if (download.type == 'fastUpdate') { // 'good' updates can happen so frequently that the UI doesn't update correctly debouncedCallback(download) diff --git a/src/electron/ipc/download/ChartDownload.ts b/src/electron/ipc/download/ChartDownload.ts index 12098c7..f3fb101 100644 --- a/src/electron/ipc/download/ChartDownload.ts +++ b/src/electron/ipc/download/ChartDownload.ts @@ -119,7 +119,7 @@ export class ChartDownload { // DOWNLOAD FILES for (let i = 0; i < this.files.length; i++) { - const downloader = new FileDownloader(this.files[i].webContentLink, chartPath) + const downloader = new FileDownloader(this.files[i].webContentLink, join(chartPath, this.files[i].name)) this.cancelFn = () => downloader.cancelDownload() const downloadComplete = this.addDownloadEventListeners(downloader, i) diff --git a/src/electron/ipc/download/DownloadHandler.ts b/src/electron/ipc/download/DownloadHandler.ts index e977806..06ae81a 100644 --- a/src/electron/ipc/download/DownloadHandler.ts +++ b/src/electron/ipc/download/DownloadHandler.ts @@ -29,7 +29,7 @@ class DownloadHandler implements IPCEmitHandler<'download'> { } } - private retryDownload(data: Download) { + private retryDownload(data: Download) { // TODO: cause this to send a GUI update that says waiting for download to finish... const index = this.retryWaiting.findIndex(download => download.versionID == data.versionID) if (index != -1) { const retryDownload = this.retryWaiting.splice(index, 1)[0] @@ -43,7 +43,7 @@ class DownloadHandler implements IPCEmitHandler<'download'> { } private cancelDownload(data: Download) { - if (this.currentDownload.versionID == data.versionID) { + if (this.currentDownload?.versionID == data.versionID) { this.currentDownload.cancel() this.currentDownload = undefined this.startNextDownload() diff --git a/src/electron/ipc/download/FileExtractor.ts b/src/electron/ipc/download/FileExtractor.ts index 7ccf891..bfc8261 100644 --- a/src/electron/ipc/download/FileExtractor.ts +++ b/src/electron/ipc/download/FileExtractor.ts @@ -112,7 +112,7 @@ export class FileExtractor { const stream = node7z.extractFull(fullPath, this.sourceFolder, { $progress: true, $bin: zipBin.path7za }) stream.on('progress', this.cancelable((progress: { percent: number; fileCount: number }) => { - this.callbacks.extractProgress(progress.percent, progress.fileCount) + this.callbacks.extractProgress(progress.percent, isNaN(progress.fileCount) ? 0 : progress.fileCount) })) let extractErrorOccured = false