From 1215df5a2c500570d502a1c8f8bd9f733139cbe9 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Fri, 2 Dec 2022 23:48:38 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20RAM=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/system/specs.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/system/specs.rs b/src/system/specs.rs index 9c70f3f..8efb851 100644 --- a/src/system/specs.rs +++ b/src/system/specs.rs @@ -33,21 +33,29 @@ pub fn get_ram_used() -> String { use std::process::Command; let mut ram_used = String::new(); + let mut ram_total = String::new(); let output = Command::new("wmic") - .args(&["OS", "get", "FreePhysicalMemory"]) + .args(&["OS", "get", "FreePhysicalMemory,TotalVisibleMemorySize"]) .output() .expect("Failed to execute process"); let output = String::from_utf8_lossy(&output.stdout); for line in output.lines() { - if !line.contains("FreePhysicalMemory") && line.trim().len() > 0 { - ram_used = line.to_string(); - } + if line.contains("Memory") || line.trim().len() == 0 {continue}; + + let mut split = line.split_whitespace(); + + ram_used = split.next().unwrap().to_string(); + ram_total = split.next().unwrap().to_string(); } - ram_used + format!( + "{}MB / {}MB", + (ram_total.parse::().unwrap() - ram_used.parse::().unwrap()) / 1024, + ram_total.parse::().unwrap() / 1024 + ) } #[cfg(target_os = "windows")] @@ -120,6 +128,7 @@ pub fn get_ram_used() -> String { ) } +#[cfg(target_os = "linux")] fn eval_ram(line: String) -> u128 { let kbs: u128 = line.split(":") .collect::>()[1].to_string()