fix download cancel
This commit is contained in:
parent
05696cffd9
commit
b76899a353
|
@ -94,7 +94,6 @@ export default class FileReceiver extends Nanobus {
|
||||||
this.downloadRequest = {
|
this.downloadRequest = {
|
||||||
cancel: () => {
|
cancel: () => {
|
||||||
this.sendMessageToSw({ request: 'cancel', id: this.fileInfo.id });
|
this.sendMessageToSw({ request: 'cancel', id: this.fileInfo.id });
|
||||||
throw new Error(0);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -129,17 +128,17 @@ export default class FileReceiver extends Nanobus {
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
URL.revokeObjectURL(downloadUrl);
|
URL.revokeObjectURL(downloadUrl);
|
||||||
|
}
|
||||||
|
|
||||||
let prog = 0;
|
let prog = 0;
|
||||||
while (prog < this.fileInfo.size) {
|
while (prog < this.fileInfo.size) {
|
||||||
const msg = await this.sendMessageToSw({
|
const msg = await this.sendMessageToSw({
|
||||||
request: 'progress',
|
request: 'progress',
|
||||||
id: this.fileInfo.id
|
id: this.fileInfo.id
|
||||||
});
|
});
|
||||||
prog = msg.progress;
|
prog = msg.progress;
|
||||||
onprogress([prog, this.fileInfo.size]);
|
onprogress([prog, this.fileInfo.size]);
|
||||||
await delay();
|
await delay();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.downloadRequest = null;
|
this.downloadRequest = null;
|
||||||
|
@ -147,6 +146,9 @@ export default class FileReceiver extends Nanobus {
|
||||||
this.state = 'complete';
|
this.state = 'complete';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.downloadRequest = null;
|
this.downloadRequest = null;
|
||||||
|
if (e === 'cancelled') {
|
||||||
|
throw new Error(0);
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue