mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-01 20:07:22 +02:00
Merge pull request #20827 from Snuffleupagus/worker-DocProgress-contentLength
Ensure that `percent === NaN` is consistently reported by the `onProgress` callback
This commit is contained in:
commit
2ffd2e65dd
@ -275,7 +275,7 @@ class WorkerMessageHandler {
|
|||||||
if (!fullReader.isStreamingSupported) {
|
if (!fullReader.isStreamingSupported) {
|
||||||
handler.send("DocProgress", {
|
handler.send("DocProgress", {
|
||||||
loaded,
|
loaded,
|
||||||
total: Math.max(loaded, fullReader.contentLength || 0),
|
total: fullReader.contentLength,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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