From 5e462885d21193706d23e42cd5e21e88763788cb Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 16 Jun 2023 16:09:45 +0100 Subject: [PATCH] JAL-3830 Look for --headless mode and add -Djava.awt.headless=true to java invocation to remove icon from dock in macos --- src/jalview/bin/Jalview.java | 6 ++++++ src/jalview/bin/Launcher.java | 17 +++++++++++++++++ utils/getdown/bin/jalview.sh | 14 ++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 3a733f3..1f86926 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -810,6 +810,7 @@ public class Jalview // Run Commands from cli cmds = new Commands(argparser, headlessArg); boolean commandsSuccess = cmds.argsWereParsed(); + if (commandsSuccess) { if (headlessArg) @@ -822,6 +823,11 @@ public class Jalview } else { + // record usage stats if in headless mode + if (Cache.getDefault("USAGESTATS", false)) + { + Cache.initGoogleTracker(headlessArg); + } Jalview.exit("Successfully completed commands in headless mode", 0); } diff --git a/src/jalview/bin/Launcher.java b/src/jalview/bin/Launcher.java index a87d322..f199002 100644 --- a/src/jalview/bin/Launcher.java +++ b/src/jalview/bin/Launcher.java @@ -50,6 +50,8 @@ public class Launcher { private final static String startClass = "jalview.bin.Jalview"; + private final static String headlessProperty = "java.awt.headless"; + private static boolean checkJVMSymlink(String testBin) { File testBinFile = new File(testBin); @@ -127,6 +129,7 @@ public class Launcher boolean debug = false; boolean wait = true; boolean quiet = false; + boolean headless = false; // must set --debug before --launcher... boolean launcherstop = false; boolean launcherprint = false; @@ -142,6 +145,10 @@ public class Launcher { quiet = true; } + if (arg.equals("--headless")) + { + headless = true; + } if (debug && arg.equals("--launcherprint")) { launcherprint = true; @@ -221,6 +228,7 @@ public class Launcher boolean memSet = false; boolean dockIcon = false; boolean dockName = false; + boolean headlessProp = false; for (int i = 0; i < command.size(); i++) { String arg = command.get(i); @@ -241,6 +249,10 @@ public class Launcher { dockName = true; } + else if (arg.startsWith("-D" + headlessProperty + "=")) + { + headlessProp = true; + } } if (!memSet) @@ -276,6 +288,11 @@ public class Launcher + appName); } } + if (headless && !headlessProp) + { + System.setProperty(headlessProperty, "true"); + command.add("-D" + headlessProperty + "=true"); + } String scalePropertyArg = HiDPISetting.getScalePropertyArg(); if (scalePropertyArg != null) diff --git a/utils/getdown/bin/jalview.sh b/utils/getdown/bin/jalview.sh index 9e3a8c7..c1ad597 100755 --- a/utils/getdown/bin/jalview.sh +++ b/utils/getdown/bin/jalview.sh @@ -36,6 +36,15 @@ if [ "$( uname -s )" = "Darwin" ]; then ISMACOS=1 fi +# check for headless mode +HEADLESS=0 +for ARG in ARGS; do + if [ "${ARG}" = "--headless" ]; then + HEADLESS=1 + break + fi +done + declare -a JVMARGS=() # set vars for being inside the macos App Bundle @@ -57,6 +66,11 @@ else JAVA="${APPDIR}/jre/bin/java" fi +if [ "${HEADLESS}" = 1 ]; then + # this suppresses the Java icon appearing in the macOS Dock and maybe other things in other OSes + JVMARGS=( "${JVMARGS[@]}" "-Djava.awt.headless=true" ) +fi + SYSJAVA=java GETDOWNTXT="${APPDIR}/getdown.txt" -- 1.7.10.2