diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java b/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java index dc8ba26d8..7f13f54e3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java @@ -21,6 +21,8 @@ import org.jackhuang.hmcl.util.FileSaver; import org.jackhuang.hmcl.util.SelfDependencyPatcher; import org.jackhuang.hmcl.util.SwingUtils; import org.jackhuang.hmcl.java.JavaRuntime; +import org.jackhuang.hmcl.util.io.FileUtils; +import org.jackhuang.hmcl.util.io.JarUtils; import org.jackhuang.hmcl.util.platform.OperatingSystem; import java.io.IOException; @@ -28,6 +30,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.nio.file.Files; +import java.nio.file.Path; import java.util.concurrent.CancellationException; import static org.jackhuang.hmcl.util.logging.Logger.LOG; @@ -49,7 +52,7 @@ public final class EntryPoint { setupJavaFXVMOptions(); checkDirectoryPath(); - if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) + if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS && !isInsideMacAppBundle()) initIcon(); checkJavaFX(); @@ -159,6 +162,25 @@ public final class EntryPoint { } } + private static boolean isInsideMacAppBundle() { + Path thisJar = JarUtils.thisJarPath(); + if (thisJar == null) + return false; + + for (Path current = thisJar.getParent(); + current != null && current.getParent() != null; + current = current.getParent() + ) { + if ("Contents".equals(FileUtils.getName(current)) + && FileUtils.getName(current.getParent()).endsWith(".app") + && Files.exists(current.resolve("Info.plist")) + ) { + return true; + } + } + return false; + } + private static void initIcon() { try { if (java.awt.Taskbar.isTaskbarSupported()) {