gpuInfo top-level property

String get gpuInfo

Implementation

String get gpuInfo {
  final data = (Process.runSync(
    "lspci",
    [],
  )).stdout.toString();
  final List<String> gpuRaws = data.split("\n");
  final List<String> gpus = [];
  for (var i = 0; i < gpuRaws.length; i++) {
    final String line = gpuRaws[i];
    if (!line.contains(":")) continue;

    final first = line.split(" ")[1];
    if (first != "Display" && first != "3D" && first != "VGA") {
      continue;
    }
    String gpu = line.split(": ")[1].replaceAll(RegExp("\\(rev .*\\)\$"), "").trim();
    if (gpu.startsWith("NVIDIA")) {
      gpu = RegExp("\\[(.*)\\]").firstMatch(gpu)?.group(1) ?? gpu;
    }
    if (gpu.startsWith("Intel")) {
      gpu = gpu.replaceAll("(R)", "");
      gpu = gpu.replaceAll("Corporation", "");
      gpu = gpu.replaceAll("Integrated Graphics Controller", "");
    }
    gpus.add(gpu.trim());
  }
  return gpus.join("\n");
}