fix(agsV2): use agsV1 logic for battery icons
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-09-27 13:56:39 -04:00
parent b40d7b80b9
commit 11223860f7
2 changed files with 30 additions and 10 deletions

View file

@ -12,16 +12,28 @@ const SPACING = 5;
export default () => ( export default () => (
<box className="bar-item battery"> <box className="bar-item battery">
<icon <icon
icon={bind(Battery, 'batteryIconName')}
setup={(self: Widget.Icon) => { setup={(self: Widget.Icon) => {
Battery.connect('notify::percentage', () => { const update = () => {
const percent = Math.round(Battery.get_percentage() * 100); const percent = Math.round(Battery.get_percentage() * 100);
const level = Math.floor(percent / 10) * 10;
const isCharging = Battery.get_charging();
const charged = percent === 100 && isCharging;
const iconName = charged ?
'battery-level-100-charged-symbolic' :
`battery-level-${level}${isCharging ?
'-charging' :
''}-symbolic`;
self.toggleClassName('charging', Battery.get_charging()); self.set_icon(iconName);
self.toggleClassName('charged', percent === 100);
self.toggleClassName('charging', isCharging);
self.toggleClassName('charged', charged);
self.toggleClassName('low', percent < LOW_BATT); self.toggleClassName('low', percent < LOW_BATT);
}); };
update();
Battery.connect('notify::percentage', () => update());
}} }}
/> />

View file

@ -1,4 +1,4 @@
import { Astal } from 'astal'; import { Astal, Gtk } from 'astal';
import Battery from './items/battery'; import Battery from './items/battery';
@ -15,9 +15,17 @@ export default () => {
Astal.WindowAnchor.RIGHT Astal.WindowAnchor.RIGHT
} }
> >
<box className="bar widget"> <centerbox className="bar widget">
<box hexpand halign={Gtk.Align.START}>
</box>
<box>
</box>
<box hexpand halign={Gtk.Align.END}>
<Battery /> <Battery />
</box> </box>
</centerbox>
</BarRevealer> </BarRevealer>
); );
}; };