Merge pull request #15949 from Snuffleupagus/ProgressBar-setDisableAutoFetch

Move the `disableAutoFetch` functionality into the `ProgressBar`-class
This commit is contained in:
Tim van der Meij 2023-01-21 13:54:18 +01:00 committed by GitHub
commit 8278abb3f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 16 deletions

View File

@ -77,7 +77,6 @@ import { SecondaryToolbar } from "./secondary_toolbar.js";
import { Toolbar } from "./toolbar.js"; import { Toolbar } from "./toolbar.js";
import { ViewHistory } from "./view_history.js"; import { ViewHistory } from "./view_history.js";
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // 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. // the loading bar will not be completely filled, nor will it be hidden.
// To prevent displaying a partially filled loading bar permanently, we // To prevent displaying a partially filled loading bar permanently, we
// hide it when no data has been loaded during a certain amount of time. // hide it when no data has been loaded during a certain amount of time.
const disableAutoFetch = if (
this.pdfDocument?.loadingParams.disableAutoFetch ?? this.pdfDocument?.loadingParams.disableAutoFetch ??
AppOptions.get("disableAutoFetch"); AppOptions.get("disableAutoFetch")
) {
if (!disableAutoFetch || isNaN(percent)) { this.loadingBar.setDisableAutoFetch();
return;
} }
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) { load(pdfDocument) {

View File

@ -693,6 +693,8 @@ function clamp(v, min, max) {
class ProgressBar { class ProgressBar {
#classList = null; #classList = null;
#disableAutoFetchTimeout = null;
#percent = 0; #percent = 0;
#visible = true; #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() { hide() {
if (!this.#visible) { if (!this.#visible) {
return; return;