Handle Chrome state changes correct.

This commit is contained in:
Nils Maier 2019-09-12 20:54:16 +02:00
parent 1a836d914b
commit e760d2b022

View File

@ -65,23 +65,23 @@ export class Download extends BaseDownload {
if (this.manId) { if (this.manId) {
const {manId: id} = this; const {manId: id} = this;
try { try {
const state = await downloads.search({id}); const state = (await downloads.search({id})).pop() || {};
if (state[0].state === "in_progress") { if (state.state === "in_progress" && !state.error && !state.paused) {
this.changeState(RUNNING); this.changeState(RUNNING);
this.updateStateFromBrowser(); this.updateStateFromBrowser();
return; return;
} }
if (state[0].state === "complete") { if (state.state === "complete") {
this.changeState(DONE); this.changeState(DONE);
this.updateStateFromBrowser(); this.updateStateFromBrowser();
return; return;
} }
if (!state[0].canResume) { if (!state.canResume) {
throw new Error("Cannot resume"); throw new Error("Cannot resume");
} }
// Cannot await here // Cannot await here
// Firefox bug: will not return until download is finished // Firefox bug: will not return until download is finished
downloads.resume(id).catch(() => {}); downloads.resume(id).catch(console.error);
this.changeState(RUNNING); this.changeState(RUNNING);
return; return;
} }
@ -314,7 +314,10 @@ export class Download extends BaseDownload {
this.markDirty(); this.markDirty();
switch (state.state) { switch (state.state) {
case "in_progress": case "in_progress":
if (error) { if (state.paused) {
this.changeState(PAUSED);
}
else if (error) {
this.cancel(); this.cancel();
this.error = error; this.error = error;
} }