Skip to content

Commit

Permalink
Move away from "Monocle" in favor of "Headless" (#1225)
Browse files Browse the repository at this point in the history
Deprecated Monocle, add support for Headless
  • Loading branch information
tresf authored Dec 10, 2024
1 parent 5df8544 commit 72726cc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/qz/common/TrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
38 changes: 22 additions & 16 deletions src/qz/printer/action/html/WebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/qz/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -655,6 +656,7 @@ public static boolean isJDK() {
return false;
}

@Deprecated
public static boolean hasMonocle() {
if(hasMonocle == null) {
try {
Expand Down
3 changes: 2 additions & 1 deletion test/qz/printer/action/WebAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72726cc

Please sign in to comment.