fallback to charge_full and charge_now

This commit is contained in:
Artemis Tosini 2023-10-10 18:30:02 +00:00
parent ea274f26c9
commit 869c754d21
Signed by: artemist
GPG key ID: ADFFE553DCBB831E
2 changed files with 15 additions and 7 deletions

View file

@ -128,9 +128,9 @@ pub async fn read_config() -> Result<Config, Box<dyn std::error::Error>> {
Ok(toml::from_slice(&config_contents)?)
}
pub fn process_tile<'a>(
pub fn process_tile(
tile: &TileConfig,
connection: &'a Arc<SyncConnection>,
connection: &Arc<SyncConnection>,
) -> BoxStream<'static, TileResult> {
let five_secs = Duration::from_secs(5);
match &tile.config_type {

View file

@ -4,16 +4,24 @@ use futures::future::try_join3;
use futures_async_stream::try_stream;
use std::error::Error;
use std::path::Path;
use tokio::fs::File;
use tokio::fs::{try_exists, File};
use tokio::io::AsyncReadExt;
#[try_stream(ok = Block, error = Box<dyn Error + Send + Sync>)]
pub async fn battery_stream(config: BatteryConfig) {
let base_path = Path::new("/sys/class/power_supply").join(&*config.battery);
let base_dir = Path::new("/sys/class/power_supply").join(&*config.battery);
let file_prefix = if try_exists(base_dir.join("energy_now")).await? {
"energy_"
} else {
"charge_"
};
let now_path = base_dir.join(file_prefix.to_owned() + "now");
let full_path = base_dir.join(file_prefix.to_owned() + "full");
loop {
let charge_now = async {
let mut raw = String::new();
File::open(base_path.join("energy_now"))
File::open(&now_path)
.await?
.read_to_string(&mut raw)
.await?;
@ -22,7 +30,7 @@ pub async fn battery_stream(config: BatteryConfig) {
};
let charge_total = async {
let mut raw = String::new();
File::open(base_path.join("energy_full"))
File::open(&full_path)
.await?
.read_to_string(&mut raw)
.await?;
@ -31,7 +39,7 @@ pub async fn battery_stream(config: BatteryConfig) {
};
let status = async {
let mut raw = String::new();
File::open(base_path.join("status"))
File::open(base_dir.join("status"))
.await?
.read_to_string(&mut raw)
.await?;