From d7013bee54f4b6f3ff174c3381062d1e2474eb62 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 21 Jan 2023 12:29:36 +0100 Subject: [PATCH] Move the `disableAutoFetch` functionality into the `ProgressBar`-class It seems nicer overall, since we're exporting the `ProgressBar` in the viewer-components, to move this functionality into the `ProgressBar`-class itself rather than handling it "manually" in the default-viewer. --- web/app.js | 20 ++++---------------- web/ui_utils.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/web/app.js b/web/app.js index 4bbc56423..4b7b7c65a 100644 --- a/web/app.js +++ b/web/app.js @@ -77,7 +77,6 @@ import { SecondaryToolbar } from "./secondary_toolbar.js"; import { Toolbar } from "./toolbar.js"; import { ViewHistory } from "./view_history.js"; -const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms @@ -1121,23 +1120,12 @@ const PDFViewerApplication = { // the loading bar will not be completely filled, nor will it be hidden. // To prevent displaying a partially filled loading bar permanently, we // hide it when no data has been loaded during a certain amount of time. - const disableAutoFetch = + if ( this.pdfDocument?.loadingParams.disableAutoFetch ?? - AppOptions.get("disableAutoFetch"); - - if (!disableAutoFetch || isNaN(percent)) { - return; + AppOptions.get("disableAutoFetch") + ) { + this.loadingBar.setDisableAutoFetch(); } - if (this.disableAutoFetchLoadingBarTimeout) { - clearTimeout(this.disableAutoFetchLoadingBarTimeout); - this.disableAutoFetchLoadingBarTimeout = null; - } - this.loadingBar.show(); - - this.disableAutoFetchLoadingBarTimeout = setTimeout(() => { - this.loadingBar.hide(); - this.disableAutoFetchLoadingBarTimeout = null; - }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT); }, load(pdfDocument) { diff --git a/web/ui_utils.js b/web/ui_utils.js index 39d6d598a..45e0d3579 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -693,6 +693,8 @@ function clamp(v, min, max) { class ProgressBar { #classList = null; + #disableAutoFetchTimeout = null; + #percent = 0; #visible = true; @@ -728,6 +730,21 @@ class ProgressBar { } } + setDisableAutoFetch(delay = /* ms = */ 5000) { + if (isNaN(this.#percent)) { + return; + } + if (this.#disableAutoFetchTimeout) { + clearTimeout(this.#disableAutoFetchTimeout); + } + this.show(); + + this.#disableAutoFetchTimeout = setTimeout(() => { + this.#disableAutoFetchTimeout = null; + this.hide(); + }, delay); + } + hide() { if (!this.#visible) { return;