Fixed cancel button sometimes not working

This commit is contained in:
Geomitron
2021-03-18 16:54:13 -05:00
parent 275a840467
commit aa8eba5a87
4 changed files with 18 additions and 9 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "bridge",
"version": "0.1.0",
"version": "1.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -19,10 +19,10 @@ export class DownloadsModalComponent {
downloadService.onDownloadUpdated(download => {
const index = this.downloads.findIndex(thisDownload => thisDownload.versionID == download.versionID)
if (index == -1) {
if (download.type == 'cancel') {
this.downloads = this.downloads.filter(thisDownload => thisDownload.versionID != download.versionID)
} else if (index == -1) {
this.downloads.push(download)
} else if (download.type == 'cancel') {
this.downloads.splice(index, 1)
} else {
this.downloads[index] = download
}

View File

@@ -35,7 +35,9 @@ export class DownloadService {
this.electronService.receiveIPC('download-updated', result => {
// Update <this.downloads> with result
const thisDownloadIndex = this.downloads.findIndex(download => download.versionID == result.versionID)
if (thisDownloadIndex == -1) {
if (result.type == 'cancel') {
this.downloads = this.downloads.filter(download => download.versionID != versionID)
} else if (thisDownloadIndex == -1) {
this.downloads.push(result)
} else {
this.downloads[thisDownloadIndex] = result
@@ -53,10 +55,13 @@ export class DownloadService {
cancelDownload(versionID: number) {
const removedDownload = this.downloads.find(download => download.versionID == versionID)
this.downloads = this.downloads.filter(download => download.versionID != versionID)
removedDownload.type = 'cancel'
this.downloadUpdatedEmitter.emit(removedDownload)
this.electronService.sendIPC('download', { action: 'cancel', versionID })
if (['error', 'done'].includes(removedDownload.type)) {
this.downloads = this.downloads.filter(download => download.versionID != versionID)
removedDownload.type = 'cancel'
this.downloadUpdatedEmitter.emit(removedDownload)
} else {
this.electronService.sendIPC('download', { action: 'cancel', versionID })
}
}
retryDownload(versionID: number) {

View File

@@ -31,6 +31,7 @@ export class ChartDownload {
private percent = 0 // Needs to be stored here because errors won't know the exact percent
private tempPath: string
private dropFastUpdate = false
private wasCanceled = false
private readonly individualFileProgressPortion: number
private readonly destinationFolderName: string
@@ -90,12 +91,15 @@ export class ChartDownload {
cancelFn()
rimraf(this.tempPath).catch(() => { /** Do nothing */ }) // Delete temp folder
}
this.updateGUI('', '', 'cancel')
this.wasCanceled = true
}
/**
* Updates the GUI with new information about this chart download.
*/
private updateGUI(header: string, description: string, type: ProgressType) {
if (this.wasCanceled) { return }
if (type == 'fastUpdate') {
if (this.dropFastUpdate) {
return