mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-07 10:35:09 +00:00
Fixed cancel button sometimes not working
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bridge",
|
"name": "bridge",
|
||||||
"version": "0.1.0",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ export class DownloadsModalComponent {
|
|||||||
|
|
||||||
downloadService.onDownloadUpdated(download => {
|
downloadService.onDownloadUpdated(download => {
|
||||||
const index = this.downloads.findIndex(thisDownload => thisDownload.versionID == download.versionID)
|
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)
|
this.downloads.push(download)
|
||||||
} else if (download.type == 'cancel') {
|
|
||||||
this.downloads.splice(index, 1)
|
|
||||||
} else {
|
} else {
|
||||||
this.downloads[index] = download
|
this.downloads[index] = download
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ export class DownloadService {
|
|||||||
this.electronService.receiveIPC('download-updated', result => {
|
this.electronService.receiveIPC('download-updated', result => {
|
||||||
// Update <this.downloads> with result
|
// Update <this.downloads> with result
|
||||||
const thisDownloadIndex = this.downloads.findIndex(download => download.versionID == result.versionID)
|
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)
|
this.downloads.push(result)
|
||||||
} else {
|
} else {
|
||||||
this.downloads[thisDownloadIndex] = result
|
this.downloads[thisDownloadIndex] = result
|
||||||
@@ -53,10 +55,13 @@ export class DownloadService {
|
|||||||
|
|
||||||
cancelDownload(versionID: number) {
|
cancelDownload(versionID: number) {
|
||||||
const removedDownload = this.downloads.find(download => download.versionID == versionID)
|
const removedDownload = this.downloads.find(download => download.versionID == versionID)
|
||||||
this.downloads = this.downloads.filter(download => download.versionID != versionID)
|
if (['error', 'done'].includes(removedDownload.type)) {
|
||||||
removedDownload.type = 'cancel'
|
this.downloads = this.downloads.filter(download => download.versionID != versionID)
|
||||||
this.downloadUpdatedEmitter.emit(removedDownload)
|
removedDownload.type = 'cancel'
|
||||||
this.electronService.sendIPC('download', { action: 'cancel', versionID })
|
this.downloadUpdatedEmitter.emit(removedDownload)
|
||||||
|
} else {
|
||||||
|
this.electronService.sendIPC('download', { action: 'cancel', versionID })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retryDownload(versionID: number) {
|
retryDownload(versionID: number) {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export class ChartDownload {
|
|||||||
private percent = 0 // Needs to be stored here because errors won't know the exact percent
|
private percent = 0 // Needs to be stored here because errors won't know the exact percent
|
||||||
private tempPath: string
|
private tempPath: string
|
||||||
private dropFastUpdate = false
|
private dropFastUpdate = false
|
||||||
|
private wasCanceled = false
|
||||||
|
|
||||||
private readonly individualFileProgressPortion: number
|
private readonly individualFileProgressPortion: number
|
||||||
private readonly destinationFolderName: string
|
private readonly destinationFolderName: string
|
||||||
@@ -90,12 +91,15 @@ export class ChartDownload {
|
|||||||
cancelFn()
|
cancelFn()
|
||||||
rimraf(this.tempPath).catch(() => { /** Do nothing */ }) // Delete temp folder
|
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.
|
* Updates the GUI with new information about this chart download.
|
||||||
*/
|
*/
|
||||||
private updateGUI(header: string, description: string, type: ProgressType) {
|
private updateGUI(header: string, description: string, type: ProgressType) {
|
||||||
|
if (this.wasCanceled) { return }
|
||||||
if (type == 'fastUpdate') {
|
if (type == 'fastUpdate') {
|
||||||
if (this.dropFastUpdate) {
|
if (this.dropFastUpdate) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user