Conversation
There was a problem hiding this comment.
Pull request overview
为 Linux 平台增加通过 dbus-send(xdg-desktop-portal Settings API)读取系统 color-scheme,从而在“自动”主题亮度模式下更准确跟随系统深色/浅色设置。
Changes:
- 在
Themes.getDefaultBrightness()中新增 Linux 分支,通过dbus-send调用org.freedesktop.portal.Settings.Read获取org.freedesktop.appearance color-scheme - 解析返回值并映射到
Brightness.DARK/LIGHT,失败时记录 warning 日志 - 增加相关 imports(
Path,FileUtils,LOG)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| String[] result = SystemUtils.run( | ||
| FileUtils.getAbsolutePath(dbusSend), | ||
| "--session", | ||
| "--print-reply=literal", | ||
| "--reply-timeout=1000", |
There was a problem hiding this comment.
This runs an external process synchronously inside getDefaultBrightness(), which is used by a JavaFX ObjectBinding (computeValue() -> getBrightness()), so it will typically execute on the FX thread. SystemUtils.run(...) can block up to 15s (see HMCLCore/.../SystemUtils.java:98-103), which risks noticeable UI freezes on Linux if dbus-send hangs. Consider enforcing a much shorter overall wait (e.g., Process.waitFor with a small timeout and then destroy the process) or moving the D-Bus query off the FX thread and caching the result before bindings are evaluated.
| "org.freedesktop.portal.Settings.Read", | ||
| "string:org.freedesktop.appearance", | ||
| "string:color-scheme" | ||
| ).trim().split(" "); |
There was a problem hiding this comment.
trim().split(" ") only splits on single space characters and will behave poorly with other whitespace (tabs/newlines) and with the multi-space indentation dbus-send commonly prints. To make theme detection more robust, split on \\s+ (or parse the trailing integer via a regex) before interpreting the last token as the color-scheme value.
| ).trim().split(" "); | |
| ).trim().split("\\s+"); |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "org.freedesktop.portal.Settings.Read", | ||
| "string:org.freedesktop.appearance", | ||
| "string:color-scheme" | ||
| ), Duration.ofSeconds(2)).trim().split(" "); |
There was a problem hiding this comment.
Using .trim().split(" ") only splits on single space characters. If dbus-send --print-reply=literal returns output with tabs/newlines or multiple whitespace between tokens, this parsing can fail to extract the numeric value.
Consider splitting on \\s+ (or extracting the trailing integer via regex) before mapping 1/2 to dark/light.
| ), Duration.ofSeconds(2)).trim().split(" "); | |
| ), Duration.ofSeconds(2)).trim().split("\\s+"); |
No description provided.