feat: show live battery charge by default
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user