mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-09 23:04:02 +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) {
|
||||
handler.send("DocProgress", {
|
||||
loaded,
|
||||
total: Math.max(loaded, fullReader.contentLength || 0),
|
||||
total: fullReader.contentLength,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -2524,7 +2524,9 @@ class WorkerTransport {
|
||||
this.loadingTask.onProgress?.({
|
||||
loaded,
|
||||
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) {
|
||||
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";
|
||||
if (reason instanceof InvalidPDFException) {
|
||||
|
||||
@ -577,11 +577,9 @@ class ExternalServices extends BaseExternalServices {
|
||||
pdfDataRangeTransport?.onDataProgressiveDone();
|
||||
break;
|
||||
case "progress":
|
||||
const percent = MathClamp(
|
||||
Math.round((args.loaded / args.total) * 100),
|
||||
0,
|
||||
100
|
||||
);
|
||||
const percent = args.total
|
||||
? MathClamp(Math.round((args.loaded / args.total) * 100), 0, 100)
|
||||
: NaN;
|
||||
|
||||
viewerApp.progress(percent);
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user