mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-05-23 11:21:02 +02:00
Ensure that percent === NaN is consistently reported by the onProgress callback
With these changes `0`, `NaN`, `null`, and `undefined` in the `total`-property all result in `percent === NaN` being reported by the callback, since previously e.g. `0` would result in `percent === 100` being reported unconditionally which doesn't make a lot of sense. Also, remove the "indeterminate" loadingBar (in the viewer) if the `PDFDocumentLoadingTask` fails since there won't be any more data arriving and displaying the animation thus seems wrong.
This commit is contained in:
parent
98dc351cfa
commit
1f69cf964c
@ -2524,7 +2524,9 @@ class WorkerTransport {
|
|||||||
this.loadingTask.onProgress?.({
|
this.loadingTask.onProgress?.({
|
||||||
loaded,
|
loaded,
|
||||||
total,
|
total,
|
||||||
percent: MathClamp(Math.round((loaded / total) * 100), 0, 100),
|
percent: total
|
||||||
|
? MathClamp(Math.round((loaded / total) * 100), 0, 100)
|
||||||
|
: NaN,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1255,6 +1255,10 @@ const PDFViewerApplication = {
|
|||||||
if (loadingTask !== this.pdfLoadingTask) {
|
if (loadingTask !== this.pdfLoadingTask) {
|
||||||
return undefined; // Ignore errors for previously opened PDF files.
|
return undefined; // Ignore errors for previously opened PDF files.
|
||||||
}
|
}
|
||||||
|
if (this.loadingBar) {
|
||||||
|
// Avoid the "indeterminate" loadingBar being displayed on error.
|
||||||
|
this.loadingBar.percent ||= 0;
|
||||||
|
}
|
||||||
|
|
||||||
let key = "pdfjs-loading-error";
|
let key = "pdfjs-loading-error";
|
||||||
if (reason instanceof InvalidPDFException) {
|
if (reason instanceof InvalidPDFException) {
|
||||||
|
|||||||
@ -577,11 +577,9 @@ class ExternalServices extends BaseExternalServices {
|
|||||||
pdfDataRangeTransport?.onDataProgressiveDone();
|
pdfDataRangeTransport?.onDataProgressiveDone();
|
||||||
break;
|
break;
|
||||||
case "progress":
|
case "progress":
|
||||||
const percent = MathClamp(
|
const percent = args.total
|
||||||
Math.round((args.loaded / args.total) * 100),
|
? MathClamp(Math.round((args.loaded / args.total) * 100), 0, 100)
|
||||||
0,
|
: NaN;
|
||||||
100
|
|
||||||
);
|
|
||||||
|
|
||||||
viewerApp.progress(percent);
|
viewerApp.progress(percent);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user