2121import org .jackhuang .hmcl .util .SelfDependencyPatcher ;
2222import org .jackhuang .hmcl .util .SwingUtils ;
2323import org .jackhuang .hmcl .java .JavaRuntime ;
24+ import org .jackhuang .hmcl .util .io .FileUtils ;
25+ import org .jackhuang .hmcl .util .io .JarUtils ;
2426import org .jackhuang .hmcl .util .platform .OperatingSystem ;
2527
2628import java .io .IOException ;
2729import java .lang .invoke .MethodHandle ;
2830import java .lang .invoke .MethodHandles ;
2931import java .lang .invoke .MethodType ;
3032import java .nio .file .Files ;
33+ import java .nio .file .Path ;
3134import java .util .concurrent .CancellationException ;
3235
3336import 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