Fix build on Freebsd (#459)

* Fix get_battery_capacity type on BSD

* Update sysinfo: 0.16.5 -> 0.23.12
This commit is contained in:
Lucas Ransan 2022-05-23 19:27:20 +02:00 committed by GitHub
parent 4fb9bd4054
commit 1830fe8535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 36 deletions

15
Cargo.lock generated
View file

@ -355,12 +355,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "doc-comment"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]] [[package]]
name = "dtoa" name = "dtoa"
version = "0.4.8" version = "0.4.8"
@ -1210,9 +1204,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.106" version = "0.2.124"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
@ -2081,13 +2075,12 @@ dependencies = [
[[package]] [[package]]
name = "sysinfo" name = "sysinfo"
version = "0.16.5" version = "0.23.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567e910ef0207be81a4e1bb0491e9a8d9866cf45b20fe1a52c03d347da9ea51b" checksum = "56b1e20ee77901236c389ff74618a899ff5fd34719a7ff0fd1d64f0acca5179a"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"core-foundation-sys", "core-foundation-sys",
"doc-comment",
"libc", "libc",
"ntapi", "ntapi",
"once_cell", "once_cell",

View file

@ -58,7 +58,7 @@ futures-core = "0.3"
futures-util = "0.3" futures-util = "0.3"
tokio-util = "0.6" tokio-util = "0.6"
sysinfo = "0.16.1" sysinfo = "0.23"
dyn-clone = "1.0" dyn-clone = "1.0"
wait-timeout = "0.2" wait-timeout = "0.2"

View file

@ -13,16 +13,16 @@ pub fn get_disks() -> String {
format!( format!(
"{{ {} }}", "{{ {} }}",
c.get_disks() c.disks()
.iter() .iter()
.map(|c| { .map(|c| {
let total_space = c.get_total_space(); let total_space = c.total_space();
let available_space = c.get_available_space(); let available_space = c.available_space();
let used_space = total_space - available_space; let used_space = total_space - available_space;
format!( format!(
r#""{}": {{"name": {:?}, "total": {}, "free": {}, "used": {}, "used_perc": {}}}"#, r#""{}": {{"name": {:?}, "total": {}, "free": {}, "used": {}, "used_perc": {}}}"#,
c.get_mount_point().display(), c.mount_point().display(),
c.get_name(), c.name(),
total_space, total_space,
available_space, available_space,
used_space, used_space,
@ -37,15 +37,15 @@ pub fn get_ram() -> String {
let mut c = SYSTEM.lock().unwrap(); let mut c = SYSTEM.lock().unwrap();
c.refresh_memory(); c.refresh_memory();
let total_memory = c.get_total_memory(); let total_memory = c.total_memory();
let available_memory = c.get_available_memory(); let available_memory = c.available_memory();
let used_memory = total_memory as f32 - available_memory as f32; let used_memory = total_memory as f32 - available_memory as f32;
format!( format!(
r#"{{"total_mem": {}, "free_mem": {}, "total_swap": {}, "free_swap": {}, "available_mem": {}, "used_mem": {}, "used_mem_perc": {}}}"#, r#"{{"total_mem": {}, "free_mem": {}, "total_swap": {}, "free_swap": {}, "available_mem": {}, "used_mem": {}, "used_mem_perc": {}}}"#,
total_memory, total_memory,
c.get_free_memory(), c.free_memory(),
c.get_total_swap(), c.total_swap(),
c.get_free_swap(), c.free_swap(),
available_memory, available_memory,
used_memory, used_memory,
(used_memory / total_memory as f32) * 100f32, (used_memory / total_memory as f32) * 100f32,
@ -58,9 +58,9 @@ pub fn get_temperatures() -> String {
c.refresh_components(); c.refresh_components();
format!( format!(
"{{ {} }}", "{{ {} }}",
c.get_components() c.components()
.iter() .iter()
.map(|c| format!(r#""{}": {}"#, c.get_label().to_uppercase().replace(" ", "_"), c.get_temperature())) .map(|c| format!(r#""{}": {}"#, c.label().to_uppercase().replace(" ", "_"), c.temperature()))
.join(",") .join(",")
) )
} }
@ -68,19 +68,14 @@ pub fn get_temperatures() -> String {
pub fn get_cpus() -> String { pub fn get_cpus() -> String {
let mut c = SYSTEM.lock().unwrap(); let mut c = SYSTEM.lock().unwrap();
c.refresh_cpu(); c.refresh_cpu();
let processors = c.get_processors(); let processors = c.processors();
format!( format!(
r#"{{ "cores": [{}], "avg": {} }}"#, r#"{{ "cores": [{}], "avg": {} }}"#,
processors processors
.iter() .iter()
.map(|a| format!( .map(|a| format!(r#"{{"core": "{}", "freq": {}, "usage": {:.0}}}"#, a.name(), a.frequency(), a.cpu_usage()))
r#"{{"core": "{}", "freq": {}, "usage": {:.0}}}"#,
a.get_name(),
a.get_frequency(),
a.get_cpu_usage()
))
.join(","), .join(","),
processors.iter().map(|a| a.get_cpu_usage()).avg() processors.iter().map(|a| a.cpu_usage()).avg()
) )
} }
@ -159,8 +154,8 @@ pub fn get_battery_capacity() -> Result<String> {
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
pub fn get_battery_capacity() -> Result<u8> { pub fn get_battery_capacity() -> Result<String> {
anyhow!("Eww doesn't support your OS for getting the battery capacity") Err(anyhow::anyhow!("Eww doesn't support your OS for getting the battery capacity"))
} }
pub fn net() -> String { pub fn net() -> String {
@ -168,9 +163,9 @@ pub fn net() -> String {
c.refresh_networks_list(); c.refresh_networks_list();
let interfaces = format!( let interfaces = format!(
"{{ {} }}", "{{ {} }}",
&c.get_networks() &c.networks()
.iter() .iter()
.map(|a| format!(r#""{}": {{ "NET_UP": {}, "NET_DOWN": {} }}"#, a.0, a.1.get_transmitted(), a.1.get_received())) .map(|a| format!(r#""{}": {{ "NET_UP": {}, "NET_DOWN": {} }}"#, a.0, a.1.transmitted(), a.1.received()))
.join(","), .join(","),
); );
interfaces interfaces