Conversation
There was a problem hiding this comment.
Pull Request Overview
为 macOS 引入环境变量 HMCL_MACOS_SET_ICON,用于控制是否设置 Dock 图标,便于 HMCL-MacOS 自定义图标集成。
- 在 EntryPoint 中仅当 macOS 且 HMCL_MACOS_SET_ICON=true 时才调用 initIcon
- 在中文调试文档中新增 HMCL_MACOS_SET_ICON 的说明,默认值为 true
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docs/Debug_zh.md | 新增 HMCL_MACOS_SET_ICON 环境变量的文档条目,说明默认值 |
| HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java | 使用环境变量开关控制 macOS 下 initIcon 的执行 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
我感觉可以不用一个环境变量来控制,而是让 HMCL 主动检测自己是否被打包为了 dmg 等格式。 |
|
当前逻辑为:如果 HMCL 目录路径中包含 |
可以进一步添加一个逻辑,检查 |
| } | ||
|
|
||
| private static boolean isMacDockIconDisabled() { | ||
| Path directory = JarUtils.thisJarPath(); |
| return false; | ||
|
|
||
| for (int i = 1; i < directory.getNameCount(); i++) { | ||
| Path subpath = directory.getRoot().resolve(directory.subpath(0, i)); |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| while (jarPath != null && jarPath.getParent() != null) { | ||
| if ("Contents".equals(jarPath.getFileName().toString()) | ||
| && jarPath.getParent().getFileName().toString().endsWith(".app") |
There was a problem hiding this comment.
这里不安全,要是 getParent() 返回 / 的话,那么它的 getFileName() 会返回 null,这里就会抛出 NPE 了。
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| current != null && current.getParent() != null; | ||
| current = current.getParent() | ||
| ) { | ||
| if ("Contents".equals(FileUtils.getName(current)) |
There was a problem hiding this comment.
The loop condition current.getParent() != null may cause the loop to terminate prematurely when checking paths near the root directory. If the JAR is located in /Applications/MyApp.app/Contents/Java/app.jar, the loop should check the MyApp.app level, but it will stop before reaching it because it requires the parent of MyApp.app (which is /Applications) to also have a parent. Remove the current.getParent() != null condition from the loop.
| current != null && current.getParent() != null; | |
| current = current.getParent() | |
| ) { | |
| if ("Contents".equals(FileUtils.getName(current)) | |
| current != null; | |
| current = current.getParent() | |
| ) { | |
| if ("Contents".equals(FileUtils.getName(current)) | |
| && current.getParent() != null |
| if ("Contents".equals(FileUtils.getName(current)) | ||
| && FileUtils.getName(current.getParent()).endsWith(".app") |
There was a problem hiding this comment.
Potential NullPointerException when calling current.getParent() on line 175. Although the loop condition checks current != null, it doesn't guarantee that current.getParent() is non-null when the condition on line 174 is true. Add a null check before accessing current.getParent().
| if ("Contents".equals(FileUtils.getName(current)) | |
| && FileUtils.getName(current.getParent()).endsWith(".app") | |
| Path parent = current.getParent(); | |
| if (parent != null | |
| && "Contents".equals(FileUtils.getName(current)) | |
| && FileUtils.getName(parent).endsWith(".app") |
不在 HMCL 被打包为 App 时设置 macOS Dock 栏图标,以支持 ShulkerSakura/HMCL-MacOS 自定义图标。