fix: show correct icon when battery is 90+

This commit is contained in:
matt1432 2023-09-08 14:14:10 -04:00
parent 59ae78fb54
commit 58055bf178
2 changed files with 37 additions and 41 deletions

View file

@ -10,10 +10,10 @@ import { QsToggle } from './quick-settings.js';
import { NotifButton } from './notif-button.js'; import { NotifButton } from './notif-button.js';
import { Clock } from './clock.js'; import { Clock } from './clock.js';
import { SysTray } from './systray.js'; import { SysTray } from './systray.js';
import { BatteryLabel } from './battery.js'; import { Batt } from './battery.js';
export const Bar = Window({ export const Bar = Window({
name: 'left-bar', name: 'bar',
layer: 'overlay', layer: 'overlay',
anchor: 'top left right', anchor: 'top left right',
exclusive: true, exclusive: true,
@ -24,10 +24,7 @@ export const Bar = Window({
style: 'margin: 5px', style: 'margin: 5px',
vertical: false, vertical: false,
children: [ startWidget: Box({
// Left
Box({
halign: 'start', halign: 'start',
children: [ children: [
@ -52,14 +49,12 @@ export const Bar = Window({
], ],
}), }),
// Center centerWidget: CurrentWindow,
CurrentWindow,
// Right endWidget: Box({
Box({
halign: 'end', halign: 'end',
children: [ children: [
BatteryLabel(), Batt,
Separator(12), Separator(12),
@ -74,6 +69,5 @@ export const Bar = Window({
QsToggle, QsToggle,
], ],
}), }),
],
}), }),
}); });

View file

@ -3,7 +3,7 @@ import { Separator } from '../common.js';
const { exec } = ags.Utils; const { exec } = ags.Utils;
const icons = charging => ([ const icons = charging => ([
...Array.from({ length: 9 }, (_, i) => i * 10).map(i => ([ ...Array.from({ length: 10 }, (_, i) => i * 10).map(i => ([
`${i}`, Icon({ `${i}`, Icon({
className: `${i} ${charging ? 'charging' : 'discharging'}`, className: `${i} ${charging ? 'charging' : 'discharging'}`,
icon: `battery-level-${i}${charging ? '-charging' : ''}-symbolic`, icon: `battery-level-${i}${charging ? '-charging' : ''}-symbolic`,
@ -22,7 +22,7 @@ const Indicators = charging => Stack({
}]], }]],
}); });
export const Indicator = ({ const Indicator = ({
charging = Indicators(true), charging = Indicators(true),
discharging = Indicators(false), discharging = Indicators(false),
...props ...props
@ -43,13 +43,13 @@ export const Indicator = ({
}]], }]],
}); });
export const LevelLabel = props => Label({ const LevelLabel = props => Label({
...props, ...props,
className: 'label', className: 'label',
connections: [[1000, label => label.label = `${exec('cat /sys/class/power_supply/BAT0/capacity')}%`]], connections: [[1000, label => label.label = `${exec('cat /sys/class/power_supply/BAT0/capacity')}%`]],
}); });
export const BatteryLabel = () => Box({ const BatteryLabel = () => Box({
className: 'toggle-off battery', className: 'toggle-off battery',
children: [ children: [
Indicator(), Indicator(),
@ -57,3 +57,5 @@ export const BatteryLabel = () => Box({
LevelLabel(), LevelLabel(),
], ],
}); });
export const Batt = BatteryLabel();