From 8174e3e64ff5547b8894205ef0eaefb6319266cc Mon Sep 17 00:00:00 2001 From: Mihail Yaremenko Date: Thu, 12 Jan 2023 15:37:08 +0200 Subject: [PATCH] Fix #655: set macOS Dock icon on jar build on newer Java versions (#703) * Add OS X resource forks and other stuff to gitignore * fix #655, try to set Dock icon only if not using app bundle * update CHANGELOG.md * try to set macOS icon only when using jar bundle, as in app bundle macOS sets everything automatically Co-authored-by: Ryan Dowling --- .gitignore | 8 +++++++ CHANGELOG.md | 1 + src/main/java/com/atlauncher/App.java | 30 ++++++++++++++++++--------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index e2d32080..760ac6fa 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,14 @@ testLauncher/ # OS X .DS_Store +._* +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent # ACT .actrc diff --git a/CHANGELOG.md b/CHANGELOG.md index c61ae3e8..51422ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,5 +8,6 @@ This changelog only contains the changes that are unreleased. For changes for in ### New Features ### Fixes +- Default Java icon in macOS Dock when using Java 9 or later [#655] (@WhiteBear60) ### Misc diff --git a/src/main/java/com/atlauncher/App.java b/src/main/java/com/atlauncher/App.java index add2d828..a90ad1ea 100644 --- a/src/main/java/com/atlauncher/App.java +++ b/src/main/java/com/atlauncher/App.java @@ -135,7 +135,7 @@ public class App { /** * This allows skipping the system tray integration so that the launcher doesn't - * even try to show the icon and menu etc, in the users system tray. It can be + * even try to show the icon and menu etc., in the users system tray. It can be * skipped with the below command line argument. *

* --skip-tray-integration @@ -637,17 +637,27 @@ public class App { } private static void setupOSSpecificThings() { - // do some Mac specific stuff, setting the name of theapplication and icon - if (OS.isMac()) { + // do some Mac specific stuff, setting the name of the application and icon + // set only when using jar bundle, as if using *.app, macOS sets icon and name automatically and apple.laf.useScreenMenuBar is set using build.gradle + if (!OS.isUsingMacApp()) { System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("com.apple.mrj.application.apple.menu.about.name", - Constants.LAUNCHER_NAME + " " + Constants.VERSION); + System.setProperty("apple.awt.application.name", Constants.LAUNCHER_NAME); // setting the application name in menu bar try { - Class util = Class.forName("com.apple.eawt.Application"); - Method getApplication = util.getMethod("getApplication"); - Object application = getApplication.invoke(util); - Method setDockIconImage = util.getMethod("setDockIconImage", Image.class); - setDockIconImage.invoke(application, Utils.getImage("/assets/image/icon-osx.png")); + if (Java.isSystemJavaNewerThanJava8()) { + // if Java 9 or higher + Class util = Class.forName("java.awt.Taskbar"); + Method getTaskbar = util.getMethod("getTaskbar"); + Object taskbar = getTaskbar.invoke(util); + Method setIconImage = util.getMethod("setIconImage", Image.class); + setIconImage.invoke(taskbar, Utils.getImage("/assets/image/icon-osx.png")); + } else { + // if Java 8 or lower + Class util = Class.forName("com.apple.eawt.Application"); + Method getApplication = util.getMethod("getApplication"); + Object application = getApplication.invoke(util); + Method setDockIconImage = util.getMethod("setDockIconImage", Image.class); + setDockIconImage.invoke(application, Utils.getImage("/assets/image/icon-osx.png")); + } } catch (Exception ex) { LogManager.logStackTrace("Failed to set dock icon", ex); }