Fixed download bugs

This commit is contained in:
Geomitron
2020-05-10 13:53:54 -04:00
parent 1cfb5f4e93
commit a81fddea3b
5 changed files with 10 additions and 8 deletions

View File

@@ -29,9 +29,11 @@ export class StatusBarComponent {
ref: ChangeDetectorRef ref: ChangeDetectorRef
) { ) {
downloadService.onDownloadUpdated(() => { downloadService.onDownloadUpdated(() => {
this.downloading = downloadService.downloadCount > 0 setTimeout(() => { // Make sure this is the last callback executed to get the accurate downloadCount
this.percent = downloadService.totalPercent this.downloading = downloadService.downloadCount > 0
ref.detectChanges() this.percent = downloadService.totalPercent
ref.detectChanges()
}, 0)
}) })
searchService.onSearchChanged(() => { searchService.onSearchChanged(() => {

View File

@@ -46,7 +46,7 @@ export class DownloadService {
} }
onDownloadUpdated(callback: (download: DownloadProgress) => void) { onDownloadUpdated(callback: (download: DownloadProgress) => void) {
const debouncedCallback = _.throttle(callback, 30) const debouncedCallback = _.throttle(callback, 30, { trailing: false })
this.downloadUpdatedEmitter.subscribe((download: DownloadProgress) => { this.downloadUpdatedEmitter.subscribe((download: DownloadProgress) => {
if (download.type == 'fastUpdate') { // 'good' updates can happen so frequently that the UI doesn't update correctly if (download.type == 'fastUpdate') { // 'good' updates can happen so frequently that the UI doesn't update correctly
debouncedCallback(download) debouncedCallback(download)

View File

@@ -119,7 +119,7 @@ export class ChartDownload {
// DOWNLOAD FILES // DOWNLOAD FILES
for (let i = 0; i < this.files.length; i++) { 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() this.cancelFn = () => downloader.cancelDownload()
const downloadComplete = this.addDownloadEventListeners(downloader, i) const downloadComplete = this.addDownloadEventListeners(downloader, i)

View File

@@ -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) const index = this.retryWaiting.findIndex(download => download.versionID == data.versionID)
if (index != -1) { if (index != -1) {
const retryDownload = this.retryWaiting.splice(index, 1)[0] const retryDownload = this.retryWaiting.splice(index, 1)[0]
@@ -43,7 +43,7 @@ class DownloadHandler implements IPCEmitHandler<'download'> {
} }
private cancelDownload(data: Download) { private cancelDownload(data: Download) {
if (this.currentDownload.versionID == data.versionID) { if (this.currentDownload?.versionID == data.versionID) {
this.currentDownload.cancel() this.currentDownload.cancel()
this.currentDownload = undefined this.currentDownload = undefined
this.startNextDownload() this.startNextDownload()

View File

@@ -112,7 +112,7 @@ export class FileExtractor {
const stream = node7z.extractFull(fullPath, this.sourceFolder, { $progress: true, $bin: zipBin.path7za }) const stream = node7z.extractFull(fullPath, this.sourceFolder, { $progress: true, $bin: zipBin.path7za })
stream.on('progress', this.cancelable((progress: { percent: number; fileCount: number }) => { 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 let extractErrorOccured = false