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:
commit
7a8aceef20
17
web/app.js
17
web/app.js
@ -151,7 +151,6 @@ const PDFViewerApplication = {
|
|||||||
/** @type {AnnotationEditorParams} */
|
/** @type {AnnotationEditorParams} */
|
||||||
annotationEditorParams: null,
|
annotationEditorParams: null,
|
||||||
isInitialViewSet: false,
|
isInitialViewSet: false,
|
||||||
downloadComplete: false,
|
|
||||||
isViewerEmbedded: window.parent !== window,
|
isViewerEmbedded: window.parent !== window,
|
||||||
url: "",
|
url: "",
|
||||||
baseUrl: "",
|
baseUrl: "",
|
||||||
@ -940,7 +939,6 @@ const PDFViewerApplication = {
|
|||||||
this.pdfLinkService.externalLinkEnabled = true;
|
this.pdfLinkService.externalLinkEnabled = true;
|
||||||
this.store = null;
|
this.store = null;
|
||||||
this.isInitialViewSet = false;
|
this.isInitialViewSet = false;
|
||||||
this.downloadComplete = false;
|
|
||||||
this.url = "";
|
this.url = "";
|
||||||
this.baseUrl = "";
|
this.baseUrl = "";
|
||||||
this._downloadUrl = "";
|
this._downloadUrl = "";
|
||||||
@ -1070,12 +1068,9 @@ const PDFViewerApplication = {
|
|||||||
async download(options = {}) {
|
async download(options = {}) {
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
if (this.downloadComplete) {
|
data = await this.pdfDocument.getData();
|
||||||
data = await this.pdfDocument.getData();
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
// When the PDF document isn't ready, or the PDF file is still
|
// When the PDF document isn't ready, simply download using the URL.
|
||||||
// downloading, simply download using the URL.
|
|
||||||
}
|
}
|
||||||
this.downloadManager.download(
|
this.downloadManager.download(
|
||||||
data,
|
data,
|
||||||
@ -1186,17 +1181,12 @@ const PDFViewerApplication = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
progress(level) {
|
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);
|
const percent = Math.round(level * 100);
|
||||||
// When we transition from full request to range requests, it's possible
|
// 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
|
// 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
|
// bar to move backwards. So prevent this by only updating the bar if it
|
||||||
// increases.
|
// increases.
|
||||||
if (percent <= this.loadingBar.percent) {
|
if (!this.loadingBar || percent <= this.loadingBar.percent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.loadingBar.percent = percent;
|
this.loadingBar.percent = percent;
|
||||||
@ -1219,7 +1209,6 @@ const PDFViewerApplication = {
|
|||||||
|
|
||||||
pdfDocument.getDownloadInfo().then(({ length }) => {
|
pdfDocument.getDownloadInfo().then(({ length }) => {
|
||||||
this._contentLength = length; // Ensure that the correct length is used.
|
this._contentLength = length; // Ensure that the correct length is used.
|
||||||
this.downloadComplete = true;
|
|
||||||
this.loadingBar?.hide();
|
this.loadingBar?.hide();
|
||||||
|
|
||||||
firstPagePromise.then(() => {
|
firstPagePromise.then(() => {
|
||||||
|
|||||||
@ -740,7 +740,7 @@ class ProgressBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDisableAutoFetch(delay = /* ms = */ 5000) {
|
setDisableAutoFetch(delay = /* ms = */ 5000) {
|
||||||
if (isNaN(this.#percent)) {
|
if (this.#percent === 100 || isNaN(this.#percent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.#disableAutoFetchTimeout) {
|
if (this.#disableAutoFetchTimeout) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user