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 { Clock } from './clock.js';
import { SysTray } from './systray.js';
import { BatteryLabel } from './battery.js';
import { Batt } from './battery.js';
export const Bar = Window({
name: 'left-bar',
name: 'bar',
layer: 'overlay',
anchor: 'top left right',
exclusive: true,
@ -24,56 +24,50 @@ export const Bar = Window({
style: 'margin: 5px',
vertical: false,
children: [
startWidget: Box({
halign: 'start',
children: [
// Left
Box({
halign: 'start',
children: [
OskToggle,
OskToggle,
Separator(12),
Separator(12),
TabletToggle,
TabletToggle,
Separator(12),
Separator(12),
Heart,
Heart,
Separator(12),
Separator(12),
SysTray,
SysTray,
Separator(12),
Separator(12),
Workspaces,
Workspaces,
],
}),
],
}),
// Center
CurrentWindow,
centerWidget: CurrentWindow,
// Right
Box({
halign: 'end',
children: [
BatteryLabel(),
endWidget: Box({
halign: 'end',
children: [
Batt,
Separator(12),
Clock,
Separator(12),
Separator(12),
Clock,
NotifButton,
Separator(12),
Separator(12),
NotifButton,
Separator(12),
QsToggle,
],
}),
],
QsToggle,
],
}),
}),
});

View file

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