Skip to content

优化 Linux 平台硬件检测#3946

Merged
Glavo merged 1 commit into
HMCL-dev:mainfrom
Glavo:fastfetch
May 31, 2025
Merged

优化 Linux 平台硬件检测#3946
Glavo merged 1 commit into
HMCL-dev:mainfrom
Glavo:fastfetch

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented May 29, 2025

No description provided.

@Glavo Glavo requested a review from Copilot May 29, 2025 03:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances hardware detection on Linux by adding fallback logic, introducing a toggle for fastfetch usage, and improving FastFetchUtils parsing and executable resolution.

  • Linux detector now falls back to the superclass methods if Linux-specific probes return null/empty.
  • A hmcl.hardware.fastfetch system property controls whether fastfetch is used by default.
  • FastFetchUtils now filters out leading garbage from output and picks the right executable per OS.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxHardwareDetector.java Add null/empty fallbacks for CPU/GPU detection
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/hardware/HardwareDetector.java Introduce USE_FAST_FETCH flag driven by system property
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/hardware/FastFetchUtils.java Select .exe on Windows, strip leading garbage, and update logs
Comments suppressed due to low confidence (2)

HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxHardwareDetector.java:56

  • [nitpick] The variable name fastfetchResults is a bit ambiguous—consider renaming it to fallbackCards to clearly indicate its purpose.
List<GraphicsCard> fastfetchResults = super.detectGraphicsCards();

HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxHardwareDetector.java:53

  • Returning null for non-Linux platforms may force callers to null-check; consider returning an empty list instead to simplify API usage.
return null;

Comment on lines 43 to 45
private static <T> T get(String type, TypeToken<T> resultType) {
Path fastfetch = SystemUtils.which("fastfetch");
Path fastfetch = SystemUtils.which(OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS ? "fastfetch.exe" : "fastfetch");
if (fastfetch == null)
Copy link

Copilot AI May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invoking which on every call can be costly; consider caching the resolved fastfetch path in a static field to avoid repeated lookups.

Copilot uses AI. Check for mistakes.
*/
@SuppressWarnings("ALL")
public class HardwareDetector {
private static final boolean USE_FAST_FETCH = "true".equalsIgnoreCase(System.getProperty("hmcl.hardware.fastfetch", "true"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里到时候要写到文档吗

@Glavo Glavo merged commit 45a40ee into HMCL-dev:main May 31, 2025
2 checks passed
@Glavo Glavo deleted the fastfetch branch May 31, 2025 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants