From e760d2b02286e48f2cec6d9cf191165769476cb5 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Thu, 12 Sep 2019 20:54:16 +0200 Subject: [PATCH] Handle Chrome state changes correct. --- lib/manager/download.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/manager/download.ts b/lib/manager/download.ts index ef63657..1b56062 100644 --- a/lib/manager/download.ts +++ b/lib/manager/download.ts @@ -65,23 +65,23 @@ export class Download extends BaseDownload { if (this.manId) { const {manId: id} = this; try { - const state = await downloads.search({id}); - if (state[0].state === "in_progress") { + const state = (await downloads.search({id})).pop() || {}; + if (state.state === "in_progress" && !state.error && !state.paused) { this.changeState(RUNNING); this.updateStateFromBrowser(); return; } - if (state[0].state === "complete") { + if (state.state === "complete") { this.changeState(DONE); this.updateStateFromBrowser(); return; } - if (!state[0].canResume) { + if (!state.canResume) { throw new Error("Cannot resume"); } // Cannot await here // Firefox bug: will not return until download is finished - downloads.resume(id).catch(() => {}); + downloads.resume(id).catch(console.error); this.changeState(RUNNING); return; } @@ -314,7 +314,10 @@ export class Download extends BaseDownload { this.markDirty(); switch (state.state) { case "in_progress": - if (error) { + if (state.paused) { + this.changeState(PAUSED); + } + else if (error) { this.cancel(); this.error = error; }