nixos/modules/homes/ags/widget/Battery.tsx

36 lines
1.0 KiB
TypeScript

import AstalBattery from "gi://AstalBattery";
import AstalPowerProfiles from "gi://AstalPowerProfiles";
import { createBinding } from "ags";
import { Gtk } from "ags/gtk4";
export default function BatteryWidget() {
const battery = AstalBattery.get_default()
const powerprofiles = AstalPowerProfiles.get_default()
const percent = createBinding(
battery,
"percentage",
)((p) => `${Math.floor(p * 100)}%`)
const setProfile = (profile: string) => {
powerprofiles.set_active_profile(profile)
}
return (
<menubutton visible={createBinding(battery, "isPresent")}>
<box>
<image iconName={createBinding(battery, "iconName")} />
<label label={percent} />
</box>
<popover>
<box orientation={Gtk.Orientation.VERTICAL}>
{powerprofiles.get_profiles().map(({ profile }) => (
<button onClicked={() => setProfile(profile)}>
<label label={profile} xalign={0} />
</button>
))}
</box>
</popover>
</menubutton>
)
}