-
Notifications
You must be signed in to change notification settings - Fork 820
在 Linux 平台使用 dbus-send 检测深色模式设置 #5317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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", |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(" "); |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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+"); |
No description provided.