From f93faae01c1565633ed7349f0ca01c41fcc63051 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 8 Jun 2026 15:30:05 +0200 Subject: [PATCH] Add a `PDFViewer` helper method for setting `#printingAllowed` and dispatching the event This reduces a little bit of code duplication, which shouldn't hurt. --- web/pdf_viewer.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 7e557f019..313b55150 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -720,6 +720,11 @@ class PDFViewer { }); } + #setPrintingAllowed(isAllowed) { + this.#printingAllowed = isAllowed; + this.eventBus.dispatch("printingallowed", { source: this, isAllowed }); + } + /** * Currently only *some* permissions are supported. * @returns {Object} @@ -731,22 +736,14 @@ class PDFViewer { textLayerMode: this.#textLayerMode, }; if (!permissions) { - this.#printingAllowed = true; - this.eventBus.dispatch("printingallowed", { - source: this, - isAllowed: this.#printingAllowed, - }); - + this.#setPrintingAllowed(true); return params; } - this.#printingAllowed = + this.#setPrintingAllowed( permissions.includes(PermissionFlag.PRINT_HIGH_QUALITY) || - permissions.includes(PermissionFlag.PRINT); - this.eventBus.dispatch("printingallowed", { - source: this, - isAllowed: this.#printingAllowed, - }); + permissions.includes(PermissionFlag.PRINT) + ); if ( !permissions.includes(PermissionFlag.COPY) && @@ -922,7 +919,6 @@ class PDFViewer { this.#annotationEditorUIManager = null; this.#annotationEditorMode = AnnotationEditorType.NONE; - this.#printingAllowed = true; }