tinymist_std/
battery.rs

1//! Battery-related utilities.
2
3#[cfg(feature = "system")]
4mod system {
5    /// Detects if the system is currently in power saving mode.
6    pub fn is_power_saving() -> bool {
7        ::battery::Manager::new()
8            .ok()
9            .and_then(|manager| manager.batteries().ok())
10            .map(|batteries| {
11                let mut batteries = batteries.peekable();
12                if batteries.peek().is_none() {
13                    return false;
14                }
15                batteries.all(|battery| match battery {
16                    Ok(bat) => matches!(bat.state(), ::battery::State::Discharging),
17                    Err(_) => false,
18                })
19            })
20            .unwrap_or(false)
21    }
22}
23#[cfg(feature = "system")]
24pub use system::*;
25
26#[cfg(not(feature = "system"))]
27mod other {
28    /// Detects if the system is currently in power saving mode.
29    pub fn is_power_saving() -> bool {
30        false
31    }
32}
33#[cfg(not(feature = "system"))]
34pub use other::*;