Refactor printing: startPrint -> performPrint
- Renamed startPrint to performPrint to emphasize that the method does not start the print process (preparing pages for the printer), but that it does the actual printing (sending pages off to the printer). - Put performPrint in the PDFPrintService, so that it can be overridden if needed.
This commit is contained in:
parent
d3b13e36d3
commit
594592216c
@ -187,6 +187,24 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
performPrint: function () {
|
||||||
|
this.throwIfInactive();
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
// Push window.print in the macrotask queue to avoid being affected by
|
||||||
|
// the deprecation of running print() code in a microtask, see
|
||||||
|
// https://github.com/mozilla/pdf.js/issues/7547.
|
||||||
|
setTimeout(function () {
|
||||||
|
if (!this.active) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
print.call(window);
|
||||||
|
// Delay promise resolution in case print() was not synchronous.
|
||||||
|
setTimeout(resolve, 20); // Tidy-up.
|
||||||
|
}.bind(this), 0);
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
get active() {
|
get active() {
|
||||||
return this === activeService;
|
return this === activeService;
|
||||||
},
|
},
|
||||||
@ -223,8 +241,7 @@
|
|||||||
}
|
}
|
||||||
var activeServiceOnEntry = activeService;
|
var activeServiceOnEntry = activeService;
|
||||||
activeService.renderPages().then(function () {
|
activeService.renderPages().then(function () {
|
||||||
activeServiceOnEntry.throwIfInactive();
|
return activeServiceOnEntry.performPrint();
|
||||||
return startPrint(activeServiceOnEntry);
|
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
// Ignore any error messages.
|
// Ignore any error messages.
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
@ -246,23 +263,6 @@
|
|||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startPrint(activeServiceOnEntry) {
|
|
||||||
return new Promise(function (resolve) {
|
|
||||||
// Push window.print in the macrotask queue to avoid being affected by
|
|
||||||
// the deprecation of running print() code in a microtask, see
|
|
||||||
// https://github.com/mozilla/pdf.js/issues/7547.
|
|
||||||
setTimeout(function () {
|
|
||||||
if (!activeServiceOnEntry.active) {
|
|
||||||
resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
print.call(window);
|
|
||||||
// Delay promise resolution in case print() was not synchronous.
|
|
||||||
setTimeout(resolve, 20); // Tidy-up.
|
|
||||||
}, 0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function abort() {
|
function abort() {
|
||||||
if (activeService) {
|
if (activeService) {
|
||||||
activeService.destroy();
|
activeService.destroy();
|
||||||
|
Loading…
Reference in New Issue
Block a user