aboutsummaryrefslogtreecommitdiff
path: root/src/utils/cpu.rs
blob: 2047a0746f2cfd24782a93b1dd3eb9ae25773e12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::config::CONFIG;
use crate::types::ThreadsData;
use std::fs::read_to_string;

// getting cpu temperature
pub fn get_cpu_temp() -> ThreadsData {
    let buf = match read_to_string("/sys/class/thermal/thermal_zone0/temp") {
        Ok(data) => data,
        _ => return ThreadsData::CpuTemp(String::from("Error reading temp")),
    };

    let value = buf.trim().parse::<f32>().unwrap();

    let result = format!(
        "  {}  {}°  {}",
        CONFIG.cpu_temperature.icon,
        value / 1000.0,
        CONFIG.seperator
    );
    ThreadsData::CpuTemp(result)
}