refactor: reorganize components, add interface to network

This commit is contained in:
2025-06-28 01:49:02 -07:00
parent 78ca57e491
commit f6c13e0ec7
9 changed files with 155 additions and 130 deletions

21
astal/widget/battery.tsx Normal file
View File

@@ -0,0 +1,21 @@
import { bind, Variable } from "astal"
import AstalBattery from "gi://AstalBattery?version=0.1"
export default function Battery() {
const battery = AstalBattery.get_default()
const battery_info = Variable.derive([bind(battery, "percentage"), bind(battery, "charging")], (percentage, charging) => {
const full_percentage = Math.floor(percentage * 100)
if (charging) {
return { label: `${full_percentage == 100 ? "FULL" : "CHR"}: ${full_percentage}%` }
}
return { label: `${full_percentage == 100 ? "FULL" : "BAT"}: ${full_percentage}%` }
})
if (!battery.is_battery) {
return <></>
}
return <box className="status-box">
<label label={battery_info((i) => i.label)} />
</box>
}