getSystemInfo method
Gather system information.
Implementation
@override
Future<SystemInfo> getSystemInfo() async {
final os = Platform.operatingSystem;
final version = Platform.operatingSystemVersion;
final hostname = Platform.localHostname;
final arch = await _runSimple('uname', ['-m']);
final cpuCores = Platform.numberOfProcessors;
int memoryBytes = 0;
if (_platform == NativePlatform.macos) {
final raw = await _runSimple('sysctl', ['-n', 'hw.memsize']);
memoryBytes = int.tryParse(raw.trim()) ?? 0;
} else if (_platform == NativePlatform.linux) {
final raw = await _runSimple('grep', ['MemTotal', '/proc/meminfo']);
final match = RegExp(r'(\d+)').firstMatch(raw);
memoryBytes = (int.tryParse(match?.group(1) ?? '0') ?? 0) * 1024;
}
final shell =
Platform.environment['SHELL'] ??
Platform.environment['COMSPEC'] ??
'/bin/sh';
return SystemInfo(
os: os,
version: version,
arch: arch.trim(),
hostname: hostname,
cpuCores: cpuCores,
memoryBytes: memoryBytes,
shell: shell,
);
}