在 Linux 平台通过 fc-match 查询默认字体 (#3922)

This commit is contained in:
Glavo
2025-05-20 00:25:56 +08:00
committed by GitHub
parent 1ac677365b
commit 4291ae5f16
3 changed files with 55 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ import org.jackhuang.hmcl.java.JavaRuntime;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.function.ExceptionalFunction;
import org.jackhuang.hmcl.util.io.IOUtils;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@@ -75,6 +76,11 @@ public final class SystemUtils {
return managedProcess.getProcess().waitFor();
}
public static String run(String... command) throws Exception {
return run(Arrays.asList(command),
inputStream -> IOUtils.readFullyAsString(inputStream, OperatingSystem.NATIVE_CHARSET));
}
public static <T> T run(List<String> command, ExceptionalFunction<InputStream, T, ?> convert) throws Exception {
File nul = OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS
? new File("NUL")

View File

@@ -23,7 +23,6 @@ import com.google.gson.JsonObject;
import org.jackhuang.hmcl.util.KeyValuePairUtils;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.IOUtils;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jackhuang.hmcl.util.platform.SystemUtils;
import org.jackhuang.hmcl.util.platform.hardware.CentralProcessor;
@@ -103,8 +102,7 @@ public final class MacOSHardwareDetector extends HardwareDetector {
String json = null;
try {
json = SystemUtils.run(Arrays.asList("/usr/sbin/system_profiler", "SPDisplaysDataType", "-json"),
inputStream -> IOUtils.readFullyAsString(inputStream, OperatingSystem.NATIVE_CHARSET));
json = SystemUtils.run("/usr/sbin/system_profiler", "SPDisplaysDataType", "-json");
JsonObject object = JsonUtils.GSON.fromJson(json, JsonObject.class);
JsonArray spDisplaysDataType = object.getAsJsonArray("SPDisplaysDataType");