Prevent multiple downloads of the same thing

This commit is contained in:
Geomitron
2020-05-18 18:21:38 -04:00
parent ebe22a39e9
commit ac22fb286d
3 changed files with 10 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ export class ChartDownload {
/** If this chart download needs to be retried */ /** If this chart download needs to be retried */
get hasFailed() { return this._hasFailed } get hasFailed() { return this._hasFailed }
get isArchive() { return this.data.driveData.isArchive } get isArchive() { return this.data.driveData.isArchive }
get hash() { return this.data.driveData.filesHash }
constructor(public versionID: number, private data: NewDownload) { constructor(public versionID: number, private data: NewDownload) {
this.updateGUI('', 'Waiting for other downloads to finish...', 'good') this.updateGUI('', 'Waiting for other downloads to finish...', 'good')

View File

@@ -19,6 +19,11 @@ class DownloadHandler implements IPCEmitHandler<'download'> {
} }
private addDownload(data: Download) { private addDownload(data: Download) {
const filesHash = data.data.driveData.filesHash
if (this.currentDownload?.hash == filesHash || this.downloadQueue.isDownloadingLink(filesHash)) {
return
}
const newDownload = new ChartDownload(data.versionID, data.data) const newDownload = new ChartDownload(data.versionID, data.data)
this.addDownloadEventListeners(newDownload) this.addDownloadEventListeners(newDownload)
if (this.currentDownload == undefined) { if (this.currentDownload == undefined) {

View File

@@ -6,6 +6,10 @@ export class DownloadQueue {
downloadQueue: ChartDownload[] = [] downloadQueue: ChartDownload[] = []
isDownloadingLink(filesHash: string) {
return this.downloadQueue.some(download => download.hash == filesHash)
}
isEmpty() { isEmpty() {
return this.downloadQueue.length == 0 return this.downloadQueue.length == 0
} }