#linux #battery #acpi

acpid_plug

监听acpid的电源适配器插头事件

2个版本

0.1.2 2024年4月5日
0.1.1 2024年4月5日
0.1.0 2024年4月5日

#429 in Unix APIs

Download history 760/week @ 2024-05-03 734/week @ 2024-05-10 579/week @ 2024-05-17 530/week @ 2024-05-24 558/week @ 2024-05-31 418/week @ 2024-06-07 402/week @ 2024-06-14 455/week @ 2024-06-21 523/week @ 2024-06-28 627/week @ 2024-07-05 564/week @ 2024-07-12 602/week @ 2024-07-19 514/week @ 2024-07-26 882/week @ 2024-08-02 1787/week @ 2024-08-09 532/week @ 2024-08-16

3,803 monthly downloads
3个crate中使用(通过lazybar-core

MPL-2.0 license

11KB
81 lines

acpid-plug

Rust crate用于从acpid监听Linux上的电源适配器插头事件。

use futures_util::StreamExt;

#[tokio::main(flavor = "current_thread")]
async fn main() -> std::io::Result<()> {
    let mut ac_plug_events = acpid_plug::connect().await?;

    while let Some(event) = ac_plug_events.next().await {
        match event {
            Ok(event) => println!("{:?}", event),
            Err(why) => eprintln!("error: {}", why),
        }
    }

    Ok(())
}

lib.rs:

use futures_util::StreamExt;

#[tokio::main(flavor = "current_thread")]
async fn main() -> std::io::Result<()> {
    let mut ac_plug_events = acpid_plug::connect().await?;

    while let Some(event) = ac_plug_events.next().await {
        match event {
            Ok(event) => println!("{:?}", event),
            Err(why) => eprintln!("error: {}", why),
        }
    }

    Ok(())
}

依赖项

~3–11MB
~107K SLoC