~humaid/hstatus

1ee4366f49f0428546e927f917b237509f4f1653 — Humaid AlQassimi 1 year, 8 months ago bedbab7
Handle sigint
2 files changed, 23 insertions(+), 1 deletions(-)

M Cargo.toml
M src/main.rs
M Cargo.toml => Cargo.toml +1 -0
@@ 13,3 13,4 @@ libc = "0.2.68"
reqwest = { version = "0.10.9", features = ["blocking"] }
select = "0.6.0-alpha.1"
cached = "0.22.0"
signal-hook = "0.2.1"

M src/main.rs => src/main.rs +22 -1
@@ 4,6 4,9 @@ extern crate x11;
extern crate reqwest;
extern crate select;
extern crate cached;
extern crate signal_hook;

use signal_hook::{iterator::Signals, SIGINT};

use cached::proc_macro::cached;



@@ 15,6 18,8 @@ use libc::{c_int, getloadavg};
use std::ffi::CString;
use std::fs::File;
use std::io::prelude::*;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::{string, thread, time};

const SYSTEM_NAME: &str = "humaid's system";


@@ 109,6 114,10 @@ fn get_covid_stats() -> String {
}

fn main() {
    let signals = Signals::new(&[SIGINT]).unwrap();


    // Register the status items
    let mut stat_items: Vec<StatusItem> = Vec::new();
    stat_items.push(get_covid_stats);
    stat_items.push(load_item);


@@ 116,7 125,19 @@ fn main() {
    stat_items.push(time_item);

    let status: DesktopStatus = DesktopStatus::new();
    loop {

    let cont = Arc::new(AtomicBool::new(true));

    {
        let c = Arc::clone(&cont);
        thread::spawn(move || {
            for _ in signals.forever() {
                c.store(false, Ordering::SeqCst);
            }
        });
    }

    while cont.load(Ordering::SeqCst) {
        println!("Updating status");
        // Run the low battery flair
        let bat_num = get_battery_perc();