Skip to content

Commit

Permalink
Merge pull request #18463 from Snuffleupagus/app-rm-downloadComplete
Browse files Browse the repository at this point in the history
Re-factor the code to remove all uses of `PDFViewerApplication.downloadComplete`
  • Loading branch information
timvandermeij committed Jul 20, 2024
2 parents 9db1ae4 + 64a4f0d commit 7a8acee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
17 changes: 3 additions & 14 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ const PDFViewerApplication = {
/** @type {AnnotationEditorParams} */
annotationEditorParams: null,
isInitialViewSet: false,
downloadComplete: false,
isViewerEmbedded: window.parent !== window,
url: "",
baseUrl: "",
Expand Down Expand Up @@ -940,7 +939,6 @@ const PDFViewerApplication = {
this.pdfLinkService.externalLinkEnabled = true;
this.store = null;
this.isInitialViewSet = false;
this.downloadComplete = false;
this.url = "";
this.baseUrl = "";
this._downloadUrl = "";
Expand Down Expand Up @@ -1070,12 +1068,9 @@ const PDFViewerApplication = {
async download(options = {}) {
let data;
try {
if (this.downloadComplete) {
data = await this.pdfDocument.getData();
}
data = await this.pdfDocument.getData();
} catch {
// When the PDF document isn't ready, or the PDF file is still
// downloading, simply download using the URL.
// When the PDF document isn't ready, simply download using the URL.
}
this.downloadManager.download(
data,
Expand Down Expand Up @@ -1186,17 +1181,12 @@ const PDFViewerApplication = {
},

progress(level) {
if (!this.loadingBar || this.downloadComplete) {
// Don't accidentally show the loading bar again when the entire file has
// already been fetched (only an issue when disableAutoFetch is enabled).
return;
}
const percent = Math.round(level * 100);
// When we transition from full request to range requests, it's possible
// that we discard some of the loaded data. This can cause the loading
// bar to move backwards. So prevent this by only updating the bar if it
// increases.
if (percent <= this.loadingBar.percent) {
if (!this.loadingBar || percent <= this.loadingBar.percent) {
return;
}
this.loadingBar.percent = percent;
Expand All @@ -1219,7 +1209,6 @@ const PDFViewerApplication = {

pdfDocument.getDownloadInfo().then(({ length }) => {
this._contentLength = length; // Ensure that the correct length is used.
this.downloadComplete = true;
this.loadingBar?.hide();

firstPagePromise.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion web/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ class ProgressBar {
}

setDisableAutoFetch(delay = /* ms = */ 5000) {
if (isNaN(this.#percent)) {
if (this.#percent === 100 || isNaN(this.#percent)) {
return;
}
if (this.#disableAutoFetchTimeout) {
Expand Down

0 comments on commit 7a8acee

Please sign in to comment.