feat: display battery applet when there is no battery
This commit is contained in:
parent
71d9d6d5bb
commit
1ca7f8cb4c
2 changed files with 326 additions and 454 deletions
722
Cargo.lock
generated
722
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -78,6 +78,7 @@ struct CosmicBatteryApplet {
|
||||||
display_icon_name: String,
|
display_icon_name: String,
|
||||||
charging_limit: Option<bool>,
|
charging_limit: Option<bool>,
|
||||||
battery_percent: f64,
|
battery_percent: f64,
|
||||||
|
no_battery: bool,
|
||||||
on_battery: bool,
|
on_battery: bool,
|
||||||
gpus: FxHashMap<PathBuf, GPUData>,
|
gpus: FxHashMap<PathBuf, GPUData>,
|
||||||
update_trigger: Option<UnboundedSender<()>>,
|
update_trigger: Option<UnboundedSender<()>>,
|
||||||
|
|
@ -382,11 +383,12 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
percent,
|
percent,
|
||||||
time_to_empty,
|
time_to_empty,
|
||||||
} => {
|
} => {
|
||||||
|
self.no_battery = false;
|
||||||
self.update_battery(percent, on_battery);
|
self.update_battery(percent, on_battery);
|
||||||
self.time_remaining = Duration::from_secs(time_to_empty as u64);
|
self.time_remaining = Duration::from_secs(time_to_empty as u64);
|
||||||
}
|
}
|
||||||
DeviceDbusEvent::NoBattery => {
|
DeviceDbusEvent::NoBattery => {
|
||||||
std::process::exit(0);
|
self.no_battery = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::KeyboardBacklight(event) => match event {
|
Message::KeyboardBacklight(event) => match event {
|
||||||
|
|
@ -515,12 +517,22 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
let applet_padding = self.core.applet.suggested_padding(true);
|
let applet_padding = self.core.applet.suggested_padding(true);
|
||||||
|
|
||||||
let mut children = vec![
|
let mut children = vec![
|
||||||
icon::from_name(self.icon_name.as_str())
|
icon::from_name(if self.no_battery {
|
||||||
.size(suggested_size.0)
|
if self.screen_brightness.is_some() {
|
||||||
.into(),
|
self.display_icon_name.as_str()
|
||||||
|
} else if self.kbd_brightness.is_some() {
|
||||||
|
"keyboard-brightness-symbolic"
|
||||||
|
} else {
|
||||||
|
self.icon_name.as_str()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.icon_name.as_str()
|
||||||
|
})
|
||||||
|
.size(suggested_size.0)
|
||||||
|
.into(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if self.config.show_percentage {
|
if self.config.show_percentage && !self.no_battery {
|
||||||
let text = format!("{:.0}%", self.battery_percent);
|
let text = format!("{:.0}%", self.battery_percent);
|
||||||
|
|
||||||
let t = if is_horizontal {
|
let t = if is_horizontal {
|
||||||
|
|
@ -630,19 +642,25 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut content: Vec<Element<'_, Message>> = vec![
|
let mut content: Vec<Element<'_, Message>> = if self.no_battery {
|
||||||
padded_control(
|
Vec::new()
|
||||||
row![
|
} else {
|
||||||
icon::from_name(&*self.icon_name).size(24).symbolic(true),
|
vec![
|
||||||
column![name, description]
|
padded_control(
|
||||||
]
|
row![
|
||||||
.spacing(8)
|
icon::from_name(&*self.icon_name).size(24).symbolic(true),
|
||||||
.align_y(Alignment::Center),
|
column![name, description]
|
||||||
)
|
]
|
||||||
.into(),
|
.spacing(8)
|
||||||
padded_control(divider::horizontal::default())
|
.align_y(Alignment::Center),
|
||||||
.padding([space_xxs, space_s])
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
padded_control(divider::horizontal::default())
|
||||||
|
.padding([space_xxs, space_s])
|
||||||
|
.into(),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
content.extend([
|
||||||
menu_button(
|
menu_button(
|
||||||
row![
|
row![
|
||||||
column![
|
column![
|
||||||
|
|
@ -709,9 +727,11 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
padded_control(divider::horizontal::default())
|
padded_control(divider::horizontal::default())
|
||||||
.padding([space_xxs, space_s])
|
.padding([space_xxs, space_s])
|
||||||
.into(),
|
.into(),
|
||||||
];
|
]);
|
||||||
|
|
||||||
if let Some(charging_limit) = self.charging_limit {
|
if let Some(charging_limit) = self.charging_limit
|
||||||
|
&& !self.no_battery
|
||||||
|
{
|
||||||
content.push(
|
content.push(
|
||||||
padded_control(
|
padded_control(
|
||||||
toggler(charging_limit)
|
toggler(charging_limit)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue