add battery level & load setting by device.env
This commit is contained in:
@@ -2,10 +2,8 @@ use std::{
|
||||
env,
|
||||
process::Command,
|
||||
};
|
||||
use dotenv::dotenv;
|
||||
|
||||
pub fn get_temperature() -> f32 {
|
||||
dotenv().ok();
|
||||
|
||||
let mut temperature = 0.0;
|
||||
let system = env::var("SYSTEM").unwrap().to_string();
|
||||
@@ -53,7 +51,7 @@ pub fn get_storage() -> i8 {
|
||||
return storage;
|
||||
}
|
||||
|
||||
pub fn get_mem() -> f32 {
|
||||
pub fn get_mem() -> i8 {
|
||||
let mem_command = Command::new("free")
|
||||
.arg("-m")
|
||||
.output().unwrap_or_else(|e| {
|
||||
@@ -64,7 +62,25 @@ pub fn get_mem() -> f32 {
|
||||
let vec_mem : Vec<&str> = mem_string.split_whitespace().collect();
|
||||
let total = vec_mem[7].parse::<f32>().unwrap();
|
||||
let mem_use = vec_mem[8].parse::<f32>().unwrap();
|
||||
let result = mem_use / total * 100.0 ;
|
||||
let result = (mem_use / total * 100.0) as i8;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn get_battery() -> i8 {
|
||||
let system = env::var("SYSTEM").unwrap().to_string();
|
||||
let mut battery = 0;
|
||||
|
||||
if system == "ubuntu" {
|
||||
let battery_command = Command::new("cat")
|
||||
.arg("/sys/class/power_supply/BAT0/capacity")
|
||||
.output().unwrap_or_else(|e| {
|
||||
panic!("failed to execute process: {}", e)
|
||||
});
|
||||
|
||||
let battery_string = &String::from_utf8_lossy(&battery_command.stdout);
|
||||
battery = (&battery_string[..battery_string.len() - 1]).parse::<i8>().unwrap();
|
||||
}
|
||||
|
||||
return battery;
|
||||
}
|
||||
Reference in New Issue
Block a user