Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
c8a74d47ef |
@ -4,6 +4,7 @@ use std::default::Default;
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Battery {
|
||||
pub icon: String,
|
||||
pub charging_icon: String,
|
||||
pub enabled: bool,
|
||||
pub delay: f64,
|
||||
}
|
||||
@ -11,6 +12,7 @@ pub struct Battery {
|
||||
impl Default for Battery {
|
||||
fn default() -> Self {
|
||||
Battery {
|
||||
charging_icon: String::from(""),
|
||||
icon: String::from(""),
|
||||
enabled: false,
|
||||
delay: 120.0,
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::config::CONFIG;
|
||||
use crate::types::ThreadsData;
|
||||
use battery::Manager;
|
||||
use battery::State;
|
||||
|
||||
// TODO: better error handeling
|
||||
|
||||
@ -18,15 +19,23 @@ pub async fn get_battery() -> ThreadsData {
|
||||
return ThreadsData::Battery(String::from("Cannot Get Battery!"));
|
||||
};
|
||||
|
||||
let percentage = if let Some(battery) = batteries.next() {
|
||||
f32::from(battery.unwrap().state_of_charge()) * 100.0
|
||||
let battery = batteries.next();
|
||||
let (icon, percentage);
|
||||
|
||||
if let Some(bat) = battery {
|
||||
let b = bat.unwrap();
|
||||
percentage = f32::from(b.state_of_charge()) * 100.0;
|
||||
icon = match b.state() {
|
||||
State::Charging => &CONFIG.battery.charging_icon,
|
||||
_ => &CONFIG.battery.icon,
|
||||
};
|
||||
} else {
|
||||
return ThreadsData::Battery(String::from("Cannot Read Battery!"));
|
||||
};
|
||||
|
||||
let result = format!(
|
||||
" {} {:.0}% {}",
|
||||
CONFIG.battery.icon, percentage, CONFIG.seperator
|
||||
icon, percentage, CONFIG.seperator
|
||||
);
|
||||
ThreadsData::Battery(result)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user