1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #18463 from Snuffleupagus/app-rm-downloadComplete

Re-factor the code to remove all uses of `PDFViewerApplication.downloadComplete`
This commit is contained in:
Tim van der Meij 2024-07-20 18:11:32 +02:00 committed by GitHub
commit 7a8aceef20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 15 deletions

View file

@ -151,7 +151,6 @@ const PDFViewerApplication = {
/** @type {AnnotationEditorParams} */
annotationEditorParams: null,
isInitialViewSet: false,
downloadComplete: false,
isViewerEmbedded: window.parent !== window,
url: "",
baseUrl: "",
@ -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 = "";
@ -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,
@ -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;
@ -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(() => {

View file

@ -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) {