Cancel, Retry, and Warning download UI

This commit is contained in:
Geomitron
2020-02-11 20:50:51 -05:00
parent a98b03dcd4
commit db083d573a
13 changed files with 291 additions and 179 deletions

View File

@@ -29,6 +29,7 @@ export class FileExtractor {
private callbacks = {} as Callbacks
private libraryFolder: string
private wasCanceled = false
constructor(private sourceFolder: string, private isArchive: boolean, private destinationFolderName: string) { }
/**
@@ -58,6 +59,7 @@ export class FileExtractor {
* @param filename The name of the archive file.
*/
private extract(filename: string) {
if (this.wasCanceled) { return } // CANCEL POINT
this.callbacks.extract(filename)
const source = join(this.sourceFolder, filename)
@@ -93,6 +95,7 @@ export class FileExtractor {
* Deletes the archive at <archiveFilepath>, then transfers the extracted chart to <this.libraryFolder>.
*/
private async transfer(archiveFilepath?: string) {
if (this.wasCanceled) { return } // CANCEL POINT
try {
// Create destiniation folder if it doesn't exist
@@ -117,6 +120,8 @@ export class FileExtractor {
files = await readdir(this.sourceFolder)
}
if (this.wasCanceled) { return } // CANCEL POINT
// Copy the files from the temporary directory to the destination
for (const file of files) {
await copyFile(join(this.sourceFolder, file), join(destinationFolder, file))
@@ -133,4 +138,8 @@ export class FileExtractor {
this.callbacks.error({ header: 'Transfer Failed', body: `Unable to transfer downloaded files to the library folder: ${e.name}` }, undefined)
}
}
cancelExtract() {
this.wasCanceled = true
}
}