Skip to content

Commit 322e296

Browse files
AnemoFlowerGlavo
andauthored
只在未被打包为 App 时设置 macOS Dock 栏图标 (#4698)
Co-authored-by: Glavo <zjx001202@gmail.com>
1 parent a86e5d7 commit 322e296

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
import org.jackhuang.hmcl.util.SelfDependencyPatcher;
2222
import org.jackhuang.hmcl.util.SwingUtils;
2323
import org.jackhuang.hmcl.java.JavaRuntime;
24+
import org.jackhuang.hmcl.util.io.FileUtils;
25+
import org.jackhuang.hmcl.util.io.JarUtils;
2426
import org.jackhuang.hmcl.util.platform.OperatingSystem;
2527

2628
import java.io.IOException;
2729
import java.lang.invoke.MethodHandle;
2830
import java.lang.invoke.MethodHandles;
2931
import java.lang.invoke.MethodType;
3032
import java.nio.file.Files;
33+
import java.nio.file.Path;
3134
import java.util.concurrent.CancellationException;
3235

3336
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
@@ -49,7 +52,7 @@ public static void main(String[] args) {
4952
setupJavaFXVMOptions();
5053
checkDirectoryPath();
5154

52-
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS)
55+
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS && !isInsideMacAppBundle())
5356
initIcon();
5457

5558
checkJavaFX();
@@ -159,6 +162,25 @@ private static void createHMCLDirectories() {
159162
}
160163
}
161164

165+
private static boolean isInsideMacAppBundle() {
166+
Path thisJar = JarUtils.thisJarPath();
167+
if (thisJar == null)
168+
return false;
169+
170+
for (Path current = thisJar.getParent();
171+
current != null && current.getParent() != null;
172+
current = current.getParent()
173+
) {
174+
if ("Contents".equals(FileUtils.getName(current))
175+
&& FileUtils.getName(current.getParent()).endsWith(".app")
176+
&& Files.exists(current.resolve("Info.plist"))
177+
) {
178+
return true;
179+
}
180+
}
181+
return false;
182+
}
183+
162184
private static void initIcon() {
163185
try {
164186
if (java.awt.Taskbar.isTaskbarSupported()) {

0 commit comments

Comments
 (0)