修复 Linux 端 hostnamectl 命令不可用时无法与手机端同步的问题 #1784
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
hostnamectl
命令是 systemd 的一部分。在一些环境下,例如非 systemd 发行版或某些沙盒环境中,此命令可能不可用。目前 lx-music-desktop 在 Linux 端启用同步时会尝试通过hostnamectl --pretty
来获取计算机名,在该命令执行失败时会导致手机端无法启用同步。此 PR 将执行此命令的代码放入try
块中,使得在该命令未能正确执行的情况下也能回退到直接使用os.hostname()
的方案。不太熟悉 JS,临时照着 MDN 的文档 写的,如有写得不对的地方请指正😉