Disable shelf in chrome
We cannot just disable it for our downloads (reliably) so disable it completely while we're running.
This commit is contained in:
parent
38735ed0ae
commit
2d1f185fcd
@ -2,7 +2,6 @@
|
||||
// License: MIT
|
||||
|
||||
import MimeType from "whatwg-mimetype";
|
||||
import { debounce } from "../../uikit/lib/util";
|
||||
import { CHROME, downloads, webRequest } from "../browser";
|
||||
import { Prefs } from "../prefs";
|
||||
import { PromiseSerializer } from "../pserializer";
|
||||
@ -28,12 +27,6 @@ const PREROLL_HOSTS = /4cdn|chan/;
|
||||
const PREROLL_TIMEOUT = 10000;
|
||||
const PREROLL_NOPE = new Set<string>();
|
||||
|
||||
const SHELF_TIMEOUT = 2000;
|
||||
|
||||
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
||||
// ignored
|
||||
};
|
||||
|
||||
function parseDisposition(disp: MimeType) {
|
||||
if (!disp) {
|
||||
return "";
|
||||
@ -73,9 +66,6 @@ function parseDisposition(disp: MimeType) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const reenableShelf = debounce(
|
||||
() => setShelfEnabled(true), SHELF_TIMEOUT, true);
|
||||
|
||||
type Header = {name: string; value: string};
|
||||
interface Options {
|
||||
conflictAction: string;
|
||||
@ -198,24 +188,18 @@ export class Download extends BaseDownload {
|
||||
this.manager.removeManId(this.manId);
|
||||
}
|
||||
|
||||
setShelfEnabled(false);
|
||||
try {
|
||||
try {
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
catch (ex) {
|
||||
if (!this.referrer) {
|
||||
throw ex;
|
||||
}
|
||||
// Re-attempt without referrer
|
||||
filterInSitu(options.headers, h => h.name !== "Referer");
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
finally {
|
||||
reenableShelf();
|
||||
catch (ex) {
|
||||
if (!this.referrer) {
|
||||
throw ex;
|
||||
}
|
||||
// Re-attempt without referrer
|
||||
filterInSitu(options.headers, h => h.name !== "Referer");
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
this.markDirty();
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ const DIRTY_TIMEOUT = 100;
|
||||
const MISSING_TIMEOUT = 12 * 1000;
|
||||
const RELOAD_TIMEOUT = 10 * 1000;
|
||||
|
||||
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
||||
// ignored
|
||||
};
|
||||
|
||||
export class Manager extends EventEmitter {
|
||||
private items: Download[];
|
||||
@ -151,7 +154,7 @@ export class Manager extends EventEmitter {
|
||||
}
|
||||
const next = await this.scheduler.next(this.running);
|
||||
if (!next) {
|
||||
this.maybeNotifyFinished();
|
||||
this.maybeRunFinishActions();
|
||||
break;
|
||||
}
|
||||
if (this.running.has(next) || next.state !== QUEUED) {
|
||||
@ -171,10 +174,31 @@ export class Manager extends EventEmitter {
|
||||
async startDownload(download: Download) {
|
||||
// Add to running first, so we don't confuse the scheduler and other parts
|
||||
this.running.add(download);
|
||||
setShelfEnabled(false);
|
||||
await download.start();
|
||||
this.notifiedFinished = false;
|
||||
}
|
||||
|
||||
async maybeRunFinishActions() {
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
await this.maybeNotifyFinished();
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
if (this.shouldReload) {
|
||||
this.saveQueue.trigger();
|
||||
setTimeout(() => {
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
runtime.reload();
|
||||
}, RELOAD_TIMEOUT);
|
||||
}
|
||||
setShelfEnabled(true);
|
||||
}
|
||||
|
||||
async maybeNotifyFinished() {
|
||||
if (!(await Prefs.get("finish-notification"))) {
|
||||
return;
|
||||
@ -184,15 +208,6 @@ export class Manager extends EventEmitter {
|
||||
}
|
||||
this.notifiedFinished = true;
|
||||
new Notification(null, _("queue-finished"));
|
||||
if (this.shouldReload) {
|
||||
this.saveQueue.trigger();
|
||||
setTimeout(() => {
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
runtime.reload();
|
||||
}, RELOAD_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
addManId(id: number, download: Download) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user