Fixed battery plugin
This commit is contained in:
parent
19aee664c2
commit
7f6920507c
|
@ -1,4 +1,4 @@
|
||||||
use std::fmt::Write;
|
use std::{fmt::Write, path::PathBuf};
|
||||||
use dim_sdk::{plugin_info, Context, DimPlugin};
|
use dim_sdk::{plugin_info, Context, DimPlugin};
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
|
@ -19,11 +19,17 @@ impl Plug {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BATT0: &'static str = "/sys/class/power_supply/BAT0/capacity";
|
||||||
|
const BATT1: &'static str = "/sys/class/power_supply/BAT1/capacity";
|
||||||
|
|
||||||
impl DimPlugin for Plug {
|
impl DimPlugin for Plug {
|
||||||
fn init(&mut self, _ctx: Context) {
|
fn init(&mut self, _ctx: Context) {
|
||||||
}
|
}
|
||||||
fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> {
|
fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> {
|
||||||
let contents = read_to_string("/sys/class/power_supply/BAT0/capacity")?;
|
//TODO: Quick fix, make this better, more portable
|
||||||
|
let path = if PathBuf::from(BATT0).exists() { BATT0 } else { BATT1 };
|
||||||
|
|
||||||
|
let contents = read_to_string(path)?;
|
||||||
let cleaned_contents: String = contents.chars().filter(|c| c.is_digit(10)).collect();
|
let cleaned_contents: String = contents.chars().filter(|c| c.is_digit(10)).collect();
|
||||||
|
|
||||||
write!(f, "Battery: {}%", cleaned_contents)?;
|
write!(f, "Battery: {}%", cleaned_contents)?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user