Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Dec 23, 2024
1 parent f4769a0 commit 5b32afa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
42 changes: 20 additions & 22 deletions src/canvas/widgets/battery_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,28 @@ impl Painter {
{
let style = self.styles.text_style;
match &battery_details.state {
BatteryState::Charging { time_to_full } => {
if let Some(secs) = time_to_full {
time = long_time(*secs);

if full_width as usize > time.len() {
battery_rows
.push(Row::new(["Time to empty", &time]).style(style));
} else {
time = short_time(*secs);
battery_rows.push(Row::new(["To empty", &time]).style(style));
}
BatteryState::Charging {
time_to_full: Some(secs),
} => {
time = long_time(*secs);

if full_width as usize > time.len() {
battery_rows.push(Row::new(["Time to full", &time]).style(style));
} else {
time = short_time(*secs);
battery_rows.push(Row::new(["To full", &time]).style(style));
}
}
BatteryState::Discharging { time_to_empty } => {
if let Some(secs) = time_to_empty {
time = long_time(*secs);

if full_width as usize > time.len() {
battery_rows
.push(Row::new(["Time to full", &time]).style(style));
} else {
time = short_time(*secs);
battery_rows.push(Row::new(["To full", &time]).style(style));
}
BatteryState::Discharging {
time_to_empty: Some(secs),
} => {
time = long_time(*secs);

if full_width as usize > time.len() {
battery_rows.push(Row::new(["Time to empty", &time]).style(style));
} else {
time = short_time(*secs);
battery_rows.push(Row::new(["To empty", &time]).style(style));
}
}
_ => {}
Expand Down
2 changes: 0 additions & 2 deletions src/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ pub mod nvidia;
#[cfg(all(target_os = "linux", feature = "gpu"))]
pub mod amd;

#[cfg(feature = "battery")]
pub mod batteries;

pub mod cpu;
pub mod disks;
pub mod error;
Expand Down
2 changes: 2 additions & 0 deletions src/data_collection/batteries/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//!
//! For more information, refer to the [starship_battery](https://github.com/starship/rust-battery) repo/docs.
#[cfg(feature = "battery")]
use starship_battery::{
units::{power::watt, ratio::percent, time::second},
Battery, Manager, State,
Expand Down Expand Up @@ -66,6 +67,7 @@ impl BatteryData {
}
}

#[cfg(feature = "battery")]
pub fn refresh_batteries(manager: &Manager, batteries: &mut [Battery]) -> Vec<BatteryData> {
batteries
.iter_mut()
Expand Down
1 change: 1 addition & 0 deletions src/data_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct ConvertedData {

pub load_avg_data: [f32; 3],
pub cpu_data: Vec<CpuWidgetData>,

pub battery_data: Vec<BatteryData>,
pub disk_data: Vec<DiskWidgetData>,
pub temp_data: Vec<TempWidgetData>,
Expand Down

0 comments on commit 5b32afa

Please sign in to comment.