feat(ags): add battery bar

This commit is contained in:
Sweetbread 2025-03-26 22:11:26 +03:00
parent 02cd11a936
commit c795a16deb
2 changed files with 29 additions and 10 deletions

View File

@ -10,6 +10,8 @@
echo \$surface0: \#${colors.base02}\; >> colors.scss
echo \$fg: \#${colors.base05}\; >> colors.scss
echo \$accent: \#${colors.base0B}\; >> colors.scss
echo \#${colors.base0B} > accent.css
'';
installPhase = ''
@ -17,5 +19,6 @@
mkdir $out
cp $src/* $out -r
mv colors.scss $out
mv accent.css $out
'';
}

View File

@ -1,14 +1,30 @@
import { bind } from "astal"
import Battery from "gi://AstalBattery"
import { bind } from "astal";
import Battery from "gi://AstalBattery";
import accent from "../../accent.css";
export default function BatteryLevel() {
const bat = Battery.get_default()
const bat = Battery.get_default();
const percent = bind(bat, "percentage").as(p => Math.floor(p * 100));
return <box className="Battery"
visible={bind(bat, "isPresent")}>
return (
<box
className="Battery"
visible={bind(bat, "isPresent")}
css={percent.as(p => `
background-image: linear-gradient(
to right,
${accent} 0%,
${accent} ${p}%,
transparent ${p}%,
transparent 100%
);
background-size: 100% 3px;
background-repeat: no-repeat;
background-position: bottom;
`)}
>
<icon icon={bind(bat, "batteryIconName")} />
<label label={bind(bat, "percentage").as(p =>
`${Math.floor(p * 100)} %`
)} />
<label label={percent.as(p => `${p}%`)} />
</box>
);
}