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