Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic battery widget #975

Merged
merged 2 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/usage/widgets/battery.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

!!! Warning

The battery features are unavailable if the binary is compiled with the `battery` feature disabled!
The battery features are unavailable if the binary is compiled with the `battery` feature disabled or if there are no batteries on the system!

The battery widget provides information about batteries on the system.

Expand Down
13 changes: 13 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use clap::ArgMatches;
use layout_options::*;
use regex::Regex;
use serde::{Deserialize, Serialize};

#[cfg(feature = "battery")]
use starship_battery::Manager;

use typed_builder::*;

use crate::{
Expand Down Expand Up @@ -844,6 +848,15 @@ fn get_hide_table_gap(matches: &ArgMatches, config: &Config) -> bool {
}

fn get_use_battery(matches: &ArgMatches, config: &Config) -> bool {
#[cfg(feature = "battery")]
if let Ok(battery_manager) = Manager::new() {
if let Ok(batteries) = battery_manager.batteries() {
if batteries.count() == 0 {
return false;
}
}
}

if cfg!(feature = "battery") {
if matches.is_present("battery") {
return true;
Expand Down