feat: show live battery charge by default

This commit is contained in:
Valdemar Lorenzen
2026-10-12 12:02:10 +02:00
parent 0d3fbc01f8
commit 8c6a050171
11 changed files with 746 additions and 41 deletions
+42
View File
@@ -170,6 +170,8 @@ pub struct EditorSession {
pending_completion: bool,
hover_owner: Option<String>,
diff_workers: BTreeMap<usize, DiffWorker>,
battery: Option<crate::battery::Battery>,
battery_enabled: bool,
}
impl EditorSession {
@@ -267,8 +269,11 @@ impl EditorSession {
pending_completion: false,
hover_owner: None,
diff_workers: BTreeMap::new(),
battery: None,
battery_enabled: false,
};
session.synchronize_documents();
session.poll_battery();
Ok(session)
}
@@ -926,9 +931,46 @@ impl EditorSession {
Ok(changed)
}
fn poll_battery(&mut self) -> bool {
let enabled = self.editor.label("battery").is_empty()
&& [
self.editor.top_bar_config(),
self.editor.bottom_bar_config(),
]
.into_iter()
.any(|bar| {
bar.left
.iter()
.chain(&bar.center)
.chain(&bar.right)
.any(|name| name == "battery")
});
let mut changed = false;
if enabled != self.battery_enabled {
self.battery_enabled = enabled;
// Unit sessions do not read external hardware; provider and renderer checks inject data.
#[cfg(not(test))]
{
self.battery = if enabled {
crate::battery::Battery::start().ok()
} else {
None
};
}
if !enabled {
changed |= self.editor.set_battery_charge(None);
}
}
if let Some(charge) = self.battery.as_mut().and_then(|battery| battery.poll()) {
changed |= self.editor.set_battery_charge(charge);
}
changed
}
/// Drains ready plugin work without waiting for command or server responses.
pub fn poll(&mut self) -> bool {
let mut changed = self.synchronize_documents();
changed |= self.poll_battery();
changed |= self.poll_diff();
for update in self.lsp.poll() {
match self.apply_update("core", update) {