Fix downloads

This commit is contained in:
Geomitron
2023-12-25 02:49:46 -06:00
parent ba309654ca
commit 99cfb306be
30 changed files with 557 additions and 1450 deletions

View File

@@ -1,6 +1,5 @@
import { ChangeDetectorRef, Component } from '@angular/core'
import { Component, HostBinding } from '@angular/core'
import { DownloadProgress } from '../../../../../../src-shared/interfaces/download.interface'
import { DownloadService } from '../../../../core/services/download.service'
@Component({
@@ -8,45 +7,9 @@ import { DownloadService } from '../../../../core/services/download.service'
templateUrl: './downloads-modal.component.html',
})
export class DownloadsModalComponent {
@HostBinding('class.contents') contents = true
downloads: DownloadProgress[] = []
constructor(private downloadService: DownloadService, ref: ChangeDetectorRef) {
window.electron.on.queueUpdated(order => {
this.downloads.sort((a, b) => order.indexOf(a.versionID) - order.indexOf(b.versionID))
})
downloadService.onDownloadUpdated(download => {
const index = this.downloads.findIndex(thisDownload => thisDownload.versionID === download.versionID)
if (download.type === 'cancel') {
this.downloads = this.downloads.filter(thisDownload => thisDownload.versionID !== download.versionID)
} else if (index === -1) {
this.downloads.push(download)
} else {
this.downloads[index] = download
}
ref.detectChanges()
})
}
trackByVersionID(_index: number, item: DownloadProgress) {
return item.versionID
}
cancelDownload(versionID: number) {
this.downloadService.cancelDownload(versionID)
}
retryDownload(versionID: number) {
this.downloadService.retryDownload(versionID)
}
getBackgroundColor(download: DownloadProgress) {
switch (download.type) {
case 'error': return '#a63a3a'
default: return undefined
}
}
constructor(public downloadService: DownloadService) { }
showFile(filepath: string) {
window.electron.emit.showFile(filepath)