fix: Add display for unknown battery state (#316)

This commit is contained in:
谢祯晖
2019-09-21 00:52:54 +08:00
committed by Matan Kushner
parent c2875d99b6
commit 14fe246138
3 changed files with 37 additions and 0 deletions
+14
View File
@@ -75,6 +75,20 @@ impl<'a> Module<'a> {
self.segments.last_mut().unwrap()
}
/// Should config exists, get a reference to a newly created segment in the module
pub fn new_segment_if_config_exists(&mut self, name: &str) -> Option<&mut Segment> {
// Use the provided value unless overwritten by config
if let Some(value) = self.config_value_str(name) {
let mut segment = Segment::new(name);
segment.set_style(self.style);
segment.set_value(value);
self.segments.push(segment);
Some(self.segments.last_mut().unwrap())
} else {
None
}
}
/// Whether a module has non-empty segments
pub fn is_empty(&self) -> bool {
self.segments.iter().all(|segment| segment.is_empty())
+11
View File
@@ -45,6 +45,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
battery::State::Discharging => {
module.new_segment("discharging_symbol", BATTERY_DISCHARGING);
}
battery::State::Unknown => {
log::debug!("Unknown detected");
module.new_segment_if_config_exists("unknown_symbol")?;
}
battery::State::Empty => {
module.new_segment_if_config_exists("empty_symbol")?;
}
_ => {
log::debug!("Unhandled battery state `{}`", state);
return None;
}
_ => return None,
}