add bat notification; fix mem string
This commit is contained in:
parent
14c54e1be4
commit
fb071db667
3 changed files with 962 additions and 10 deletions
958
Cargo.lock
generated
958
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,4 +7,5 @@ edition = "2024"
|
|||
battery = "0.7.8"
|
||||
chrono = "0.4.40"
|
||||
local-ip-address = "0.6.3"
|
||||
notify-rust = "4.11.7"
|
||||
sysinfo = "0.34.2"
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -7,11 +7,13 @@ use sysinfo::System;
|
|||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut c = 0;
|
||||
let mut bat_notify_sent = false;
|
||||
loop {
|
||||
c += 1;
|
||||
let sys = System::new_all();
|
||||
let free_mem = sys.available_memory() / 1073741824;
|
||||
let total_mem = sys.total_memory() / 1073741824;
|
||||
let used_mem = total_mem - free_mem;
|
||||
let cpu = sys.global_cpu_usage();
|
||||
let ip4 = match local_ip_address::local_ip() {
|
||||
Ok(i) => i.to_string().replace("0", ""),
|
||||
|
@ -61,6 +63,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
)
|
||||
.as_str(),
|
||||
);
|
||||
if bat_res.state_of_charge().value * 100.0 < 20.0 && !bat_notify_sent {
|
||||
notify_rust::Notification::new()
|
||||
.summary("Battery level critical!")
|
||||
.body("Your battery is below 20%. Please connect you charger")
|
||||
.show()?;
|
||||
bat_notify_sent = true;
|
||||
} else if bat_notify_sent && bat_res.state_of_charge().value * 100.0 > 20.0 {
|
||||
bat_notify_sent = false;
|
||||
}
|
||||
batc += 1;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +81,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let time = chrono::Local::now().format("%A, %d-%m (%b), %Y %I:%M %p");
|
||||
|
||||
println!(
|
||||
"{battery}NET:{ip}|{disk_str}|MEM:{free_mem}/{total_mem}GB|CPU:{:.2}%|{time}",
|
||||
"{battery}NET:{ip}|{disk_str}|MEM:{used_mem}/{total_mem}GB|CPU:{:.2}%|{time}",
|
||||
cpu
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue