From 72726cc942dacb204ad8df67e384fc7c4941a408 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Tue, 10 Dec 2024 18:03:05 -0500 Subject: [PATCH] Move away from "Monocle" in favor of "Headless" (#1225) Deprecated Monocle, add support for Headless --- src/qz/common/TrayManager.java | 6 ++-- src/qz/printer/action/html/WebApp.java | 38 +++++++++++++++----------- src/qz/utils/SystemUtilities.java | 2 ++ test/qz/printer/action/WebAppTest.java | 3 +- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/qz/common/TrayManager.java b/src/qz/common/TrayManager.java index 6adf180e4..f529d95a2 100644 --- a/src/qz/common/TrayManager.java +++ b/src/qz/common/TrayManager.java @@ -293,10 +293,10 @@ private void addMenuItems() { monocleItem.setToolTipText("Use monocle platform for HTML printing (restart required)"); monocleItem.setMnemonic(KeyEvent.VK_U); monocleItem.setState(getPref(TRAY_MONOCLE)); - if(!SystemUtilities.hasMonocle()) { - log.warn("Monocle engine was not detected"); + if(Constants.JAVA_VERSION.getMajorVersion() <= 8) { + log.warn("Monocle engine is not available for this Java version"); monocleItem.setEnabled(false); - monocleItem.setToolTipText("Monocle HTML engine was not detected"); + monocleItem.setToolTipText("Monocle HTML engine is not available."); } monocleItem.addActionListener(monocleListener); diff --git a/src/qz/printer/action/html/WebApp.java b/src/qz/printer/action/html/WebApp.java index b4f1da08f..a83135d97 100644 --- a/src/qz/printer/action/html/WebApp.java +++ b/src/qz/printer/action/html/WebApp.java @@ -181,25 +181,31 @@ public static synchronized void initialize() throws IOException { // Fallback for JDK11+ headless = true; } - if (useMonocle && SystemUtilities.hasMonocle()) { - log.trace("Initializing monocle platform"); - System.setProperty("javafx.platform", "monocle"); - // Don't set glass.platform on Linux per https://github.com/qzind/tray/issues/702 - switch(SystemUtilities.getOs()) { - case WINDOWS: - case MAC: - System.setProperty("glass.platform", "Monocle"); - break; - default: - // don't set "glass.platform" - } + if (useMonocle) { + if(SystemUtilities.hasMonocle()) { + // Legacy "Monocle" mode + System.setProperty("javafx.platform", "monocle"); + // Don't set glass.platform on Linux per https://github.com/qzind/tray/issues/702 + switch(SystemUtilities.getOs()) { + case WINDOWS: + case MAC: + System.setProperty("glass.platform", "Monocle"); + break; + default: + // don't set "glass.platform" + } - //software rendering required headless environments - if (headless) { - System.setProperty("prism.order", "sw"); + //software rendering required headless environments + if (headless) { + System.setProperty("prism.order", "sw"); + } + } else { + // Assume newer "Headless" mode is available + System.setProperty("glass.platform", "Headless"); } + log.trace("Initializing {} glass.platform", SystemUtilities.hasMonocle() ? "monocle" : "headless"); } else { - log.warn("Monocle platform will not be used"); + log.warn("{} glass.platform will not be used", SystemUtilities.hasMonocle() ? "Monocle" : "Headless"); } } diff --git a/src/qz/utils/SystemUtilities.java b/src/qz/utils/SystemUtilities.java index 6bbffccbb..05c4dc9bc 100644 --- a/src/qz/utils/SystemUtilities.java +++ b/src/qz/utils/SystemUtilities.java @@ -70,6 +70,7 @@ public class SystemUtilities { private static Boolean darkDesktop; private static Boolean darkTaskbar; + @Deprecated private static Boolean hasMonocle; private static String classProtocol; private static Version osVersion; @@ -655,6 +656,7 @@ public static boolean isJDK() { return false; } + @Deprecated public static boolean hasMonocle() { if(hasMonocle == null) { try { diff --git a/test/qz/printer/action/WebAppTest.java b/test/qz/printer/action/WebAppTest.java index 61e09b589..83a8f0888 100644 --- a/test/qz/printer/action/WebAppTest.java +++ b/test/qz/printer/action/WebAppTest.java @@ -222,7 +222,8 @@ private static WebAppModel buildModel(String index, double width, double height, } private static PrinterJob buildVectorJob(String name) throws Throwable { - Printer defaultPrinter = Printer.getDefaultPrinter(); + // Get "PDF" printer + Printer defaultPrinter = Printer.getAllPrinters().stream().filter(printer -> printer.getName().contains("PDF")).findFirst().get(); PrinterJob job = PrinterJob.createPrinterJob(defaultPrinter); // All this to remove margins