|
18 | 18 | package com.lambda.util |
19 | 19 |
|
20 | 20 | import com.lambda.Lambda.mc |
| 21 | +import net.minecraft.client.util.MacWindowUtil |
21 | 22 | import org.lwjgl.glfw.GLFW |
22 | 23 | import org.lwjgl.glfw.GLFWImage |
23 | 24 | import org.lwjgl.system.MemoryStack |
24 | 25 | import org.lwjgl.system.MemoryUtil |
25 | 26 | import java.awt.image.BufferedImage |
| 27 | +import java.io.ByteArrayInputStream |
| 28 | +import java.io.ByteArrayOutputStream |
26 | 29 | import java.nio.ByteBuffer |
| 30 | +import javax.imageio.ImageIO |
27 | 31 |
|
28 | 32 | object WindowIcons { |
29 | 33 | /** |
@@ -86,19 +90,15 @@ object WindowIcons { |
86 | 90 | } |
87 | 91 |
|
88 | 92 | GLFW.GLFW_PLATFORM_COCOA -> { |
89 | | - // On macOS glfwSetWindowIcon is ignored; set dock icon instead if possible. |
90 | | - try { |
91 | | - val largest = iconPaths |
92 | | - .mapNotNull { runCatching { it.readImage() }.getOrNull() } |
93 | | - .maxByOrNull { it.width * it.height } |
94 | | - ?: return |
| 93 | + val largest = iconPaths |
| 94 | + .mapNotNull { runCatching { it.readImage() }.getOrNull() } |
| 95 | + .maxByOrNull { it.width * it.height } |
| 96 | + ?: return |
95 | 97 |
|
96 | | - // Try Minecraft's MacWindowUtil if present |
97 | | - val klass = Class.forName("net.minecraft.client.util.MacWindowUtil") |
98 | | - val method = klass.getMethod("setApplicationIconImage", BufferedImage::class.java) |
99 | | - method.invoke(null, largest) |
100 | | - } catch (_: Throwable) { |
101 | | - // Silently ignore if class isn't available; no safe fallback on macOS via GLFW. |
| 98 | + MacWindowUtil.setApplicationIconImage { |
| 99 | + val baos = ByteArrayOutputStream() |
| 100 | + ImageIO.write(largest, "PNG", baos) |
| 101 | + ByteArrayInputStream(baos.toByteArray()) |
102 | 102 | } |
103 | 103 | } |
104 | 104 |
|
|
0 commit comments