aboutsummaryrefslogtreecommitdiff
path: root/src/utils/cpu.rs
blob: 3e582ad50afb333c7c4f2f0823ae36c6cfd237a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::types::Config;
use std::fs::File;
use std::io::Read;

// getting cpu temperature
pub fn get_cpu_temp(config: &Config) -> Result<String, std::io::Error> {
    let mut buf = String::new();
    File::open("/sys/class/thermal/thermal_zone0/temp")?.read_to_string(&mut buf)?;
    let value = buf.trim().parse::<f32>().unwrap();

    let result = format!(
        "  {}  {}°  {}",
        config.cpu_temperature.icon,
        value / 1000.0,
        config.seperator
    );
    Ok(result)
}