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
|
// License: MIT
|
||||||
|
|
||||||
import MimeType from "whatwg-mimetype";
|
import MimeType from "whatwg-mimetype";
|
||||||
import { debounce } from "../../uikit/lib/util";
|
|
||||||
import { CHROME, downloads, webRequest } from "../browser";
|
import { CHROME, downloads, webRequest } from "../browser";
|
||||||
import { Prefs } from "../prefs";
|
import { Prefs } from "../prefs";
|
||||||
import { PromiseSerializer } from "../pserializer";
|
import { PromiseSerializer } from "../pserializer";
|
||||||
@ -28,12 +27,6 @@ const PREROLL_HOSTS = /4cdn|chan/;
|
|||||||
const PREROLL_TIMEOUT = 10000;
|
const PREROLL_TIMEOUT = 10000;
|
||||||
const PREROLL_NOPE = new Set<string>();
|
const PREROLL_NOPE = new Set<string>();
|
||||||
|
|
||||||
const SHELF_TIMEOUT = 2000;
|
|
||||||
|
|
||||||
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
|
||||||
// ignored
|
|
||||||
};
|
|
||||||
|
|
||||||
function parseDisposition(disp: MimeType) {
|
function parseDisposition(disp: MimeType) {
|
||||||
if (!disp) {
|
if (!disp) {
|
||||||
return "";
|
return "";
|
||||||
@ -73,9 +66,6 @@ function parseDisposition(disp: MimeType) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const reenableShelf = debounce(
|
|
||||||
() => setShelfEnabled(true), SHELF_TIMEOUT, true);
|
|
||||||
|
|
||||||
type Header = {name: string; value: string};
|
type Header = {name: string; value: string};
|
||||||
interface Options {
|
interface Options {
|
||||||
conflictAction: string;
|
conflictAction: string;
|
||||||
@ -198,8 +188,6 @@ export class Download extends BaseDownload {
|
|||||||
this.manager.removeManId(this.manId);
|
this.manager.removeManId(this.manId);
|
||||||
}
|
}
|
||||||
|
|
||||||
setShelfEnabled(false);
|
|
||||||
try {
|
|
||||||
try {
|
try {
|
||||||
this.manager.addManId(
|
this.manager.addManId(
|
||||||
this.manId = await downloads.download(options), this);
|
this.manId = await downloads.download(options), this);
|
||||||
@ -213,10 +201,6 @@ export class Download extends BaseDownload {
|
|||||||
this.manager.addManId(
|
this.manager.addManId(
|
||||||
this.manId = await downloads.download(options), this);
|
this.manId = await downloads.download(options), this);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reenableShelf();
|
|
||||||
}
|
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
|
@ -25,6 +25,9 @@ const DIRTY_TIMEOUT = 100;
|
|||||||
const MISSING_TIMEOUT = 12 * 1000;
|
const MISSING_TIMEOUT = 12 * 1000;
|
||||||
const RELOAD_TIMEOUT = 10 * 1000;
|
const RELOAD_TIMEOUT = 10 * 1000;
|
||||||
|
|
||||||
|
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
||||||
|
// ignored
|
||||||
|
};
|
||||||
|
|
||||||
export class Manager extends EventEmitter {
|
export class Manager extends EventEmitter {
|
||||||
private items: Download[];
|
private items: Download[];
|
||||||
@ -151,7 +154,7 @@ export class Manager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
const next = await this.scheduler.next(this.running);
|
const next = await this.scheduler.next(this.running);
|
||||||
if (!next) {
|
if (!next) {
|
||||||
this.maybeNotifyFinished();
|
this.maybeRunFinishActions();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.running.has(next) || next.state !== QUEUED) {
|
if (this.running.has(next) || next.state !== QUEUED) {
|
||||||
@ -171,10 +174,31 @@ export class Manager extends EventEmitter {
|
|||||||
async startDownload(download: Download) {
|
async startDownload(download: Download) {
|
||||||
// Add to running first, so we don't confuse the scheduler and other parts
|
// Add to running first, so we don't confuse the scheduler and other parts
|
||||||
this.running.add(download);
|
this.running.add(download);
|
||||||
|
setShelfEnabled(false);
|
||||||
await download.start();
|
await download.start();
|
||||||
this.notifiedFinished = false;
|
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() {
|
async maybeNotifyFinished() {
|
||||||
if (!(await Prefs.get("finish-notification"))) {
|
if (!(await Prefs.get("finish-notification"))) {
|
||||||
return;
|
return;
|
||||||
@ -184,15 +208,6 @@ export class Manager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
this.notifiedFinished = true;
|
this.notifiedFinished = true;
|
||||||
new Notification(null, _("queue-finished"));
|
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) {
|
addManId(id: number, download: Download) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user